2018-11-06 09:43:53 -05:00
< ? php
/**
* @ copyright Copyright ( c ) 2018 John Molakvoæ < skjnldsv @ protonmail . com >
*
2020-12-16 08:54:15 -05:00
* @ author Christoph Wurst < christoph @ winzerhof - wurst . at >
2021-06-04 15:52:51 -04:00
* @ author John Molakvoæ < skjnldsv @ protonmail . com >
2019-12-03 13:57:53 -05:00
* @ author Michael Weimann < mail @ michael - weimann . eu >
2018-11-06 09:43:53 -05:00
*
* @ license GNU AGPL version 3 or any later version
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
2021-06-04 15:52:51 -04:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
2018-11-06 09:43:53 -05:00
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*
*/
namespace OC\Repair ;
2019-01-20 05:13:41 -05:00
use OC\Avatar\AvatarManager ;
2018-11-06 09:43:53 -05:00
use OCP\IConfig ;
2022-09-19 13:03:27 -04:00
use OCP\BackgroundJob\IJobList ;
2018-11-06 09:43:53 -05:00
use OCP\Migration\IOutput ;
use OCP\Migration\IRepairStep ;
class ClearGeneratedAvatarCache implements IRepairStep {
2022-08-31 08:24:25 -04:00
protected AvatarManager $avatarManager ;
private IConfig $config ;
2022-09-19 13:03:27 -04:00
private IJobList $jobList ;
2018-11-06 09:43:53 -05:00
2022-09-19 13:03:27 -04:00
public function __construct ( IConfig $config , AvatarManager $avatarManager , IJobList $jobList ) {
2020-10-05 09:12:57 -04:00
$this -> config = $config ;
2018-11-06 09:43:53 -05:00
$this -> avatarManager = $avatarManager ;
2022-09-19 13:03:27 -04:00
$this -> jobList = $jobList ;
2018-11-06 09:43:53 -05:00
}
2022-08-31 08:24:25 -04:00
public function getName () : string {
2023-05-09 06:27:46 -04:00
return 'Clear every generated avatar' ;
2018-11-06 09:43:53 -05:00
}
/**
* Check if this repair step should run
*/
2022-08-31 08:24:25 -04:00
private function shouldRun () : bool {
2023-04-05 06:50:08 -04:00
$versionFromBeforeUpdate = $this -> config -> getSystemValueString ( 'version' , '0.0.0.0' );
2018-11-06 09:43:53 -05:00
2023-05-09 06:27:46 -04:00
// This job only runs if the server was on a version lower than or equal to 27.0.0 before the upgrade.
// To clear the avatar cache again, bump the version to the currently released version (and change the operator to <= if it's not the master branch) and wait for the next release.
return version_compare ( $versionFromBeforeUpdate , '27.0.0' , '<' );
2018-11-06 09:43:53 -05:00
}
2022-08-31 08:24:25 -04:00
public function run ( IOutput $output ) : void {
2018-11-06 09:43:53 -05:00
if ( $this -> shouldRun ()) {
try {
2022-09-19 13:03:27 -04:00
$this -> jobList -> add ( ClearGeneratedAvatarCacheJob :: class , []);
$output -> info ( 'Avatar cache clearing job added' );
2018-11-06 09:43:53 -05:00
} catch ( \Exception $e ) {
$output -> warning ( 'Unable to clear the avatar cache' );
}
}
}
}