aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio <silvio@devlet.com.br>2010-10-07 17:58:24 -0300
committerSilvio <silvio@devlet.com.br>2010-10-07 17:58:24 -0300
commit7e97d53bd1dd4cd726debb0993cf817e13192263 (patch)
treef6bc98b7c04126326b46dad9d86cb9cdc26b56ce
parent56d80e671b12e01acdf0cbc1ab3d704f89e0c35e (diff)
downloadmass_image_import-7e97d53bd1dd4cd726debb0993cf817e13192263.tar.gz
mass_image_import-7e97d53bd1dd4cd726debb0993cf817e13192263.tar.bz2
Using drupal_execute at mass_image_import_create_node_from
-rw-r--r--mass_image_import.module54
1 files changed, 26 insertions, 28 deletions
diff --git a/mass_image_import.module b/mass_image_import.module
index 9c20982..ff49539 100644
--- a/mass_image_import.module
+++ b/mass_image_import.module
@@ -203,13 +203,17 @@ function mass_image_import_batch_finished($success, $results, $operations) {
/**
* Create an image entry. Contains some code from image_create_node_from().
*
- * @see http://drupal.org/node/330421
+ * @see
+ * http://drupal.org/node/330421#comment-2806336
+ *
* @todo
* Mime, content type, field name, taxonomy, etc.
*/
function mass_image_import_create_node_from($filepath, $title, $body, $taxonomy) {
- $mime = 'image/jpeg';
+ $type = 'foto';
+ $field = 'foto';
+ $uid = 1;
// Make sure we can copy the file into our temp directory.
$original_path = $filepath;
@@ -221,38 +225,32 @@ function mass_image_import_create_node_from($filepath, $title, $body, $taxonomy)
$file = new stdClass();
$file->filename = basename($filepath);
$file->filepath = $filepath;
- $file->filemime = $mime;
+ $file->filemime = file_get_mimetype($filepath);
$file->filesize = filesize($filepath);
$file->uid = $uid;
- $file->status = FILE_STATUS_PERMANENT;
+ //$file->status = FILE_STATUS_PERMANENT; // See http://drupal.org/node/881020
$file->timestamp = time();
drupal_write_record('files', $file);
// Create the node.
$node = new StdClass();
- $node->type = 'foto';
- $node->body = $body;
- $node->title = $title;
-
- // Image field.
- $node->field_foto = array(
- array(
- 'fid' => $file->fid,
- 'title' => basename($file->filename),
- 'filename' => $file->filename,
- 'filepath' => $file->filepath,
- 'filesize' => $file->filesize,
- 'mimetype' => $mime,
- 'description' => basename($file->filename),
- 'list' => 1,
- ),
- );
-
- $node->uid = 1;
- $node->status = 1;
- $node->active = 1;
- $node->promote = 0;
- node_save($node);
-
+ $node->type = $type;
+
+ // Add image field.
+ $files = array();
+ $files[0] = (array) $file;
+ $files[0]['status'] = 0;
+
+ // Node form.
+ $form_state = array();
+ $form_state['values']['type'] = $type;
+ $form_state['values']['title'] = $title;
+ $form_state['values']['body'] = $body;
+ $form_state['values']['op'] = t('Save');
+ $form_state['values']['field_'. $field] = $files;
+
+ // Submit.
+ module_load_include('inc', 'node', 'node.pages');
+ drupal_execute($type .'_node_form', $form_state, $node);
return $node;
}