52 $tempRepo = $repo->getTempRepo();
54 $dbr = $repo->getReplicaDB();
57 $cutoff = time() - (int)$this->
getConfig()->get( MainConfigNames::UploadStashMaxAge );
59 $this->
output(
"Getting list of files to clean up...\n" );
60 $res = $dbr->newSelectQueryBuilder()
62 ->from(
'uploadstash' )
63 ->where( $dbr->expr(
'us_timestamp',
'<', $dbr->timestamp( $cutoff ) ) )
64 ->caller( __METHOD__ )
68 if ( $res->numRows() == 0 ) {
69 $this->
output(
"No stashed files to cleanup according to the DB.\n" );
73 foreach ( $res as $row ) {
74 $keys[] = $row->us_key;
77 $this->
output(
'Removing ' . count( $keys ) .
" file(s)...\n" );
84 foreach ( $keys as $key ) {
87 $stash->getFile( $key,
true );
88 $stash->removeFileNoAuth( $key );
90 $type = get_class( $ex );
91 $this->
output(
"Failed removing stashed upload with key: $key ($type)\n" );
93 if ( $i % 100 == 0 ) {
98 $this->
output(
"$i done\n" );
102 $dir = $tempRepo->getZonePath(
'thumb' );
103 $iterator = $tempRepo->getBackend()->getFileList( [
'dir' => $dir,
'adviseStat' => 1 ] );
104 if ( $iterator ===
null ) {
105 $this->
fatalError(
"Could not get file listing." );
107 $this->
output(
"Deleting old thumbnails...\n" );
110 foreach ( $iterator as $file ) {
111 if (
wfTimestamp( TS_UNIX, $tempRepo->getFileTimestamp(
"$dir/$file" ) ) < $cutoff ) {
112 $batch[] = [
'op' =>
'delete',
'src' =>
"$dir/$file" ];
115 $i += count( $batch );
121 if ( count( $batch ) ) {
123 $i += count( $batch );
125 $this->
output(
"$i done\n" );
128 $dir = $tempRepo->getZonePath(
'public' );
129 $iterator = $tempRepo->getBackend()->getFileList( [
'dir' => $dir,
'adviseStat' => 1 ] );
130 if ( $iterator ===
null ) {
131 $this->
fatalError(
"Could not get file listing." );
133 $this->
output(
"Deleting orphaned temp files...\n" );
134 if ( strpos( $dir,
'/local-temp' ) ===
false ) {
135 $this->
output(
"Temp repo might be misconfigured. It points to directory: '$dir' \n" );
140 foreach ( $iterator as $file ) {
141 if (
wfTimestamp( TS_UNIX, $tempRepo->getFileTimestamp(
"$dir/$file" ) ) < $cutoff ) {
142 $batch[] = [
'op' =>
'delete',
'src' =>
"$dir/$file" ];
145 $i += count( $batch );
151 if ( count( $batch ) ) {
153 $i += count( $batch );
155 $this->
output(
"$i done\n" );