issue88, overwrite option for gen_thumbs.php
authorAndreas Unterkircher <unki@netshadow.at>
Tue, 1 Jan 2008 17:43:27 +0000 (18:43 +0100)
committerAndreas Unterkircher <unki@netshadow.at>
Tue, 1 Jan 2008 19:13:15 +0000 (20:13 +0100)
gen_thumbs.php
phpfspot.class.php

index a2235bd8e2e10b921908041513aeab16508f8a37..f6742e08c074c0867e237cfe427cf264845dc088 100755 (executable)
@@ -32,10 +32,52 @@ require_once "phpfspot.class.php";
 $fspot = new PHPFSPOT;
 $fspot->fromcmd = true;
 
+$overwrite = false;
+
+$short_options = "";
+$short_options.= "h"; /* help */
+$short_options.= "o"; /* overwrite */
+
+$long_options = array(
+   "help",
+   "overwrite",
+);
+
+/* command line option specified? */
+if(isset($_SERVER['argc']) && $_SERVER['argc'] > 1) {
+   /* validate */
+   $con = new Console_Getopt;
+   $args = $con->readPHPArgv(); 
+   $options = $con->getopt($args, $short_options, $long_options);
+
+   if(PEAR::isError($options)) {
+      die ("Error in command line: " . $options->getMessage() . "\n");
+   }
+
+   foreach($options[0] as $opt) {
+      switch($opt[0]) {
+         case 'h':
+         case '--help':
+            print "we need some help here!\n";
+            exit(0);
+            break;
+         case 'o':
+         case '--overwrite':
+            print "Overwrite flag set!\n";
+            $overwrite = true;
+            break;
+         default:
+            print "invalid option";
+            exit(1);
+            break;
+      }
+   }
+}
+
 $all = $fspot->getPhotoSelection();
 
 foreach($all as $photo) {
-   $fspot->gen_thumb($photo);
+   $fspot->gen_thumb($photo, $overwrite);
 }
 
 ?>
index 63a913937d8ac5eac60352bd724805e5e924de8b..9e78d1dcfe7ba06000fa5a7a19f1215cf3ac1eb0 100644 (file)
@@ -1306,7 +1306,7 @@ class PHPFSPOT {
     * 2. Check if the md5sum of the original file has changed
     * 3. Generate the thumbnails if needed
     */
-   public function gen_thumb($idx = 0, $force = 0)
+   public function gen_thumb($idx = 0, $force = 0, $overwrite = false)
    {
       $error = 0;
 
@@ -1339,6 +1339,8 @@ class PHPFSPOT {
       $changes = false;
 
       foreach($resolutions as $resolution) {
+   
+         $generate_it = false;
 
          $thumb_sub_path = substr($file_md5, 0, 2);
          $thumb_path = $this->cfg->thumb_path ."/". $thumb_sub_path ."/". $resolution ."_". $file_md5;
@@ -1349,15 +1351,14 @@ class PHPFSPOT {
 
          /* if the thumbnail file doesn't exist, create it */
          if(!file_exists($thumb_path)) {
-
-            $this->_debug(" ". $resolution ."px");
-            if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
-               $error = 1;
-
-            $changes = true;
+            $generate_it = true;
          }
          /* if the file hasn't changed there is no need to regen the thumb */
          elseif($file_md5 != $this->getMD5($idx) || $force) {
+            $generate_it = true;
+         }
+
+         if($generate_it || $overwrite) {
 
             $this->_debug(" ". $resolution ."px");
             if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
@@ -1632,6 +1633,11 @@ class PHPFSPOT {
          print "PEAR Calendar package is missing<br />\n";
          $missing = true;
       }
+      @include_once 'Console/Getopt.php';
+      if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) {
+         print "PEAR Console_Getopt package is missing<br />\n";
+         $missing = true;
+      }
       ini_restore('track_errors');
 
       if(isset($missing))