2018-11-06 14:43:53 +00:00
< ? php
/**
2024-05-23 07:26:56 +00:00
* SPDX - FileCopyrightText : 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX - License - Identifier : AGPL - 3.0 - or - later
2018-11-06 14:43:53 +00:00
*/
namespace OC\Repair ;
2019-01-20 10:13:41 +00:00
use OC\Avatar\AvatarManager ;
2022-09-19 17:03:27 +00:00
use OCP\BackgroundJob\IJobList ;
2018-11-06 14:43:53 +00:00
use OCP\IConfig ;
use OCP\Migration\IOutput ;
use OCP\Migration\IRepairStep ;
class ClearGeneratedAvatarCache implements IRepairStep {
2022-08-31 12:24:25 +00:00
protected AvatarManager $avatarManager ;
private IConfig $config ;
2022-09-19 17:03:27 +00:00
private IJobList $jobList ;
2018-11-06 14:43:53 +00:00
2022-09-19 17:03:27 +00:00
public function __construct ( IConfig $config , AvatarManager $avatarManager , IJobList $jobList ) {
2020-10-05 13:12:57 +00:00
$this -> config = $config ;
2018-11-06 14:43:53 +00:00
$this -> avatarManager = $avatarManager ;
2022-09-19 17:03:27 +00:00
$this -> jobList = $jobList ;
2018-11-06 14:43:53 +00:00
}
2022-08-31 12:24:25 +00:00
public function getName () : string {
2023-05-09 10:27:46 +00:00
return 'Clear every generated avatar' ;
2018-11-06 14:43:53 +00:00
}
/**
* Check if this repair step should run
*/
2022-08-31 12:24:25 +00:00
private function shouldRun () : bool {
2023-04-05 10:50:08 +00:00
$versionFromBeforeUpdate = $this -> config -> getSystemValueString ( 'version' , '0.0.0.0' );
2018-11-06 14:43:53 +00:00
2023-05-09 10:27:46 +00: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 14:43:53 +00:00
}
2022-08-31 12:24:25 +00:00
public function run ( IOutput $output ) : void {
2018-11-06 14:43:53 +00:00
if ( $this -> shouldRun ()) {
try {
2022-09-19 17:03:27 +00:00
$this -> jobList -> add ( ClearGeneratedAvatarCacheJob :: class , []);
$output -> info ( 'Avatar cache clearing job added' );
2018-11-06 14:43:53 +00:00
} catch ( \Exception $e ) {
$output -> warning ( 'Unable to clear the avatar cache' );
}
}
}
}