1
0

ClearGeneratedAvatarCache.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author John Molakvoæ <skjnldsv@protonmail.com>
  7. * @author Michael Weimann <mail@michael-weimann.eu>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OC\Repair;
  26. use OC\Avatar\AvatarManager;
  27. use OCP\IConfig;
  28. use OCP\BackgroundJob\IJobList;
  29. use OCP\Migration\IOutput;
  30. use OCP\Migration\IRepairStep;
  31. class ClearGeneratedAvatarCache implements IRepairStep {
  32. protected AvatarManager $avatarManager;
  33. private IConfig $config;
  34. private IJobList $jobList;
  35. public function __construct(IConfig $config, AvatarManager $avatarManager, IJobList $jobList) {
  36. $this->config = $config;
  37. $this->avatarManager = $avatarManager;
  38. $this->jobList = $jobList;
  39. }
  40. public function getName(): string {
  41. return 'Clear every generated avatar';
  42. }
  43. /**
  44. * Check if this repair step should run
  45. */
  46. private function shouldRun(): bool {
  47. $versionFromBeforeUpdate = $this->config->getSystemValueString('version', '0.0.0.0');
  48. // This job only runs if the server was on a version lower than or equal to 27.0.0 before the upgrade.
  49. // 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.
  50. return version_compare($versionFromBeforeUpdate, '27.0.0', '<');
  51. }
  52. public function run(IOutput $output): void {
  53. if ($this->shouldRun()) {
  54. try {
  55. $this->jobList->add(ClearGeneratedAvatarCacheJob::class, []);
  56. $output->info('Avatar cache clearing job added');
  57. } catch (\Exception $e) {
  58. $output->warning('Unable to clear the avatar cache');
  59. }
  60. }
  61. }
  62. }