3 * Scan the deletion log and purges affected files within a timeframe.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup Maintenance
24 require_once __DIR__
. '/Maintenance.php';
27 * Maintenance script that scans the deletion log and purges affected files
30 * @ingroup Maintenance
32 class PurgeDeletedFiles
extends Maintenance
{
33 public function __construct() {
34 parent
::__construct();
35 $this->mDescription
= "Scan the logging table and purge files that where deleted.";
36 $this->addOption( 'starttime', 'Starting timestamp', false, true );
37 $this->addOption( 'endtime', 'Ending timestamp', false, true );
40 public function execute() {
41 $this->output( "Purging cache and thumbnails for deleted files...\n" );
42 $this->purgeFromLogType( 'delete' );
43 $this->output( "...deleted files purged.\n\n" );
45 $this->output( "Purging cache and thumbnails for suppressed files...\n" );
46 $this->purgeFromLogType( 'suppress' );
47 $this->output( "...suppressed files purged.\n" );
50 protected function purgeFromLogType( $logType ) {
51 $repo = RepoGroup
::singleton()->getLocalRepo();
52 $db = $repo->getSlaveDB();
55 'log_namespace' => NS_FILE
,
56 'log_type' => $logType,
57 'log_action' => array( 'delete', 'revision' )
59 $start = $this->getOption( 'starttime' );
61 $conds[] = 'log_timestamp >= ' . $db->addQuotes( $db->timestamp( $start ) );
63 $end = $this->getOption( 'endtime' );
65 $conds[] = 'log_timestamp <= ' . $db->addQuotes( $db->timestamp( $end ) );
68 $res = $db->select( 'logging', array( 'log_title', 'log_timestamp' ), $conds, __METHOD__
);
69 foreach ( $res as $row ) {
70 $file = $repo->newFile( Title
::makeTitle( NS_FILE
, $row->log_title
) );
72 // Purge current version and any versions in oldimage table
74 $file->purgeHistory();
75 // Purge items from fileachive table (rows are likely here)
76 $this->purgeFromArchiveTable( $file );
78 $this->output( "Purged file {$row->log_title}; deleted on {$row->log_timestamp}.\n" );
82 protected function purgeFromArchiveTable( LocalFile
$file ) {
83 $db = $file->getRepo()->getSlaveDB();
84 $res = $db->select( 'filearchive',
85 array( 'fa_archive_name' ),
86 array( 'fa_name' => $file->getName() ),
89 foreach ( $res as $row ) {
90 $file->purgeOldThumbnails( $row->fa_archive_name
);
95 $maintClass = "PurgeDeletedFiles";
96 require_once RUN_MAINTENANCE_IF_MAIN
;