I just fixed an older version of Gallery Assist by changing the file_save_upload portion of the code:


if (is_dir($upload_dir) && $node->newfile['name']['pictures'. $i]) {

              //if (file_save_upload('pictures'. $i, $validators, $upload_dir, $replace = FILE_EXISTS_REPLACE)) {
                $this_file = file_save_upload('pictures'. $i, $validators, $upload_dir, $replace = FILE_EXISTS_REPLACE);

                rename($filepath, $new_filepath);
                image_scale($new_filepath, $gallery_assist_thumbnail, 80, 80);

                if ($conf['use_imagecache'] == 0) {
                  $thmb_size = $conf['upload_thm'];
                  image_scale($new_filepath, $upload_thm, $thmb_size, $thmb_size); 
                  $imageinfo = image_get_info($new_filepath);
                  $my_dim_ref = $imageinfo['width'] > $imageinfo['height'] ? $imageinfo['width'] : $imageinfo['height'];
                  $prev_size = $conf['upload_prev'];
                  if ($prev_size <= $my_dim_ref) {
                    image_scale($new_filepath, $upload_prev, $prev_size, $prev_size);
                  }
                  else {
                    rename($new_filepath, $upload_prev);
                  }
                  // Clear the cached filesize and refresh the image information.
                  clearstatcache();
                }

                file_set_status($this_file, 1);

The 2 lines referencing $this_file are new. Comment out the if statement and its closing brace.

Thanks to ricky1975 in another thread he tipped off to the fact the GA files uploaded were set with a status of 0, triggering Drupal garbage collection on them, resulting in broken galleries.

After this change, files are now status 1, I ran cron and they were left untouched.

It looks like file_set_status() is in the newer versions of GA, but I know a lot of people are still using older versions experiencing this problem. Hope this helps.

Comments

kevinquillen’s picture

Edit: I noticed this from 6.x-1.0 to 6.x-6.16

deggertsen’s picture

I'm a bit confused. I can't find much of the code as you put it above in either version 6.x-1.10 or 6.x-1.15 so I can't figure out what to change. I can find slight variations under "Implementation of hook_save()" but nothing just how you put it above, much of it has "$upl_file->filepath" in there. Are you saying that you replaced everything under the "Implementation of hook_save()" with the code you posted above?

Could you possibly generate a patch and attach it for the current stable release so that I can just apply it and test it?

Thanks for your work on this!

kevinquillen’s picture

No I only changed the part where it wrapped the code with the if (file_save_upload(.. part and just assigned $this_file to file_save_upload inside of function gallery_assist_save().

This is an older version of GA (December-ish). Unfortunately I did this editing on the live server so I can't generate a patch right now. I basically searched for 'file_save_upload' and this was the only spot it turned up in GA.

I commented out the if, and added:

$this_file = file_save_upload('pictures'. $i, $validators, $upload_dir, $replace = FILE_EXISTS_REPLACE);
file_set_status($this_file, 1);
deggertsen’s picture

It looks like that portion has been changed quite a bit to accommodate Gallery Assist Upload and Import Helper so I think it will need to be modified for more recent versions.

The if statement that you are talking about now looks like this:

<?php
$arch_file = file_save_upload('pictures'. $i, $arch_validators, $import_dir, $replace = FILE_EXISTS_REPLACE);
          if (count($arch_file)) {
?>

And the code inside the beginning if statement of the code you posted looks like:

<?php
if (is_dir($upload_dir) && $node->newfile['name']['pictures'. $i]) {

            $replace = variable_get('gallery_assist_upload_method', 1) == 1 ? TRUE : FALSE;

            // In case the file exists remove al derivatives.
            // So can the module write the new files.
            if ($replace == 1 && file_exists($upload_dir .'/'. $node->newfile['name']['pictures'. $i])) {
              drupal_set_message('Files are be replaced. In case you see the old files, you see only from the cache of your browser. By reload you can see the just uploaded.');
              if (file_exists($upload_dir .'/'. $node->newfile['name']['pictures'. $i])) {
                file_delete($upload_dir .'/'. $node->newfile['name']['pictures'. $i]);
                $p_i_d  = db_fetch_object(db_query("SELECT fid, pid FROM {gallery_assist_item} WHERE opath = '%s'", $upload_dir .'/'. $node->newfile['name']['pictures'. $i]));
                if (!empty($p_i_d)) {
                  db_query('DELETE FROM {files} WHERE fid = %d', $p_i_d->fid);
                  db_query('DELETE FROM {gallery_assist_translated} WHERE pid = %d', $p_i_d->pid);
                  db_query('DELETE FROM {gallery_assist_item} WHERE pid = %d', $p_i_d->pid);
                }
              }
              if (file_exists($upload_dir .'/img/'. $node->newfile['name']['pictures'. $i])) {
                file_delete($upload_dir .'/img/'. $node->newfile['name']['pictures'. $i]);
              }
              if (file_exists($upload_dir .'/thm/'. $node->newfile['name']['pictures'. $i])) {
                file_delete($upload_dir .'/thm/'. $node->newfile['name']['pictures'. $i]);
              }
              if (file_exists($upload_dir .'/prev/'. $node->newfile['name']['pictures'. $i])) {
                file_delete($upload_dir .'/prev/'. $node->newfile['name']['pictures'. $i]);
              }
            }

            $upl_file = file_save_upload('pictures'. $i, $validators, $upload_dir, $replace);
            if (count($upl_file)) {
              $a = explode('/', $upl_file->filepath);
              $new_filename = end($a);
              $gallery_assist_thumbnail = $upload_dir .'/img/'. $new_filename;
              $upload_thm = $upload_dir .'/thm/'. $new_filename;
              $upload_prev = $upload_dir .'/prev/'. $new_filename;
              @chmod($upl_file->filepath, 0664);

              $imageinfo = image_get_info($upl_file->filepath);
              $my_dim_ref = $imageinfo['width'] > $imageinfo['height'] ? $imageinfo['width'] : $imageinfo['height'];
              $img_direction = $imageinfo['width'] > $imageinfo['height'] ? 'h' : 'v';

              if (80 < $my_dim_ref) {
                image_scale($upl_file->filepath, $gallery_assist_thumbnail, 80, 80);
              }
              else {
                copy($upl_file->filepath, $gallery_assist_thumbnail);
              }
              @chmod($gallery_assist_thumbnail, 0664);

              if ($conf['use_imagecache'] == 0) {
                $thmb_size = $conf['upload_thm'];
                $prev_size = $conf['upload_prev'] ? $conf['upload_prev'] : 550;

                if ($thmb_size < $my_dim_ref) {
                  image_scale($upl_file->filepath, $upload_thm, $thmb_size, $thmb_size);
                }
                else {
                  copy($upl_file->filepath, $upload_thm);
                }
                @chmod($upload_thm, 0664);

                if ($prev_size < $my_dim_ref) {
                  image_scale($upl_file->filepath, $upload_prev, $prev_size, $prev_size);
                }
                else {
                  copy($upl_file->filepath, $upload_prev);
                }
                @chmod($upload_prev, 0664);

                // Clear the cached filesize and refresh the image information.
                clearstatcache();
              }

              // Set permanent status to the files table entries.
              file_set_status($upl_file, 1);

              $result = db_fetch_object(db_query("SELECT gid, gref FROM {gallery_assist} WHERE nid = %d", $node->nid));
              $item_count = db_result(db_query("SELECT count(pid) FROM {gallery_assist_item} WHERE nid = %d", $node->nid));
              $my_gref = $result->gref ? $result->gref : $result->gid;

              $insert_item_data = array(
                'nid' => $node->nid,
                'ref' => $node->ref,
                'gid' => $result->gid,
                'gref' => $my_gref,
                'sid' => $node->sid ? $node->sid : $node->gallconf[$node->type]['show_download_link'],
                'uid' => $node->uid,
                'fid' => $upl_file->fid,
                'filename' => $new_filename,
                'tpath' => $upload_thm,
                'ppath' => $upload_prev,
                'opath' => $upl_file->filepath,
                'copyright' => $node->temp_copyright,
                'cover' => $cover == 1 ? TRUE : FALSE,
              );
              $insert_item_data['weight'] = $item_count + 2;
              drupal_write_record('gallery_assist_item', $insert_item_data);
              $cover = 0;

              // Get the pid from recent updated file.
              $my_last_incerted = db_last_insert_id('gallery_assist_item', 'pid');

              // See how many language entries, and make the picture-entry for each language.
              $just_translated = db_query("SELECT nid, lang FROM {gallery_assist} WHERE ref=%d", $node->ref);

              while ($r = db_fetch_object($just_translated)) {
                $my_ptitle = preg_replace('/\_/', ' ', $my_ptitle);
                $inset_translated_data = array(
                  'nid' => $r->nid,
                  'gid' => $result->gid,
                  'gref' => $my_gref,
                  'pid' => $my_last_incerted,
                  'lang' => $r->lang,
                  'ptitle' => $my_ptitle,
                  'palt' => $my_ptitle,
                  'pdescription' => '',
                );
                drupal_write_record('gallery_assist_translated', $inset_translated_data);
              }
              if (module_exists('image_upload_gallery_assist') && $node->ga_multiupload == TRUE) {
                drupal_set_message('The image '. $my_ptitle .' was uploaded sucessfull.');
                return $upl_file;
              }
            }
?>

It looks to me like the newer version is attempting to set the files to a 1 status with "file_set_status($upl_file, 1);" so I assume that what you did only works for the older versions.

kevinquillen’s picture

Yeah, this still happens in the newest version??

              // Clear the cached filesize and refresh the image information.
                clearstatcache();
              }

              // Set permanent status to the files table entries.
              file_set_status($upl_file, 1);

Was exactly what was missing in the older versions. The sites I was looking at had 3 different versions.

On the other hand, can it be explained why Gallery Assist needs img/thm/prev and its own foldering structure? Why not just require Imagecache, remove the if/else code regarding Imagecache, lose some of the bloat and whatnot.

If this doesn't stop images disappearing... it -seemed- to work, but it sounds like you are saying it still happens in the newer versions?

deggertsen’s picture

That's right. I'm still having the same problem and it seems that others are too according to some of the other issues in the queue.

I agree with you that this module should just require imagecache as it just makes sense for performance reasons and simplicity reasons.

kevinquillen’s picture

Other than that, I don't see any code at all pertaining to file/image deletion either with GA functions or core Drupal functions (file_delete etc) OR db_query doing anything it shouldn't be doing. Puzzling!

deggertsen’s picture

I noticed in the database that under the table "gallery_assist_translated" there are less values (267, starting with pid 340) than there are in "gallery_assist_item" (441, starting with pid 1). Shouldn't those two values be the same? Just looking at it briefly it looks like gallery_assist_translated is supposed to have an entry for each "gallery_assist_item". Maybe that gives a clue?

kevinquillen’s picture

Hmmm... Wasn't aware it was turned on. Wouldn't translation happen through t() functions and related modules if that's the case? What is that table for?

FreeFox’s picture

Version: 6.x-1.10 » 6.x-1.x-dev

I downloaded the latest dev version (Today = 2010-07-20) and still the status of the files = 0

kevinquillen’s picture

Is it missing from gallery_assist_imagecache and gallery_assist_lightboxes etc

Tran’s picture

This is a terrific module. If only it would stop breaking.

Tran’s picture

My gut tells me it's an issue with Run Cron, because when I was running a poormanscron, it was deleting galleries within hours.
Now, it seems to happen when I update modules, which often involves a run cron.

I've published some more galleries and will test this today.

kevinquillen’s picture

I think that has to do with the garbage collection removing files that are set as temporary status.

deggertsen’s picture

That seems to be the problem. But looking into the code it appears that the files are set to the correct status... Maybe somewhere else that is overridden though?

kevinquillen’s picture

Yeah, thats what I thought I fixed in my original post.

It seems the easiest thing at this point is think about a rewrite. There is a lot of duplicated code, and not a lot of understanding.

Tran’s picture

Just to clarify.
I build a gallery.
A week later, poof, all the pictures are gone.
However, using FTP, I can see that all my images and thumbs are still in the gallery assist filed with the same name as the node. And when I edit the file, all of the pictures are gone, obviously. However, I can see there's a pager, and if there are 81 files in my FTP file, the pager still recognizes 81 files.
But they simply aren't loading.

Has Juan abandoned the project?

jcmc’s picture

Hello Kevin Quillen, deggertsen, midek

I will only inform you that I'm back.

No midek, I haven't abandoned the project, I was only very "busy" the last months.

The whole time I was trying to find the cause of this issue in the module "Gallery-Assist".

The supposition of deggertsen in #4 is correct. I have never asked the people, which have this problem, if they are using the Gallery Assist Upload and Import Helper module and there is one of the causes (maybe the once).

The function "file_set_status()" which set the status of uploaded files to permanent was added in GA version 1.8-beta2. In GA-UPPORT never, although it is very important.
I am now by developing some requested features, the updates, bug fixes etc and want upload the newest stabile (relative ;-) version as a BETA tomorrow.

Regards and Thanks
Juan Carlos

Tran’s picture

Thanks Juan.
I am anxious to begin reloading galleries but I am afraid to start if the problem is not corrected.

FreeFox’s picture

Hi Juan,

Thanks for the heads-up. I didn't see the new release, have you posted one already?
I guess many people are waiting for the fix and you will make many people happy.

Thanks in advance
FF

jcmc’s picture

Project: Gallery Assist » Gallery Assist Upload and Import Helper

For the first I change this report to the right module.

jcmc’s picture

Status: Active » Needs review

Hello all,

I released version 1.0 alpha 1 GA-UPPORT and need testers and feedback concerning to the great theme "Images disappear".

Regards
Juan Carlos

FreeFox’s picture

Just installed alpha 1. I created a gallery, saved, clicked edit again and got this error:

Fatal error: Call to undefined function gallery_assist_check_access() in xxx/sites/all/modules/gallery_assist_upport/gallery_assist_upport.module on line 99

Greetz
FF

jhans’s picture

Version: 6.x-1.x-dev » 6.x-1.0-alpha1

I installed also the alpha and images disappearing. No idea why. Also my already published galleries crashed.

Regards
Joachim

jcmc’s picture

Hello FreeFox,

the error is caused because you need to update to the GA 1.16-alpha1 version.
It is so that with the implementation of the public status settings the new conditions (sub-permissions) are to be checked by the module GA-UPPORT too.

I wrote it just now in the release notes.

Sorry for the late information.

Regards
Juan Carlos

jcmc’s picture

Hello jhans,

I hope this was not in the production server. It is recommended to having a test.server for that. In drupal is a alpha version = test.
Your report give me a idea:

The old version from GA-UPPORT haven't set the file status to 1 and this mean by updates and cron runs the system delete after a determined time all uploaded files with status 0.
I would be grateful if you test to run in your mysql database the statement "UPDATE files SET status = 1 WHERE filepath LIKE ''%files/gallery_assist%".
Is this the solution, I have to integrate it in the next update function.

Can you test it? I have the problem that by my installations or old or new I never got this issue.

I thank you in advance

Regards
Juan Carlos

jhans’s picture

Hi jcmc

Thanks for the reply.

I'll give it a test next week when I am hanging around in a hotel. I have to set that up because I want to bring the website online. By the way I got an error after installing the version saying the node table cannot be found. During the installation I entered a table prefix so the node table has a different name, it's called drupalnode. Here is the error message:

user warning: Table 'db1189643-sccd.node' doesn't exist query: SELECT n.nid, n.title, g.data, p.tpath, p.opath FROM node n JOIN gallery_assist g ON g.nid = n.nid JOIN gallery_assist_item p on p.gref = g.gref WHERE g.uid = 1 AND p.cover = 1 ORDER BY n.created DESC LIMIT 7 in /is/htdocs/wp1189643_SIGGT33CP7/www/sccweb/sites/all/modules/gallery_assist/gallery_assist.module on line 3916.

I like the gallery but I'am playing around now for month. Please help jcmc to get this stuff stable. I am not a developer but if you need help in translation some stuff let me know. The german translation for "public" is "öffentlich" and not "öffentlisch" :-)

Thanks and cheers
Joachim

jhans’s picture

Hi

the bug mentioned in my last post was fixed by myself. Curly brackets where missing for the tables in the SELECT statement starting at line 3885 in the gallary_assist.module.

I have no idea to publish a patch file, so you have to fix it on your site.

Regards

jcmc’s picture

thanks, I will do that.

FreeFox’s picture

Hi jcmc,

Thanks for your answer in #26.

Today (2010-09-08 15.30 CET) I removed and reinstalled GA and GA-Upport.

gallery_assist-6.x-1.16-beta1
gallery_assist_upport-6.x-1.0-alpha2

When doing an update in Drupal I get this error:

Fatal error: Cannot redeclare gallery_assist_update_1() (previously declared in xxx/sites/all/modules/gallery_assist/gallery_assist.install:473) in xxx/sites/all/modules/gallery_assist_upport/gallery_assist_upport.install on line 18

I checked and you have indeed 2 functions with the same name.

Kind Regards
FreeFox

jcmc’s picture

ups! sorry
copy and paste capital error.
It is now fixed. Please use update alpha 3

Thanks Juan

jcmc’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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