2014-05-12 21:41:12 +09:00
|
|
|
#!/usr/bin/env php
|
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* StatusNet - a distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2008, 2009, StatusNet, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
\define('INSTALLDIR', \dirname(__DIR__));
|
|
|
|
\define('PUBLICDIR', INSTALLDIR . \DIRECTORY_SEPARATOR . 'public');
|
2014-05-12 21:41:12 +09:00
|
|
|
|
2021-02-21 18:03:12 +09:00
|
|
|
$shortoptions = 'y::a::f';
|
2021-10-10 17:26:18 +09:00
|
|
|
$longoptions = ['yes', 'all', 'force'];
|
2014-05-12 21:41:12 +09:00
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
$helptext = <<<'END_OF_HELP'
|
|
|
|
clean_thumbnails.php [options]
|
|
|
|
Deletes all local thumbnails so they can be regenerated. Also deletes
|
|
|
|
if the original File object does not exist, even for remote entries.
|
2014-05-12 21:41:12 +09:00
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
-y --yes do not wait for confirmation
|
|
|
|
-a --all delete remote thumbnails
|
|
|
|
-f --force delete even if we can't regenerate later
|
2014-05-12 21:41:12 +09:00
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
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.
|
2014-05-12 21:41:12 +09:00
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
END_OF_HELP;
|
2014-05-12 21:41:12 +09:00
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
require_once INSTALLDIR . '/scripts/commandline.inc';
|
2014-05-12 21:41:12 +09:00
|
|
|
|
2021-02-21 18:03:12 +09:00
|
|
|
$only_local = !have_option('a', 'all');
|
|
|
|
|
2014-05-12 21:41:12 +09:00
|
|
|
if (!have_option('y', 'yes')) {
|
2021-10-10 17:26:18 +09:00
|
|
|
echo 'About to delete locally generated thumbnails to allow regeneration. Are you sure? [y/N] ';
|
|
|
|
$response = fgets(\STDIN);
|
|
|
|
if (mb_strtolower(trim($response)) != 'y') {
|
|
|
|
echo "Aborting.\n";
|
2014-05-12 21:41:12 +09:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
echo 'Deleting';
|
2014-05-12 21:41:12 +09:00
|
|
|
$thumbs = new File_thumbnail();
|
|
|
|
$thumbs->find();
|
|
|
|
while ($thumbs->fetch()) {
|
|
|
|
try {
|
2021-10-10 17:26:18 +09:00
|
|
|
$file = $thumbs->getFile();
|
2021-02-21 18:03:12 +09:00
|
|
|
$is_local = $file->isLocal();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2014-05-12 21:41:12 +09:00
|
|
|
$thumbs->delete();
|
2021-10-10 17:26:18 +09:00
|
|
|
echo '.';
|
2014-05-12 21:41:12 +09:00
|
|
|
}
|
|
|
|
} catch (NoResultException $e) {
|
|
|
|
// No File object for thumbnail, let's delete the thumbnail entry
|
|
|
|
$thumbs->delete();
|
2021-10-10 17:26:18 +09:00
|
|
|
echo 'x';
|
2014-05-12 21:41:12 +09:00
|
|
|
}
|
|
|
|
}
|
2021-10-10 17:26:18 +09:00
|
|
|
echo "\nDONE.\n";
|