Closed (fixed)
Project:
Image
Version:
6.x-1.x-dev
Component:
image.module
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
3 Feb 2010 at 14:18 UTC
Updated:
4 Jul 2010 at 09:20 UTC
Jump to comment: Most recent file
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.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 703542.image_.create-api-keep-original.patch | 1.33 KB | joachim |
| #8 | image_module_patch.txt | 1.56 KB | CODECOWBOY-1 |
| #4 | Report3.txt | 5.52 KB | CODECOWBOY-1 |
Comments
Comment #1
joachim commentedI'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 :)
Comment #2
CODECOWBOY-1 commented* @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;
}
Comment #3
joachim commentedCould you attach this as a patch file please?
Also, the function's PHPdoc needs a mention of the new parameter.
Comment #4
CODECOWBOY-1 commentedComment #5
CODECOWBOY-1 commentedComment #6
CODECOWBOY-1 commentedComment #7
joachim commentedNeeds 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.
Comment #8
CODECOWBOY-1 commentedHave attached a revised patch for this, hopefully without the whitespace diffs!
Comment #9
joachim commentedThat 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?
Comment #10
CODECOWBOY-1 commented#9: 703542.image_.create-api-keep-original.patch queued for re-testing.
Comment #11
CODECOWBOY-1 commentedHave re-tested and this works fine.
Comment #12
Hetta commentedPatch 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!
Comment #13
joachim commentedCommitted -- thanks.
#703542 by the_real_codecowboy, joachim: Added option for keeping the original file to the create image node from file API function.