singapore: the smallest big galery
home » forum » Mods » Remove deleted images when reindexing

You are not logged in.

  • Index
  •  » Mods
  •  » Remove deleted images when reindexing

#1 2010-01-11 13:30:03

tamlyn
Lead Developer

Remove deleted images when reindexing

For some reason that I don't remember, reindex only imports new images to the gallery but doesn't remove images which have been deleted. This mod fixes that.

In includes/admin.class.php, find the reindexGallery() method (around line 930) and change it to the following (changes marked with //comments):

Code:

  function reindexGallery($galleryId = null)
  {
    if($galleryId == null)
      $gal =& $this->gallery;
    else
      $gal =& $this->io->getGallery($galleryId, new stdClass);
    
    $imagesAdded = 0;
    //get list of images
    $dir = Singapore::getListing($this->config->pathto_galleries.$gal->id, $this->config->recognised_extensions);

    //MOD reindex delete
    $remainingImages = $gal->images;
    //END reindex delete
    
    //cycle through the image files
    for($i=0; $i<count($dir->files); $i++) {
      //search for the image file in the database images
      for($j=0; $j<count($gal->images); $j++)
        //if we find it
        //MOD reindex delete
        if($dir->files[$i] == $gal->images[$j]->id) {
          unset($remainingImages[$j]);
          //skip the rest of this loop
          continue 2;
        }
        //END reindex delete
      //otherwise add the image to the database
      $gal->images[$j] = new sgImage($dir->files[$i], $gal, $this->config);
      $gal->images[$j]->name = $dir->files[$i];
      list(
        $gal->images[$j]->width, 
        $gal->images[$j]->height, 
        $gal->images[$j]->type
      ) = GetImageSize($this->config->pathto_galleries.$gal->id."/".$gal->images[$j]->id);
      $imagesAdded++;
    }
    
    //MOD reindex delete
    foreach ($remainingImages as $index => $image) { 
      unset($gal->images[$index]);
    }    
    $gal->images = array_values($gal->images);
    //END reindex delete
    
    if($this->io->putGallery($gal))
      return $imagesAdded;
      
    return $this->pushError($this->translator->_g("Could not save gallery info"));
  }

The success message will only report added images but images should now be deleted as necessary as well.

Offline

 

#2 2011-06-22 18:06:10

pcphotos
Member

Re: Remove deleted images when reindexing

These seems to break my gallery when used with the latest version. Is that expected?

Offline

 

#3 2011-06-27 19:47:31

DC
Administrator

Re: Remove deleted images when reindexing

What do you mean?

DC


To code or not to code that is the question?

Did my response help you out? Consider donating by buying me a slice, Whats this? Read More!
http://www.clickcraft.net/slice.php

Offline

 
  • Index
  •  » Mods
  •  » Remove deleted images when reindexing