41 $tempRepo = $repo->getTempRepo();
43 $dbr = $repo->getReplicaDB();
46 $cutoff = time() - (int)$this->
getConfig()->get( MainConfigNames::UploadStashMaxAge );
48 $this->
output(
"Getting list of files to clean up...\n" );
49 $keys = $dbr->newSelectQueryBuilder()
51 ->from(
'uploadstash' )
52 ->where( $dbr->expr(
'us_timestamp',
'<', $dbr->timestamp( $cutoff ) ) )
53 ->caller( __METHOD__ )
58 $this->
output(
"No stashed files to cleanup according to the DB.\n" );
60 $this->
output(
'Removing ' . count( $keys ) .
" file(s)...\n" );
67 foreach ( $keys as $key ) {
70 $stash->getFile( $key,
true );
71 $stash->removeFileNoAuth( $key );
73 $type = get_class( $ex );
74 $this->
output(
"Failed removing stashed upload with key: $key ($type)\n" );
76 if ( $i % 100 == 0 ) {
81 $this->
output(
"$i done\n" );
85 $dir = $tempRepo->getZonePath(
'thumb' );
86 $iterator = $tempRepo->getBackend()->getFileList( [
'dir' => $dir,
'adviseStat' => 1 ] );
87 if ( $iterator ===
null ) {
88 $this->
fatalError(
"Could not get file listing." );
90 $this->
output(
"Deleting old thumbnails...\n" );
93 foreach ( $iterator as $file ) {
94 if (
wfTimestamp( TS::UNIX, $tempRepo->getFileTimestamp(
"$dir/$file" ) ) < $cutoff ) {
95 $batch[] = [
'op' =>
'delete',
'src' =>
"$dir/$file" ];
98 $i += count( $batch );
104 if ( count( $batch ) ) {
106 $i += count( $batch );
108 $this->
output(
"$i done\n" );
111 $dir = $tempRepo->getZonePath(
'public' );
112 $iterator = $tempRepo->getBackend()->getFileList( [
'dir' => $dir,
'adviseStat' => 1 ] );
113 if ( $iterator ===
null ) {
114 $this->
fatalError(
"Could not get file listing." );
116 $this->
output(
"Deleting orphaned temp files...\n" );
117 if ( !str_contains( $dir,
'/local-temp' ) ) {
118 $this->
output(
"Temp repo might be misconfigured. It points to directory: '$dir' \n" );
123 foreach ( $iterator as $file ) {
124 if (
wfTimestamp( TS::UNIX, $tempRepo->getFileTimestamp(
"$dir/$file" ) ) < $cutoff ) {
125 $batch[] = [
'op' =>
'delete',
'src' =>
"$dir/$file" ];
128 $i += count( $batch );
134 if ( count( $batch ) ) {
136 $i += count( $batch );
138 $this->
output(
"$i done\n" );