763f556a064740fe1785c711873032cc2af4123c
3 * Remove old or broken uploads from temporary uploaded file storage,
4 * clean up associated database records
6 * Copyright © 2011, Wikimedia Foundation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
24 * @author Ian Baker <ibaker@wikimedia.org>
25 * @ingroup Maintenance
28 require_once( dirname( __FILE__
) . '/Maintenance.php' );
30 class UploadStashCleanup
extends Maintenance
{
32 public function __construct() {
33 parent
::__construct();
34 $this->mDescription
= "Clean up abandoned files in temporary uploaded file stash";
37 public function execute() {
38 $dbr = wfGetDB( DB_SLAVE
);
40 $this->output( "Getting list of files to clean up...\n" );
44 'us_timestamp < ' . wfTimestamp( TS_MW
, time() - UploadStash
::REPO_AGE
* 3600 ),
48 if( !is_object( $res ) ) {
53 // finish the read before starting writes.
55 while( $row = $dbr->fetchRow( $res ) ) {
56 array_push( $keys, $row['us_key'] );
59 $this->output( 'Removing ' . count($keys) . " file(s)...\n" );
60 // this could be done some other, more direct/efficient way, but using
61 // UploadStash's own methods means it's less likely to fall accidentally
62 // out-of-date someday
63 $repo = RepoGroup
::singleton()->getLocalRepo();
64 $stash = new UploadStash( $repo );
66 foreach( $keys as $key ) {
67 $stash->getFile( $key, true );
68 $stash->removeFileNoAuth( $key );
73 $maintClass = "UploadStashCleanup";
74 require_once( RUN_MAINTENANCE_IF_MAIN
);