From 48e9cc684fd22512924e2f46c1e67179628e4a4d Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Sat, 1 Jan 2011 15:15:44 -0500 Subject: [PATCH] add option to the ansel.php cli script for reseting all stacks and/or views Use judiciously, this will cause all generated images to need to be recreated. --- ansel/scripts/ansel.php | 59 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/ansel/scripts/ansel.php b/ansel/scripts/ansel.php index 26a9201be..a6f4f2877 100755 --- a/ansel/scripts/ansel.php +++ b/ansel/scripts/ansel.php @@ -14,10 +14,10 @@ Horde_Registry::appInit('ansel', array('authentication' => 'none', 'cli' => true // We accept the user name on the command-line. $ret = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), - 'hu:p:lc:g:a:d:t:', + 'hu:p:lc:g:a:d:t:r', array('help', 'username=', 'password=', 'list', 'create=', 'gallery=', 'add=', 'dir=', - 'caption=')); + 'caption=', 'reset=')); if ($ret instanceof PEAR_Error) { $error = _("Couldn't read command-line options."); @@ -83,6 +83,20 @@ foreach ($opts as $opt) { case '--caption': $caption = $optValue; break; + case 'r': + case '--reset': + $resetting = true; + $resetType = $optValue; + if (!empty($resetType)) { + switch ($resetType) { + case 'stacks': + case 'thumbs': + break; + default: + Horde:fatal(_("Invalid image type. Must be \"stacks\" or \"thumbs\"")); + } + } + break; } } @@ -100,6 +114,28 @@ if (!empty($username) && !empty($password)) { } } +if (!empty($resetting)) { + if (!$registry->isAdmin()) { + Horde::fatal(_("Requires admin access.")); + } + $cli->message(_("Resetting thumbnails: "), 'cli.info'); + $galleries = $injector->getInstance('Ansel_Storage')->listGalleries(array('perm' => null)); + foreach ($galleries as $gallery) { + if (empty($resetType) || $resetType == 'stacks') { + $gallery->clearStacks(); + $cli->message(sprintf(_("Successfully reset stack cache for gallery: %d"), $gallery->getId()), 'cli.success'); + + } + if (empty($resetType) || $resetType == 'thumbs') { + $gallery->clearViews(); + $cli->message(sprintf(_("Successfully reset image cache for gallery: %d"), $gallery->getId()), 'cli.success'); + } + } + + $cli->message(_("Done."), 'cli.success'); + exit; +} + // Choose the gallery to add to (or use the created one). if (!empty($galleryId)) { if (!$GLOBALS['injector']->getInstance('Ansel_Storage')->galleryExists($galleryId)) { @@ -266,14 +302,15 @@ function showHelp() $cli->writeln(); $cli->writeln(_("Mandatory arguments to long options are mandatory for short options too.")); $cli->writeln(); - $cli->writeln(_("-h, --help Show this help")); - $cli->writeln(_("-l, --list List galleries or photos (if combined with -g)")); - $cli->writeln(_("-c, --create[=name/description/owner]\n Create gallery (and use it) Combined with -g to create a subgallery.")); - $cli->writeln(_("-g, --gallery[=shortname] Select gallery to use")); - $cli->writeln(_("-a, --add[=filename] Add local file to selected gallery")); - $cli->writeln(_("-d, --dir[=directory] Add all files from the directory to the selected\n gallery")); - $cli->writeln(_("-u, --username[=username] Horde login username")); - $cli->writeln(_("-p, --password[=password] Horde login password")); - $cli->writeln(_("-t, --caption[=caption] Caption for photo (if combined with -a)")); + $cli->writeln(_("-h, --help Show this help")); + $cli->writeln(_("-l, --list List galleries or photos (if combined with -g)")); + $cli->writeln(_("-c, --create[=name/description/owner]\n Create gallery (and use it) Combined with -g to create a subgallery.")); + $cli->writeln(_("-g, --gallery[=shortname] Select gallery to use")); + $cli->writeln(_("-a, --add[=filename] Add local file to selected gallery")); + $cli->writeln(_("-d, --dir[=directory] Add all files from the directory to the selected gallery")); + $cli->writeln(_("-u, --username[=username] Horde login username")); + $cli->writeln(_("-p, --password[=password] Horde login password")); + $cli->writeln(_("-t, --caption[=caption] Caption for photo (if combined with -a)")); + $cli->writeln(_("-r, --reset[=[thumbs|stacks]]\n Reset generated images, optionally only a certain type. Script must be run as root or another system user with enough permissions to the VFS to delete.")); $cli->writeln(); } -- 2.11.0