FlickrSync appears to be running as expected except that the actual fullsize image files appear to be systematically deleted from the site files directory (via cron?) after being sync'd from Flickr. The corresponding Flickr thumbnail files are left in place.

Running Drupal 6.8, with:
CCK 6.x-2.1
FileField 6.x-3.0-alpha5
FlickrSync 6.x-1.x-dev
FlickrAPI 6.x-1.x-dev
ImageAPI 6.x.1.2
ImageField 6.x-3.0-alpha3

CommentFileSizeAuthor
#21 flickrsync_tmpfile_fix.patch645 bytesWiredRogue

Comments

sejtraav’s picture

I am having this issue too.
Any solutions?

sejtraav’s picture

Priority: Normal » Critical
benshell’s picture

I can't imagine why this would happen, but it'd be great if you could help debug this further. To start with, can you reproduce the problem without FlickrSync by just using the ImageField and/or FileField modules by themselves?

sejtraav’s picture

I have other imagefields, but only the one associated with FlickrSync is being removed

xolotl’s picture

hmmm, not sure how to reproduce further

I am also manipulating the flickr images via imagecache (6.x-2.0-beta5)...I wonder if it could it be that on transformation by imagecache, the original file from flickr is deleted by imagecache?

xolotl’s picture

Status: Active » Closed (fixed)

OK, I think I figured out what was happening and apparently fixed it, although I do not know why it was happening.

Imagecache indeed seems to be the culprit, but it is in beta, so not unsurprising. I will try to file an issue in the imagecache queue.

One of the imagecache presets that I was applying to the flickrsync imagefield was apparently not working correctly. Maybe because the preset was failing, the images it was manipulating were deleted in the failed preset process.

I flushed that specific imagecache preset, and updated it (without changing any of its settings), which seemed to get the preset working again. Then if I updated any flickrsync imagefield from flickr, the preset in question worked and the original file was not deleted.

I then used the unix wget command with a file that listed the flickrsync update urls (eg, http://yoursite.tld/node/nid/flickrsync) for every node with a flickrsync image field to systematically update everything from flickr (make sure you temporarily enable the update from flickr permission for anonymous users so wget can do its work).

Now it's all working as designed, click on a header image at http://xolotl.org/.

xolotl’s picture

Status: Closed (fixed) » Active

Actually, perhaps I spoke too soon.

Gradually, all original sync'd flickr images still disappear from the files directory (thanks to cron?).

I can resync all images by updating from flickr (even using the bulk wget method above), but over time, all the original pictures will again disappear.

I'm now again suspecting something that happens during cron...perhaps there's an issue if anonymous users (eg, cron) do not have the update from flickr permission? I'm leaving that permission on for anonymous users as a test to see if the original images still disappear.

However, that's not a good fix, because I don't want anonymous users to see the update from flickr control on every page.

xolotl’s picture

Further info: Allowing anonymous users the update from flickr permission has no effect. All original images sync'd from flickr still disappear in a few hours (I have cron set to run hourly).

xolotl’s picture

Further info: original flickr image seems to be deleted during "update from flickr" after initial sync.

Images sync perfectly when they are first posted to flickr via cron. Immediately running cron after first sync does not remove original sync'd image. However, running "update from flickr" does remove both sync'd image and thumbnail.

elly’s picture

I think this just happened to me, also. I ran cron and it imported all my new images since the last import, but removed all my old ones! The thumbs are still in the directory but all the originals are gone, as reported.

In addition, I got a ton of these errors, which I'm not sure are related - those are really weird, I had no files named anything like these filenames on my site, but I thought I'd show them in case they are a clue.



    * warning: unlink(/tmp/currency.1031.1894.uo8rrp.cache) [function.unlink]: Operation not permitted in /home/ellyjonez/dev.elly.org/sites/all/modules/flickrapi/phpFlickr/phpFlickr.php on line 139.
    * warning: unlink(/tmp/bestsellers.1031.1894.uo8rrp.cache) [function.unlink]: Operation not permitted in /home/ellyjonez/dev.elly.org/sites/all/modules/flickrapi/phpFlickr/phpFlickr.php on line 139.
    * warning: unlink(/tmp/prices.4.1031.1894.uo8rrp.cache) [function.unlink]: Operation not permitted in /home/ellyjonez/dev.elly.org/sites/all/modules/flickrapi/phpFlickr/phpFlickr.php on line 139.
    * warning: unlink(/tmp/prices.5.1031.1894.uo8rrp.cache) [function.unlink]: Operation not permitted in /home/ellyjonez/dev.elly.org/sites/all/modules/flickrapi/phpFlickr/phpFlickr.php on line 139.
    * warning: unlink(/tmp/prices.1.1031.1894.uo8rrp.cache) [function.unlink]: Operation not permitted in /home/ellyjonez/dev.elly.org/sites/all/modules/flickrapi/phpFlickr/phpFlickr.php on line 139.
    * warning: unlink(/tmp/prices.2.1031.1894.uo8rrp.cache) [function.unlink]: Operation not permitted in /home/ellyjonez/dev.elly.org/sites/all/modules/flickrapi/phpFlickr/phpFlickr.php on line 139.
    * warning: unlink(/tmp/prices.105.1031.1894.uo8rrp.cache) [function.unlink]: Operation not permitted in /home/ellyjonez/dev.elly.org/sites/all/modules/flickrapi/phpFlickr/phpFlickr.php on line 139.
    * warning: unlink(/tmp/prices.104.1031.1894.uo8rrp.cache) [function.unlink]: Operation not permitted in /home/ellyjonez/dev.elly.org/sites/all/modules/flickrapi/phpFlickr/phpFlickr.php on line 139.
    * warning: unlink(/tmp/upsales.1031.1894.uo8rrp.cache) [function.unlink]: Operation not permitted in /home/ellyjonez/dev.elly.org/sites/all/modules/flickrapi/phpFlickr/phpFlickr.php on line 139.

:( :(

xolotl’s picture

Further information: the original flickr image appears to be deleted when the "update from flickr" process is run another time after the original image is first imported.

xolotl’s picture

I think I've narrowed it down to an issue with line 788 in the flickrsync_download_photo function in the flickrsync.module file:
if ($file = field_file_save_file($filename, array(), $directory, TRUE)) {

The line above successfully returns an array to $file, but does not successfully copy the file from the temporary flickrtemp directory to the permanent files directory. If the file already exists in the permanent directory, it is deleted.

The very next line deletes the temporary copy, so all copies of the original flickr image are gone.

Are we sure that the field_file_save_file is the right filefield function to use here? Or perhaps this is an issue with filefield module?

mariusooms’s picture

Hmmm...experiencing the exact same behavior...odd though, out of all images a few do remain.

Subscribing to a solution.

mariusooms’s picture

I found a related issue somewhere else, but for another function file_save_upload. Maybe change field_file_save_file to the file_save_upload function together with file_set_status($file, FILE_STATUS_PERMANENT);? Seems files are not saved properly when cron runs before it is saved to the table? Just shooting one of in the dark here, but I do think the issue lies somewhere in this code.

In D6, files now have a status. By default, the uploaded file is considered temporary and will be deleted on the next cron run after 24 hrs. So, if there is a file_save_upload and the same function does not include file_set_status($file, FILE_STATUS_PERMANENT);, it would be nice to issue a warning that the file may be deleted as a temporary file.

Regards,

Marius

pfrilling’s picture

I added the following code to the flickrsync_download_photo function below the field_file_save_file line that Marius was referring to:

$tempfile = (object)$file;
file_set_status($tempfile, FILE_STATUS_PERMANENT);

After importing and updating flickr images, I checked the files table and the file status was changed from 0 to 1.

Phil

--

xolotl’s picture

pfrilling's suggested fix in #15 of #357711: sync'd images removed by cron? above did not work for me...files modified locally still get deleted in the next cron job

internets’s picture

I'm also having this problem.

Using Drupal 6, image_cache, cck image field, and a views slideshow. When I initially setup my images and sync them from flickr the slideshow is working great. I have views slideshows generated based on my Flickr images. Then I check the next day, I believe after cron has run. No slideshow, no images showing up until I go to the node and 'update from flickr'.

Any working fixes? I'm going to make sure I'm using the latest version of all related modules, try new image cache presets. Anyone have a fix for this?

internets’s picture

Ok well after some trouble shooting and re-reading of this thread I think I have got everything working correctly (for my specific needs).

The problem was any time cron ran the images would disappear. The original files were being deleted. The images would also disappear if I ran "Update from Flickr" on any node created with Flickr Sync.

I added this: around line 789 of flickrsync.module

if ($file = field_file_save_file($filename, array(), $directory, TRUE)) {
    //if ($file = file_save_upload($filename, array(), $directory, TRUE)) {
    // file_set_status($file, FILE_STATUS_PERMANENT);
    $tempfile = (object)$file;
    file_set_status($tempfile, FILE_STATUS_PERMANENT);
    ...

When I tried file_save_upload as recommended above my images were not saving properly unless I'm using it incorrectly but the params all seem to match up with the description in the drupal API.

After adding the above code the images are not disappearing when cron runs and new images are automatically imported / created. If I run "Update from Flickr" on any flickr sync node the images still disappear.

So it seems to be working ok as long as no one ever uses the "Update from Flickr" link. I haven't noticed any other issues yet and I have ran cron a number of times to verify that newly tagged Flickr photos automatically start showing up in my slideshow.

*edit*

Another note after some more testing I was wondering if I could untag images in Flickr and then they would then be unpublished / deleted from my site when cron runs the 'flickr-sync'. The images remain published / active. Are they supposed to get unpublished if the tag is removed on flickr? That is the point of a 'sync' correct?

Maybe this is related to the above edits?

I'll just manually unpublish any images I don't want for now.

glove’s picture

Taking a look at this, I see the likely culprit being line 667 in the flickrsync.module file:
$file = flickrsync_download_photo($flickr_photo, 'largest');

When flickrsync_download_photo returns false (often timing out with Flickr), $file stores as FALSE. However, since there is no check for $file, it continues to rebuild the node and submit it with an empty file. Below is the suggested fix:

// get the path to the largest available image size (cached locally)
$file = flickrsync_download_photo($flickr_photo, 'largest');
if (!$file) {
drupal_set_message(t("Couldn't download file, unable to save image %photo_id", array('%photo_id' => $photo_id)));
return FALSE;
}

Since this happens sporadically, I'm still checking to see if this does the trick.

elly’s picture

glove - interested to know if this solution worked for you. please update us!

WiredRogue’s picture

StatusFileSize
new645 bytes

With glove's change (#19), I've added the file_set_status of internets (#18)

So far this is working on my test system. Entries in the files table are saved with a status of "1" instead of "0" and are not removed during cron runs. I overwrote the DRUPAL_MAXIMUM_TEMP_FILE_AGE in settings.php to be able to test this in minutes vs hours. ( define('DRUPAL_MAXIMUM_TEMP_FILE_AGE', 300); )

The following code is the patch:

--- flickrsync.module.orig 2008-10-31 18:00:51.000000000 -0500
+++ flickrsync.module   2009-12-18 12:25:05.000000000 -0600
@@ -665,6 +665,13 @@

   // get the path to the largest available image size (cached locally)
   $file = flickrsync_download_photo($flickr_photo, 'largest');
+  if (!$file) {
+    drupal_set_message(t("Couldn't download file, unable to save image %photo_id", array('%photo_id' => $photo_id)));
+    return FALSE;
+  }
+  // Set file to permanent status so it isn't cleaned up later
+  $fileobj = (object)$file;
+  file_set_status($fileobj, FILE_STATUS_PERMANENT);

   $content = '';
   if ($flickr_photo['description']) {
cashwilliams’s picture

There hasn't been any activity on this thread for around 6 months, but I have recently installed Flickr Sync and am having this issue so I figure its still a problem.

I am going to test the patch above in #21 and I'll post results. Any idea on when this issue will be fixed in the release?

cashwilliams’s picture

The patch seems to have fixed the problem. My site has been running for about a week now without losing any of the images.

However, I know have an issue with the number of photos imported. In the settings, the maximum number of flickr images to import during each cron run isn't working as it should. With the value set to 5, the same 5 images are imported over and over, so I never had more then 5 images. I've changed this number to 40, but now I'm limited to 40 images. I'm not sure if this is a separate issue, or an issue caused by the patch. I'm going to look for another thread or open a new one.

cyberwolf’s picture

Subscribing.

xolotl’s picture

The patch in #357711-21: sync'd images removed by cron? seems to have fixed the issue for me as well, however I did a couple of things to start fresh which may or may not be necessary to make it work:

  1. deleted all nodes of the content type that was being flickrsync'd
  2. deleted all flickrsync'd images from the files directory
  3. made sure there were no records pointing to flickrsync'd images in the files table or the flickrsync_images table
  4. edited the settings of the accounts of the user(s) who are flickrsyncing to make sure the "Date of first Flickr photo to import" is prior to the first photo in their flickr stream they want to import
  5. returned the flickersync settings at /admin/settings/flickrsync to defaults (ie, 30 sec timeout, 10 photos per cron run)

Flickrsync'd photos then should gradually resync with each cron run and not disappear once in place.

gclicon’s picture

Status: Active » Closed (fixed)

I have tested and committed the patch in #357711-21: sync'd images removed by cron?. Marking this issue as fixed.