summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgen_thumbs.php7
-rw-r--r--phpfspot.class.php34
2 files changed, 41 insertions, 0 deletions
diff --git a/gen_thumbs.php b/gen_thumbs.php
index f6742e0..05b7d0c 100755
--- a/gen_thumbs.php
+++ b/gen_thumbs.php
@@ -37,10 +37,12 @@ $overwrite = false;
$short_options = "";
$short_options.= "h"; /* help */
$short_options.= "o"; /* overwrite */
+$short_options.= "c"; /* cleanup */
$long_options = array(
"help",
"overwrite",
+ "cleanup",
);
/* command line option specified? */
@@ -66,6 +68,11 @@ if(isset($_SERVER['argc']) && $_SERVER['argc'] > 1) {
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);
diff --git a/phpfspot.class.php b/phpfspot.class.php
index 826fafd..837e3e1 100644
--- a/phpfspot.class.php
+++ b/phpfspot.class.php
@@ -2370,6 +2370,40 @@ class PHPFSPOT {
} // 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
?>