[StoreRemoteMedia][SCRIPTS] Update removeRemoteMedia

This commit is contained in:
Diogo Peralta Cordeiro 2021-02-21 09:26:35 +00:00
parent 890f3bd91e
commit 4deaaa8dbe

View File

@ -20,8 +20,9 @@
* *
* @category Plugin * @category Plugin
* @package GNUsocial * @package GNUsocial
* @author Diogo Cordeiro <diogo@fc.up.pt> * @author Diogo Peralta Cordeiro <mail+gnusocial@diogo.site>
* @copyright 2018 Free Software Foundation, Inc http://www.fsf.org * @author Alexei Sorokin
* @copyright 2018-2021 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/ */
@ -33,20 +34,15 @@ $longoptions = ['limit=', 'all', 'image'];
$helptext = <<<END_OF_HELP $helptext = <<<END_OF_HELP
remove_remote_media.php [options] remove_remote_media.php [options]
Removes remote media. In most cases, (if not all), an URL will be kept for the original attachment. Removes remote media. Thumbs will be removed as well.
In case the attachment is an image its thumbs will be removed as well.
-l --limit [date] This is a timestamp, format is: yyyy-mm-dd (optional time hh:mm:ss may be provided) -l --limit [date] This is a timestamp, format is: yyyy-mm-dd (optional time hh:mm:ss may be provided)
-a --all By default only remote attachments will be deleted, by using this flag you will remove oembed previews and alike
-i --image Remove image only attachments (will ignore oembed previews and alike)
END_OF_HELP; END_OF_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc'; require_once INSTALLDIR . '/scripts/commandline.inc';
$quiet = have_option('q', 'quiet'); $quiet = have_option('q', 'quiet');
$include_previews = have_option('a', 'all');
$image_only = have_option('i', 'image');
if (!have_option('l', 'limit')) { if (!have_option('l', 'limit')) {
echo "You must provide a limit!\n\n"; echo "You must provide a limit!\n\n";
@ -66,13 +62,10 @@ $fn->query(sprintf(
FROM file_to_post FROM file_to_post
INNER JOIN file ON file_to_post.file_id = file.id INNER JOIN file ON file_to_post.file_id = file.id
INNER JOIN notice ON file_to_post.post_id = notice.id INNER JOIN notice ON file_to_post.post_id = notice.id
WHERE notice.is_local = 0 WHERE notice.is_local = 0 AND notice.modified <= '%3$s'
%1$s%2$sAND notice.modified <= '%3$s'
GROUP BY file_to_post.file_id GROUP BY file_to_post.file_id
ORDER BY MAX(notice.modified) ORDER BY MAX(notice.modified)
END, END,
$image_only ? 'AND file.width IS NOT NULL AND file.height IS NOT NULL ' : '',
$include_previews ? '' : 'AND file.filehash IS NOT NULL ',
$fn->escape($max_date) $fn->escape($max_date)
)); ));