Mercurial > hg > mgallery
comparison mgtool.php @ 255:d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 12 Dec 2018 14:52:00 +0200 |
parents | 5b41efcec87d |
children | 6ad17bc3d1a6 |
comparison
equal
deleted
inserted
replaced
254:d536c57fa952 | 255:d0bcc6c7fc66 |
---|---|
362 unlink($path); | 362 unlink($path); |
363 } | 363 } |
364 } | 364 } |
365 | 365 |
366 | 366 |
367 function mgDeleteQuiet($path, &$noDelete) | |
368 { | |
369 if (is_dir($path)) | |
370 { | |
371 if (($dirHandle = @opendir($path)) === FALSE) | |
372 return mgError("Could not read directory '".$path."'.\n"); | |
373 | |
374 while (($dirFile = @readdir($dirHandle)) !== FALSE) | |
375 { | |
376 if ($dirFile != "." && $dirFile != "..") | |
377 mgDeleteQuiet($path."/".$dirFile, $noDelete); | |
378 } | |
379 | |
380 closedir($dirHandle); | |
381 | |
382 if (!array_key_exists($path, $noDelete)) | |
383 { | |
384 //echo "DEL DIR '".$path."'\n"; | |
385 rmdir($path); | |
386 } | |
387 } | |
388 else | |
389 if (file_exists($path) && !array_key_exists($path, $noDelete)) | |
390 { | |
391 //echo "DEL FILE '".$path."'\n"; | |
392 unlink($path); | |
393 } | |
394 } | |
395 | |
396 | |
367 // | 397 // |
368 // Check if we have received the quit signal | 398 // Check if we have received the quit signal |
369 // and if yes, quit cleanly now. | 399 // and if yes, quit cleanly now. |
370 // | 400 // |
371 function mgCheckQuit($now = FALSE) | 401 function mgCheckQuit($now = FALSE) |
540 $gallery["parent"] = &$parentData; | 570 $gallery["parent"] = &$parentData; |
541 mgCopyEntryData($gallery, $parentEntry, MG_STR, "caption", "caption"); | 571 mgCopyEntryData($gallery, $parentEntry, MG_STR, "caption", "caption"); |
542 } | 572 } |
543 | 573 |
544 // Start actual processing | 574 // Start actual processing |
575 $tnPath = $path."/".$galTNPath; | |
576 $medPath = $path."/".$galMedPath; | |
577 $generatedFiles = []; | |
578 $generatedFiles[$tnPath] = 1; | |
579 $generatedFiles[$medPath] = 1; | |
580 | |
545 $nentries = count($entries); | 581 $nentries = count($entries); |
546 $nentry = 0; | 582 $nentry = 0; |
547 echo $path." .. "; | 583 echo $path." .. "; |
548 foreach ($entries as $ename => &$edata) | 584 foreach ($entries as $ename => &$edata) |
549 { | 585 { |
564 { | 600 { |
565 foreach ($captions[$ename] as $ckey => $cval) | 601 foreach ($captions[$ename] as $ckey => $cval) |
566 $edata[$ckey] = $cval; | 602 $edata[$ckey] = $cval; |
567 } | 603 } |
568 | 604 |
569 $tnPath = $path."/".$galTNPath; | |
570 $medPath = $path."/".$galMedPath; | |
571 | 605 |
572 // Handle entry based on type | 606 // Handle entry based on type |
573 if ($edata["type"] == 0) | 607 if ($edata["type"] == 0) |
574 { | 608 { |
575 $updFlags = 0; | 609 $updFlags = 0; |
576 $medFilename = $medPath."/".$ename.".".mgGetSetting("med_format"); | 610 $medFilename = $medPath."/".$ename.".".mgGetSetting("med_format"); |
577 $tnFilename = $tnPath."/".$ename.".".mgGetSetting("tn_format"); | 611 $tnFilename = $tnPath."/".$ename.".".mgGetSetting("tn_format"); |
578 $capFilename = $path."/".$edata["base"].".txt"; | 612 $capFilename = $path."/".$edata["base"].".txt"; |
613 | |
614 $generatedFiles[$medFilename] = 1; | |
615 $generatedFiles[$tnFilename] = 1; | |
579 | 616 |
580 // Check what we need to update .. | 617 // Check what we need to update .. |
581 if (!file_exists($medFilename) || filemtime($medFilename) < $edata["mtime"]) | 618 if (!file_exists($medFilename) || filemtime($medFilename) < $edata["mtime"]) |
582 $updFlags |= GUPD_MED_IMAGE; | 619 $updFlags |= GUPD_MED_IMAGE; |
583 | 620 |
651 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "title"); | 688 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "title"); |
652 mgCopyEntryData($edata, $tmp, MG_BOOL, "hide", "hide", FALSE); | 689 mgCopyEntryData($edata, $tmp, MG_BOOL, "hide", "hide", FALSE); |
653 mgCopyEntryData($edata, $tmp, MG_BOOL, "hide_contents", "hide_contents", FALSE); | 690 mgCopyEntryData($edata, $tmp, MG_BOOL, "hide_contents", "hide_contents", FALSE); |
654 } | 691 } |
655 } | 692 } |
693 | |
694 // Delete any "trash" files from medium/thumbnail dirs | |
695 mgDeleteQuiet($tnPath, $generatedFiles); | |
696 mgDeleteQuiet($medPath, $generatedFiles); | |
656 | 697 |
657 echo "\r".$path." ..... DONE\n"; | 698 echo "\r".$path." ..... DONE\n"; |
658 | 699 |
659 mgCheckQuit(TRUE); | 700 mgCheckQuit(TRUE); |
660 } | 701 } |