[MEDIA][SCRIPTS] clean_thumbnails Allow to delete remote thumbs as well
If the sysadmin decides that StoreRemoteMedia plugin should store original, then its thumbs will be regenerated as well, making it safe to delete them if needed. Beware that Embed plugin never stores the original tho.
This commit is contained in:
parent
ee872b5e44
commit
f8e6ad416b
|
@ -21,8 +21,8 @@
|
||||||
define('INSTALLDIR', dirname(__DIR__));
|
define('INSTALLDIR', dirname(__DIR__));
|
||||||
define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
|
define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
|
||||||
|
|
||||||
$shortoptions = 'y';
|
$shortoptions = 'y::a::f';
|
||||||
$longoptions = array('yes');
|
$longoptions = ['yes', 'all', 'force'];
|
||||||
|
|
||||||
$helptext = <<<END_OF_HELP
|
$helptext = <<<END_OF_HELP
|
||||||
clean_thumbnails.php [options]
|
clean_thumbnails.php [options]
|
||||||
|
@ -30,6 +30,8 @@ Deletes all local thumbnails so they can be regenerated. Also deletes
|
||||||
if the original File object does not exist, even for remote entries.
|
if the original File object does not exist, even for remote entries.
|
||||||
|
|
||||||
-y --yes do not wait for confirmation
|
-y --yes do not wait for confirmation
|
||||||
|
-a --all delete remote thumbnails
|
||||||
|
-f --force delete even if we can't regenerate later
|
||||||
|
|
||||||
Will print '.' for deleted local files and 'x' where File entry was missing.
|
Will print '.' for deleted local files and 'x' where File entry was missing.
|
||||||
If the script seems to stop, it is processing correct File_thumbnail entries.
|
If the script seems to stop, it is processing correct File_thumbnail entries.
|
||||||
|
@ -38,6 +40,8 @@ END_OF_HELP;
|
||||||
|
|
||||||
require_once INSTALLDIR.'/scripts/commandline.inc';
|
require_once INSTALLDIR.'/scripts/commandline.inc';
|
||||||
|
|
||||||
|
$only_local = !have_option('a', 'all');
|
||||||
|
|
||||||
if (!have_option('y', 'yes')) {
|
if (!have_option('y', 'yes')) {
|
||||||
print "About to delete locally generated thumbnails to allow regeneration. Are you sure? [y/N] ";
|
print "About to delete locally generated thumbnails to allow regeneration. Are you sure? [y/N] ";
|
||||||
$response = fgets(STDIN);
|
$response = fgets(STDIN);
|
||||||
|
@ -53,8 +57,17 @@ $thumbs->find();
|
||||||
while ($thumbs->fetch()) {
|
while ($thumbs->fetch()) {
|
||||||
try {
|
try {
|
||||||
$file = $thumbs->getFile();
|
$file = $thumbs->getFile();
|
||||||
if ($file->isLocal()) {
|
$is_local = $file->isLocal();
|
||||||
// only delete properly linked thumbnails if they're local
|
if ($is_local || !$only_local) {
|
||||||
|
// only delete if we can regenerate it
|
||||||
|
if (!$is_local && !have_option('f', 'force')) {
|
||||||
|
try {
|
||||||
|
$file->getPath();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// We can't regenerate later if we don't have the original.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
$thumbs->delete();
|
$thumbs->delete();
|
||||||
print '.';
|
print '.';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user