merged master
[lhc/web/wiklou.git] / maintenance / cleanupUploadStash.php
index 10fb437..cc32946 100644 (file)
  * @ingroup Maintenance
  */
 
-require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+require_once( __DIR__ . '/Maintenance.php' );
 
+/**
+ * Maintenance script to remove old or broken uploads from temporary uploaded
+ * file storage and clean up associated database records.
+ *
+ * @ingroup Maintenance
+ */
 class UploadStashCleanup extends Maintenance {
 
        public function __construct() {
                parent::__construct();
                $this->mDescription = "Clean up abandoned files in temporary uploaded file stash";
-       }
+       }
 
-       public function execute() {
+       public function execute() {
                $repo = RepoGroup::singleton()->getLocalRepo();
 
                $dbr = $repo->getSlaveDb();
@@ -51,14 +57,14 @@ class UploadStashCleanup extends Maintenance {
                );
 
                if( !is_object( $res ) || $res->numRows() == 0 ) {
-                       $this->output( 'No files to cleanup!' );
+                       $this->output( "No files to cleanup!\n" );
                        // nothing to do.
                        return;
                }
 
                // finish the read before starting writes.
                $keys = array();
-               foreach($res as $row) {
+               foreach( $res as $row ) {
                        array_push( $keys, $row->us_key );
                }
 
@@ -68,15 +74,21 @@ class UploadStashCleanup extends Maintenance {
                // out-of-date someday
                $stash = new UploadStash( $repo );
 
+               $i = 0;
                foreach( $keys as $key ) {
+                       $i++;
                        try {
                                $stash->getFile( $key, true );
                                $stash->removeFileNoAuth( $key );
                        } catch ( UploadStashBadPathException $ex ) {
                                $this->output( "Failed removing stashed upload with key: $key\n"  );
                        }
+                       if ( $i % 100 == 0 ) {
+                               $this->output( "$i\n" );
+                       }
                }
-       }
+               $this->output( "$i done\n" );
+       }
 }
 
 $maintClass = "UploadStashCleanup";