Is there a way to prevent image_create_from_node_from() from removing the original file after it has been moved to default/files/images? I'm calling this function from another module.

This might be a useful admin setting. The relevant line is 1103 in image.module.

Comments

joachim’s picture

I'm not sure I see the point of an admin setting. When would a user want to change this within image module?

However, I don't see any harm in adding an optional parameter like $keep_original = FALSE. Then if, say, image_import wants to provide this option, it can give a UI option and then pass in the variable on the call.

I'll take a patch for that :)

CODECOWBOY-1’s picture

Status: Active » Patch (to be ported)

* @return
* A node object if the node is created successfully or FALSE on error.
*/
-function image_create_node_from($filepath, $title = NULL, $body = '', $taxonomy = NULL) {
+function image_create_node_from($filepath, $title = NULL, $body = '', $taxonomy = NULL, $keep_original = NULL) {
global $user;

if (!user_access('create images')) {
@@ -1100,7 +1100,9 @@
node_save($node);

// Remove the original image now that the import has completed.
- file_delete($original_path);
+ if (!isset($keep_original)) {
+ file_delete($original_path);
+ }

return $node;
}

joachim’s picture

Status: Patch (to be ported) » Needs work

Could you attach this as a patch file please?
Also, the function's PHPdoc needs a mention of the new parameter.

CODECOWBOY-1’s picture

Status: Needs work » Patch (to be ported)
StatusFileSize
new5.52 KB
CODECOWBOY-1’s picture

Assigned: Unassigned » CODECOWBOY-1
Status: Patch (to be ported) » Active
CODECOWBOY-1’s picture

Status: Active » Needs review
joachim’s picture

Status: Needs review » Needs work

Needs work ;)

Please leave whitespace fixing to another time -- I know the module has crufty whitespace, but that's to be dealt with separately.
Also, the extra parameter needs documenting.

CODECOWBOY-1’s picture

Status: Needs work » Needs review
StatusFileSize
new1.56 KB

Have attached a revised patch for this, hopefully without the whitespace diffs!

joachim’s picture

That patch doesn't apply -- wrong file heading, and somehow the 2nd hunk fails even once I tell it which file to patch.

Here's a proper patch. (I tweaked the comment BTW.)

Please could you test it and confirm it's correct?

CODECOWBOY-1’s picture

CODECOWBOY-1’s picture

Have re-tested and this works fine.

Hetta’s picture

Patch applied cleanly and didn't interfere with image import; I don't know where to set things to "TRUE" vs. "FALSE" though.

Gotta love the changes to image_import from d5 - thumbnails, a pager, directory structure [ ], like, woot!

joachim’s picture

Status: Needs review » Fixed

Committed -- thanks.

#703542 by the_real_codecowboy, joachim: Added option for keeping the original file to the create image node from file API function.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.