CCK Imagefield Support

peach - May 12, 2007 - 12:23
Project:Node import
Version:5.x-1.6
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:patch (code needs work)
Description

http://drupal.org/node/143468

Just a heads up for the mainter(s) of this project :)

#1

Robrecht Jacques - May 15, 2007 - 06:33
Assigned to:Anonymous» Robrecht Jacques

I'm interested in implementing this. I've tried contacting you, but haven't heard from you - so maybe it's not that ASAP.

Just to make sure: you want this for 4.7.x, right?

#2

v1nce - August 22, 2007 - 14:17
Title:bounty for imagefield support» CCK Imagefield Support
Version:4.7.x-1.5» 5.x-1.2
Assigned to:Robrecht Jacques» Anonymous
Status:active» patch (code needs work)

This patch allows images to be imported to nodes for the cck imagefield. There is no ui for this, so you'll need to update your file paths accordingly and edit the code manually at these two lines:

<?php
$file_temp
[$ii] = file_get_contents(file_directory_path() .'/test_image_batchupload/'. $importfile[$ii]['field_image']);
$file_temp[$ii] = file_save_data($file_temp[$ii], file_directory_path() .'/collection/'. $importfile[$ii]['field_image'], FILE_EXISTS_REPLACE);
?>

You're CSV file needs to have the column name of the cck imagefield (ex. field_image) with the filename of each image. Then you just need to upload your images to the temp folder you specified above and import as usual.

If someone could incorporate this within node_import's UI that would be great!

AttachmentSize
node_import_1_0.patch2.13 KB

#3

Petra - September 2, 2007 - 10:57

Works fine for me - thanks!

> If someone could incorporate this within node_import's UI that would be great!

For this, I think you must make the image-folders selectable and change mime_content_type() to a function, which is not deprecated.
Do you know an alternate function for mime_content_type()?

#4

sliiiiiide - September 3, 2007 - 06:55

Good stuff.

Imagecache images are not created though.

I had to create a new imagecache preset (identical settings to my previous one), just with a different name in order to get imagecache working...

#5

tacobot - October 30, 2007 - 18:07

question regarding the filepath part of the code - is the relative to the "files" directory that drupal uses?

so, '/test_image_batchupload/' would be a dir under "files"?

#6

v1nce - October 31, 2007 - 02:47

Yes it is under the drupal 'files' directory. You can see the code is calling the file_directory_path() function.

#7

moshe weitzman - November 19, 2007 - 20:08

imagecache is independant of this. it acts when images are first requested, so just start using your site and it will start transforming images on the fly (and caching them to disk as it goes)

i'd love to see this patch committed in some form. sorry i can't test it right now. just passing through ...

#8

lupus78 - December 10, 2007 - 16:15

I was able to apply the patch, but i can't make this module work. The images are on the server, under the files directory, node_import.module file modified for this subfolder.
I have a column in the CSV, where the image filenames are located, but when I have to do the Mapping i have 3 rows for the imagefield in the dropdown:
thumbnail_image alt
thumbnail_image fid
thumbnail_image title

I've tried to assign my image column with all the 3 fields, but non imported my images!!!

Please help me!

#9

ixlr8 - December 14, 2007 - 22:06

Is this patch for 5.x or for 4.7?

#10

arcX - December 20, 2007 - 17:29

Works for me. Running 5.5.
Would there by a simpler way of doing it having the files on the local system?

I guess you would not have to copy the files, you would just need to get the filepath, and related database fields filled in correctly?

#11

konsumer - January 4, 2008 - 09:22

Re: mime_content_type

php manual says to use:
http://us3.php.net/manual/en/ref.fileinfo.php

Here's how to make a new one, if it's missing:

<?php
if (!function_exists('mime_content_type')) {
    function
mime_content_type($filename) {
       
$finfo    = finfo_open(FILEINFO_MIME);
       
$mimetype = finfo_file($finfo, $filename);
       
finfo_close($finfo);
        return
$mimetype;
    }
}
?>

I'm not sure I agree with the deprecation reason:

This function has been deprecated as the PECL extension Fileinfo provides the same functionality (and more) in a much cleaner way.

#12

scroogie - January 4, 2008 - 09:50

Why does this patch use file_get_contents and file_save_data instead of just calling file_move() or file_copy()? The content is not even unset, so it loads all files to the memory during import.

#13

konsumer - January 5, 2008 - 06:15
Status:patch (code needs work)» patch (code needs review)

I implemented UI support, along with some other features.

Here are the things I didn't like about the other solution:

  1. settings require a UI to be useful, and there is already a UI for "where does the file get saved to" in the field settings for your imagefield.
  2. extra function buildStock is not really needed, it's an extra parse of the CSV file. The above solution could actually be implemented easier, using array_combine($header, $row)
  3. I didn't like the file_get_contents stuff, and general memory-hogginess either
  4. No support for titles, alt, etc, and the original support was broken (it just inserted blank files)
  5. It's a CCK specific thing, so I think it should be in supported/cck/content.inc.
  6. No rollback support. If the rest of the node fails, it shouldn't add a file.
  7. No preview.
  8. Depracated mime function

I realize this was a quick hack, and it definitely helped get me on the right track to making it work my way, so I apprecaite it.

I implemented it in supported/cck/content.inc. I made one very small change in the main module to pass $node by reference, so the pre-process on preview view can alter it.

Now files act more like node_reference or user_reference. Map your image filename field to fid. If it's a number, it will use that as the actual fid, but if it's not, it will save it until after the node is saved, then insert imagefield data. It combines any other fields you provide, too, so you can set a fieldmap for title and alt, and it will actually add it correctly (as long as you have another field mapped to fid.) This adds support for preview. This also adds support for multiple file fields being used in one import.

This patch also includes a fix to an issue that others were having (need link) which I needed to apply to even get node_import working for me.

Usage:

  1. Make sure there is a field that just has the image data I will use an example: column name:"images", example data:"smiley.gif"
  2. Make sure your default content-filter allow images. Mine didn't on a new demo site, and it took me a while to figure it out.
  3. Make sure your image is saved in the folder that the image field points to. in this example I will use "images" so you should have a file "files/images/smiley.gif" The default (if you didn't set this in the field properties) is files/
  4. Import as usual, set the fid to the field that has your image name ("images"->yourfield->fid)
  5. If you map alt or title for that field, make sure you also have a fid field set, or you will get the old problem of it inserting blank file records.
AttachmentSize
node_import_imagefield_support.patch5.73 KB

#14

konsumer - January 5, 2008 - 11:23
Assigned to:Anonymous» konsumer

I'm not sure if it's correct to assign this to myself, but I didn't use any of the original code. If this is a faux pas, just set it back to Robrecht Jacques or v1nce.

#15

arcX - January 7, 2008 - 12:30

Here are some notes from my testing of the node_import_imagefield_support.patch patch:

1. I applied the patch, node_import_imagefield_support.patch. I think it applied ok, even though it threw a couple of errors.
2. I ran a test case, note that I needed to enter the full path to the image. I got that from looking at the files table, to see an existing image entry. Note that I am using a multisite setup. Here is my import text file:

"TITLE","BODY","USER","Images","extra1","extra2"
"new pic","some body text","Username","sites/name_of_site/files/1.jpg","extra 1","extra 2"

            [fid] => 11
            [title] => extra 2
            [alt] => 1.jpg
            [nid] => 46
            [filename] => 1.jpg
            [filepath] => sites/name_of_site/files/1.jpg
            [filemime] => image/jpeg
            [filesize] => 7592

So, yes it worked for me but 1. I found it a little confusing that I needed to map the "image fid" field to the image location itself, considering that the fid is really just an id field.
2. When it came to mapping the fields, though I mapped "extra 1" to the alt path, it got entered the fid column entry. See array above.

#16

konsumer - January 12, 2008 - 12:05

Thanks for reviewing.

1. >> even though it threw a couple of errors.
What were the errors? If I know what's wrong, I'll fix it in the next patch that addresses some of the other issues you mentioned.

2. You need to set the file field to just the name, no path. You set the path in your field settings for the content type. For example, if I have a content-type called "press" and it has an image field called "cover_image" I go to /admin/content/types/press/fields/field_cover_image and set "Image path" to "images/press", or whatever, which is relative to the site files dir. If you didn't set this, it should still grab the correct files dir, based on your site file settings. If this is not working correctly, let me know, and I will look at this. Also, the file needs to really exist in that location, or it will not add it.

so my CSV/TSV data looks like this:

file
cool.gif

and it will look for YOURFILEDIR/images/press/cool.gif

1. I followed the same convention set for uid, tid, and others. Maybe I should figure out how to change fid to just "File" so it looks more like User, Taxonomy, etc. I think that's a great suggestion.

2. I am passing the old stuff through on alt/title, so it may be a bug in the original way it handled alt/title. I'll have to look at that, closer. In my testing I just used title and fid, so it worked ok, but maybe it screws up with multiple non-fid fields.

#17

BradM - January 19, 2008 - 07:05

Looking forward to this -- I actually did a messed-up work-around at my site. I had about 1000 CCK nodes that I bulk imported a while back, all of which had a text field with an image name (as in 'foo.jpg'). I then just used a custom template to display these full-res images, uploaded separately via ftp, as part of the node.

I then added an image field to this node type, once I realized what an image field was. ;) Then, through some mysql trickery via phpmyadmin, and the bulk image import via the image module, I managed to translate all these text-field images to actual image field images.

So now they nicely display thumbnails in the node, which link via lightbox to a full-screen popup. :)

Messed up way to do it, but I was backtracking. ;)

Brad

#18

arcX - January 24, 2008 - 15:32

I have been using it quite a bit now and not getting any unexpected errors. Afraid I forgot the old errors, maybe they were just to do with missing images as below.

I am still using the full path for the fid as in sites/sitename/files/works/14.jpg and it is working fine like that.
I tested with just using filename and I get this error for each of the images, which is the same error I get when I am missing image files:
warning: filesize() [function.filesize]: stat failed for 2.jpg in /home/alex/workspace/nonca/ws/modules/contrib-5/node_import/node_import.module on line 75.

BTW The 'works' part is from the path I already had set in the content type imagefield settings as you described. Also I am using a multisite setup and I set the filepath in the settings file, in case this has anything to do wit it, with:
$conf = array(
'file_directory_path' => conf_path() . 'files',
)

Alt for images still not working for me when I try to map it to the title - but that is a little niggle.

I tested with single select taxonomy and that also worked, but I guess that did not change with the patch.

Great module!

#19

arcX - January 24, 2008 - 15:56

Just to follow up, that the image title is mapping, and for me that is actually more important than the alt title, anyway.

title
Pears

field_image

Array
(
    [0] => Array
        (
            [fid] => 20061
            [title] => Pears
            [alt] => 2107.jpg
            [nid] => 21871
            [filename] => 2107.jpg
            [filepath] => sites/ws.50/files/works/2107.jpg
            [filemime] => image/jpeg
            [filesize] => 145316
        )

)

#20

tacobot - January 29, 2008 - 20:59

I've been using the reworked code - works great. Was curious if there is a way to import multiple images for a single image field using this. Instead of creating an image field for each image on a node.

#21

jthaxton@drupal.org - January 30, 2008 - 22:25

If it helps, I get this deprecation error at the top of the page:

Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of [runtime function name](). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file in C:\wamp\www\drupal-5.3\modules\node_import\node_import.module on line 621

However, it still works just fine!

#22

gagarine - February 7, 2008 - 10:06

very sexy feature! subscribing...

#23

gagarine - February 7, 2008 - 14:45

Wouha konsumer patch work like a dream...

I use it to import product from csv to ubercart (i have also image_cache enabled). All thing is ok in my case.

Just one thing, if the file is not present the error look like this:

    * warning: filesize() [function.filesize]: stat failed for files/product_images/test2.jpg in /home/gagarine/public_html/rodisa/sites/all/modules/node_import/supported/cck/content.inc on line 213.

I think a message like "image not found: /files/product_images/test.jpg" is more user friendly.

#24

konsumer - February 7, 2008 - 15:12

Great suggestion. I'll add this to my next patch.

#25

scroogie - February 7, 2008 - 15:13

You could add a

if (!file_exists($node->$dummy_name))
// do something

check before doing the filesize() call to supress that. But there needed to be a policy first how to work with files that don't exist. Do you want the entry in the filetable to be created or not? Do you want the reference in the node to be saved or not, etc.

#26

gagarine - February 8, 2008 - 10:33

perhaps like for taxonomy term : warn, add reference or do noting

#27

deekayen - February 27, 2008 - 18:42
Version:5.x-1.2» 5.x-1.3
Category:support request» bug report
Status:patch (code needs review)» patch (code needs work)

I installed CVS revision 1.50.2.3.2.9 of node_import.module, which is tagged for node_import 5.x-1.3, and it appears now as a result of this issue, I have the following on the top of every page load:

Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of [runtime function name](). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file in /Users/davidnorman/Sites/test25/sites/all/modules/node_import/node_import.module on line 616

Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of [runtime function name](). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file in /Users/davidnorman/Sites/test25/sites/all/modules/node_import/node_import.module on line 659

I only looked at the diff enough to see there's a new $function(&$node, $preview > 0) in the code. It's deprecated because it's hacky. Can the ampersand not go in the function declaration instead?

#28

konsumer - February 28, 2008 - 07:51

I think that is a fine solution, I wanted to not modify the original function (make as few changes as possible, and do it all in a contrib sub-module) but it seems like that is a better way to allow the fake node to be passed back and forth. I think I will look over all this stuff when I get a bit more time (I am so busy right now), and restructure it a bit, implementing all these ideas. Feel free to jump in, anyone else, and play around with it...

#29

autonetex - March 24, 2008 - 04:32

I was trying to install 5.x-1.5 latest, patch with imagefield mentioned here, nothing is working for me. Does it mean that I need 5x.-1.3?
Desperately need imagefield support. I'm throwing bounty for this. Please help ASAP.

#30

konsumer - March 28, 2008 - 14:12
Version:5.x-1.3» 5.x-1.5

Here's a patch that works for 5.x-1.5.

I still need to implement the other ideas when I have a little more time.

AttachmentSize
node_import_imagefield_support.patch4.61 KB

#31

johannes_db - April 12, 2008 - 22:05

I only see the image in 'preview' mode.. once the import is finished the images are not in the node.. am I doing something wrong?

(using 5.x-1.5 and latest patch)

#32

introfini - April 14, 2008 - 22:12

Hi,

The same is happening to me...

Thanks.

introfini

#33

introfini - April 17, 2008 - 11:11

Hi,

I found out where the problem is.
After applying the patch you need no comment out the line #183

  //unset($node->$dummy_name);

Regards,
introfini

#34

doorjam - April 22, 2008 - 19:09

Hi.

I applied the patch in post #30 to version 5.x-1.5. I am having the same issue with images showing up in preview but not in the node view.

I tried commenting out line #183 (suggested in post 33), but got error messages.

I am using just the image name (e.g. image.jpg) in the CSV field that maps to fid, not the full url of the image. I leave image alt and image title blank.

Also: I did have to set my default content filter to full HTML to get it to work.

Any Ideas. Thanks.

#35

johannes_db - April 23, 2008 - 08:43

hello,

commenting out line #183 (suggested in post 33) gives me:

PHP Fatal error: Call to undefined function finfo_open() in /sites/all/modules/node_import/supported/cck/content.inc on line 248

..

#36

introfini - April 23, 2008 - 12:54

That’s good it shows that the code is going to the new function :-)

Now you need to install the PECL package http://pecl.php.net/package/Fileinfo

The commenting out of the unset is just a quick fix, I will try to post a new patch that fixes that problem and a other one where alt and title fields aren’t set (a problem with the array_merge) .

introfini

#37

doorjam - April 24, 2008 - 12:09

Is PECL package fileinfo required for this patch to work? I believe my shared hosting acc. only supports PEAR packages.

#38

zeezhao - April 24, 2008 - 12:15

Hi. I am interested in this too, as I cant get product images to import for use in either ecommerce or ubercart.

I am running drupal 5.7 with node_import 1.5, ecommerce 3.4 (also tried ubercart 1.04 in another database with same results). It gets to the "Apply (import nodes)" button, and then does nothing after the button is pressed...

Alternatively, please could you post a zip file of a version of node_import that works for images? Thanks for your help.

#39

introfini - April 24, 2008 - 13:45

@timkolke: Yes, or you need to have the mime_magic extension installed.

introfini

#40

cangeceiro - April 28, 2008 - 16:02

i am trying to use the patch offered in comment #30 but it doesnt seem to be working. the patch came back and said it applied, but i am not getting the images at all.

i have all my images in the "files/" directory. and the csv only contains the names of the image, no path. node_import 1.5 and drupal 5.7

#41

introfini - April 28, 2008 - 18:16

hi,

the images must be in the correct directory and they must have the right permissions.

introfini

#42

cangeceiro - April 28, 2008 - 18:31

yup, im a dumb ass and didnt have the permissions set right on the local filesystem. thanks

#43

doorjam - April 28, 2008 - 18:49

Images are now importing! My shared hosting admin was kind enough to install the Fileinfo extension.

I get these error messages, however.

warning: finfo_open() [function.finfo-open]: Failed to load magic database at '/etc/magic'. in /users/home/kolke/domains/kissandmakeupstore.com/web/public/sites/all/modules/node_import/supported/cck/content.inc on line 249.

warning: finfo_file(): supplied argument is not a valid file_info resource in /users/home/kolke/domains/kissandmakeupstore.com/web/public/sites/all/modules/node_import/supported/cck/content.inc on line 250.

warning: finfo_close(): supplied argument is not a valid file_info resource in /users/home/kolke/domains/kissandmakeupstore.com/web/public/sites/all/modules/node_import/supported/cck/content.inc on line 251.

Line 183 is commented out: //unset($node->$dummy_name)

Thanks.

#44

introfini - April 28, 2008 - 22:35

@timkolke: fileinfo is very problematic. I've used mime_magic instead.

introfini

#45

cangeceiro - April 29, 2008 - 15:16

does patch 30 support importing multiple images into one imagefield? if so what is the proceedure? this is the only thing i havent figured out at this point.

#46

doorjam - April 29, 2008 - 16:51

Thanks for the reply introfini. I don't know anything about this stuff, but here is some info I found:

This extension [i.e. mime_magic] has been deprecated as the PECL extension Fileinfo provides the same functionality (and more) in a much cleaner way.

Here is a link: http://ca3.php.net/manual/en/intro.mime-magic.php

I don't think I can use mime_magic with my shared hosting.

Cheers.

#47

konsumer - April 30, 2008 - 19:15

I mentioned this, above, that's why I used a fileinfo adapter.

if you have mime_content_type, but not finfo, it will just ignore this function.

I am currently working on a better solution for imagefield imports, in a separate include in supported/cck, rather then a patch to supported/cck/content.inc

I've got all the above suggestions implemented (more UI options, etc)

I still need to work out the proper way to do previews (the fake node passed back and forth on import), but image importing is working correctly, other then that.

As a side note, I also wrote taxonomy_field, foreign_key (like if you have an ID field in another data-source) import modules and services modules for import and file management.

I will be releasing everything very soon.

#48

gthing - May 14, 2008 - 22:47

After applying the patch from comment #30, I see the following:

Fatal error: Cannot redeclare content_node_import_postprocess() in [...]/public_html/drupal/modules/node_import/supported/cck/content.inc on line 195

I put the patch in the same directory as content.inc and ran "patch < node_import_imagefield_support_0.patch" via ssh. It appeared to patch fine reporting "patching file content.inc"

I am using CCK 5.x-1.7 and node_import 5.x-1.6

Any ideas? Thanks...

#49

gthing - May 14, 2008 - 23:01

Ahh .. it looks like the most recent node import (1.6) busted the patch. I tried with 1.5 and it appears to be working. 1.6 does not include this patch, unfortunately.

#50

uber_serg - June 8, 2008 - 12:06

How i can support importing multiple images into one imagefield with this patch?

#51

goodeit - June 16, 2008 - 14:44

konsumer,
Did you ever release this? I would love to test it for you, as image import is something I really need...

#52

Ozeuss - June 24, 2008 - 17:15
Version:5.x-1.5» 5.x-1.6
Status:patch (code needs work)» patch (code needs review)

I've took Konsumer's patch and changed it a bit so it accomodated 1.6. basically, the dummy name unset is pushed to the postprocess hook.
i also throwed a file_exists() so if a node is missing an image it won't stop the whole upload.

Comments are welcome.

P.S- this patch and issue is well over a year old, any chance of commiting it?

AttachmentSize
imagefield.patch5.35 KB

#53

tibek - June 25, 2008 - 16:26

Hi,
Is there any solution for multiple value for the same image field like terms with the pipe separator?
Thanks.

#54

yhager - July 3, 2008 - 11:44
Status:patch (code needs review)» patch (code needs work)

The patch in #52 applies cleanly and works fine.
I had to remove the added 'file_exists()' check, since I didn't want to fail the whole import of a node if a file does not exist. Please consider rerolling the patch without it.

#55

Ozeuss - July 6, 2008 - 13:10

The solution might be to add a file_exists check, but to not throw an error if it fails, just unset the the dummy var.

#56

yhager - July 6, 2008 - 17:44

I guess you are right, I haven't familiarized myself with the implications.. would you reroll the patch then?

#57

Ozeuss - July 10, 2008 - 10:51

instead of outputing to error[], i've set a message.
i added a trim before file name to avoid space errors in the csv file.

AttachmentSize
imagefield2.patch5.43 KB

#58

grah - July 11, 2008 - 22:31

interested in this.

subd.

#59

marciaj - July 14, 2008 - 02:54

Just to add to this thread. I had problems importing images using the patch because the import overwrote my content template. However, I discovered that if I sized my images to the specifications of the thumbnail settings I would be able to import all my content. ...no problem. The other thing I found was that I had to place the images into my files directory because I would get an error message when I attempted to import referencing the images directory. Now I dont have to edit my nodes individually, which is great because it's a time saver.

#60

kanted - August 2, 2008 - 06:58
Assigned to:konsumer» Anonymous

I tried patch 52 and landed into a wsod ,Don't know much abt Php all i did try to change the content.inc file in the Nodeimport/supported folder.

I would like to know if there is anyother thing that need to be done. I change the filed and am still not able to attach images.

If i don't chhange the .inc file it works fine but i am not able to upload the images.

Any help/pointers will be highly appreciated.

Thanks,
Vinod

#61

a_c_m - August 12, 2008 - 12:56

@ #57

instead of outputting to error[], i've set a message.

Why? You've also changed it so the message is only set if $preview is true. Took me a while to find this. I dont think this patch adds anything (except perhaps the use of trim() ).

#62

giorgio79 - September 4, 2008 - 21:19

Thanks for the patch, will be trying it

#63

natrio - September 15, 2008 - 21:28

Hi, like the several posts above, I'd like to know too whether this patch supports importing multiple images into one imagefield. Is this possible?

#64

LGyucha - September 23, 2008 - 16:42

Solution for multiple image import should be welcomed.

#65

ksenzee - October 7, 2008 - 17:15

I'd suggest that before this patch is committed, it could use

# an option for whether or not to import nodes if the image is missing, similar to the UI option for what to do about non-existing taxonomy nodes. This would take care of the disagreement between #54 and #61 above.
# Token module support, in case the imagefield widget's default file path includes tokens. At the moment it's interpreting them literally, so in my case it went looking for a path named 'images/[yyyy]/[mm]'.
# the instructions from #13 put somewhere in the UI.

The patch is hugely helpful as is, though. Thanks a ton. Sorry I'm not more help -- I'm under a deadline or I'd do some work on it myself.

P.S. Multiple image support would be great, but I think this feature is useful enough to go in as is, with multiple images in a separate patch. Just my opinion.

#66

doomed - October 13, 2008 - 05:07

Whats the best latest most recent patch ?

I would like to use this to import a bunch of new products with images into Ubercart.

Using:
- drupal 5.10
- ubercart 1.5
- node_import 1.6

 
 

Drupal is a registered trademark of Dries Buytaert.