issue98, add function to clean up phpfspot database
authorAndreas Unterkircher <unki@netshadow.at>
Sun, 13 Jan 2008 09:57:43 +0000 (10:57 +0100)
committerAndreas Unterkircher <unki@netshadow.at>
Sun, 13 Jan 2008 09:57:43 +0000 (10:57 +0100)
Signed-off-by: Andreas Unterkircher <unki@netshadow.at>
gen_thumbs.php
phpfspot.class.php

index f6742e08c074c0867e237cfe427cf264845dc088..05b7d0cd465313262898da341cb9b458054157aa 100755 (executable)
@@ -37,10 +37,12 @@ $overwrite = false;
 $short_options = "";
 $short_options.= "h"; /* help */
 $short_options.= "o"; /* overwrite */
 $short_options = "";
 $short_options.= "h"; /* help */
 $short_options.= "o"; /* overwrite */
+$short_options.= "c"; /* cleanup */
 
 $long_options = array(
    "help",
    "overwrite",
 
 $long_options = array(
    "help",
    "overwrite",
+   "cleanup",
 );
 
 /* command line option specified? */
 );
 
 /* command line option specified? */
@@ -66,6 +68,11 @@ if(isset($_SERVER['argc']) && $_SERVER['argc'] > 1) {
             print "Overwrite flag set!\n";
             $overwrite = true;
             break;
             print "Overwrite flag set!\n";
             $overwrite = true;
             break;
+         case 'c':
+         case '--cleanup':
+            $fspot->cleanup_phpfspot_db();
+            exit(0);
+            break;
          default:
             print "invalid option";
             exit(1);
          default:
             print "invalid option";
             exit(1);
index 826fafd2d1101b792306590de0cd032731443a7d..837e3e1db4ffb86ce91fb9f7738705b4d3bde4c2 100644 (file)
@@ -2370,6 +2370,40 @@ class PHPFSPOT {
 
    } // check_config_options()
 
 
    } // check_config_options()
 
+   /**
+    * cleanup phpfspot own database
+    *
+    * When photos are getting delete from F-Spot, there will remain
+    * remain some residues in phpfspot own database. This function
+    * will try to wipe them out.
+    */
+   public function cleanup_phpfspot_db()
+   {
+      $to_delete = Array();
+
+      $result = $this->cfg_db->db_query("
+         SELECT img_idx
+         FROM images
+         ORDER BY img_idx ASC
+      ");
+
+      while($row = $this->cfg_db->db_fetch_object($result)) {
+         if(!$this->db->db_fetchSingleRow("
+            SELECT id
+            FROM photos
+            WHERE id='". $row['img_idx'] ."'")) {
+
+            array_push($to_delete, $row['img_idx'], ',');
+         }
+      }
+
+      $this->cfg_db->db_exec("
+         DELETE FROM images
+         WHERE img_idx IN (". implode($to_delete) .")
+      ");
+
+   } // cleanup_phpfspot_db()
+
 } // class PHPFSPOT
 
 ?>
 } // class PHPFSPOT
 
 ?>