I suspect that this is a pretty widespread problem among those of us who use shared hosting: timeouts while using image_import. When it happens, I get partially imported images - some have just the original (fine, because it recreates thumbs, etc.), but some have just the preview/thumbnail!

It's also a pain because I can only do 2-5 high-res pics at a time. I have to re-enter everything again manually.

Here's my work-around. Feel free to use, improve, or shoot it down.

First, I modified image_import_form_submit to output items to a queue table. One row per image:

function image_import_form_submit($form_id, $form_values) {
.
.
.
$db_insert_values = array(
//          $node = image_create_node_from(
            $filename,
            $form_values['title'][$index],
            $form_values['body'][$index],
            preg_replace('/\n|  /','', var_export($form_values['taxonomy'],TRUE))
          );
$db_insert = 'INSERT INTO {image_import_queue} (filepath, title, body, taxonomy) VALUES (\''.implode('\', \'', preg_replace('/\'/','\\\'', $db_insert_values)) . '\')';
db_query($db_insert);
.
.
.

Next, I created a page which reads one record at a time and imports it:


$query = db_query('SELECT * FROM {image_import_queue}');
while($item = db_fetch_array($query)) {
    if(is_writable($item['filepath'])) {
        print $item['filepath'].'<br />'.$item['title'].'<br />'.$item['body'].'<br />'.$item['taxonomy'].'<br />';
        $node = image_create_node_from($item['filepath'], $item['title'], $item['body'], $item['taxonomy']);
        print '<p><a href="' . base_path() . "/node/$node->nid\">$node->title</a></p>";
        db_query('DELETE FROM {image_import_queue} WHERE filepath='.$item['filepath'].' LIMIT 1');
        break;
    }
}

I then have Greasemonkey refresh the page continuously to empty the queue. I can do hundreds of images with minimal effort.

Obviously this has some security concerns: I wasn't careful about validating user inputs. I'm also no PHP guru - C++ is my thing - so it could probably be neater.

I was thinking that this could be a useful option to the image module, with the import being triggered either client-side using Javascript refreshes or server-side using cron.

Now...critique my amateurish code! :)

Comments

soupy’s picture

Addendum: the taxonomy element must be eval()ed while processing the queue. Ooops!

pyutaros’s picture

Subscribing. The image import has been spotty for me at best. Max six images at a time.

drewish’s picture

once we're on Drupal 6 the new batch processing stuff would be the right way to do this.

in the short term you could get your host to extend the script time out. and try out the -dev release it should be better.

pyutaros’s picture

Thanks for the answer Drewish. I think I'm just going to use Acidfree Albums instead. It doesn't work perfectly, but it seems to import the same set of folders with no problem, and so far has been intuitive about retaining gallery structure based on subfolders. You two may want to consider combining forces. Acidfree uses image nodes to create its albums from and there is certainly some feature replication between your two modules. Anyhow, thanks for responding.

Hetta’s picture

Status: Active » Postponed
sun’s picture

Status: Postponed » Closed (won't fix)

Sorry, 5.x-1.x won't see any new features.