51 $tempRepo = $repo->getTempRepo();
53 $dbr = $repo->getReplicaDB();
56 $cutoff = time() - (int)$this->
getConfig()->get( MainConfigNames::UploadStashMaxAge );
58 $this->
output(
"Getting list of files to clean up...\n" );
59 $res = $dbr->newSelectQueryBuilder()
61 ->from(
'uploadstash' )
62 ->where( $dbr->expr(
'us_timestamp',
'<', $dbr->timestamp( $cutoff ) ) )
63 ->caller( __METHOD__ )
67 if ( $res->numRows() == 0 ) {
68 $this->
output(
"No stashed files to cleanup according to the DB.\n" );
72 foreach ( $res as $row ) {
73 $keys[] = $row->us_key;
76 $this->
output(
'Removing ' . count( $keys ) .
" file(s)...\n" );
83 foreach ( $keys as $key ) {
86 $stash->getFile( $key,
true );
87 $stash->removeFileNoAuth( $key );
89 $type = get_class( $ex );
90 $this->
output(
"Failed removing stashed upload with key: $key ($type)\n" );
92 if ( $i % 100 == 0 ) {
97 $this->
output(
"$i done\n" );
101 $dir = $tempRepo->getZonePath(
'thumb' );
102 $iterator = $tempRepo->getBackend()->getFileList( [
'dir' => $dir,
'adviseStat' => 1 ] );
103 if ( $iterator ===
null ) {
104 $this->
fatalError(
"Could not get file listing." );
106 $this->
output(
"Deleting old thumbnails...\n" );
109 foreach ( $iterator as $file ) {
110 if (
wfTimestamp( TS_UNIX, $tempRepo->getFileTimestamp(
"$dir/$file" ) ) < $cutoff ) {
111 $batch[] = [
'op' =>
'delete',
'src' =>
"$dir/$file" ];
114 $i += count( $batch );
120 if ( count( $batch ) ) {
122 $i += count( $batch );
124 $this->
output(
"$i done\n" );
127 $dir = $tempRepo->getZonePath(
'public' );
128 $iterator = $tempRepo->getBackend()->getFileList( [
'dir' => $dir,
'adviseStat' => 1 ] );
129 if ( $iterator ===
null ) {
130 $this->
fatalError(
"Could not get file listing." );
132 $this->
output(
"Deleting orphaned temp files...\n" );
133 if ( strpos( $dir,
'/local-temp' ) ===
false ) {
134 $this->
output(
"Temp repo might be misconfigured. It points to directory: '$dir' \n" );
139 foreach ( $iterator as $file ) {
140 if (
wfTimestamp( TS_UNIX, $tempRepo->getFileTimestamp(
"$dir/$file" ) ) < $cutoff ) {
141 $batch[] = [
'op' =>
'delete',
'src' =>
"$dir/$file" ];
144 $i += count( $batch );
150 if ( count( $batch ) ) {
152 $i += count( $batch );
154 $this->
output(
"$i done\n" );