ClearGeneratedAvatarCache.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 on major updates';
  42. }
  43. /**
  44. * Check if this repair step should run
  45. */
  46. private function shouldRun(): bool {
  47. $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0');
  48. // was added to 25.0.0.10
  49. return version_compare($versionFromBeforeUpdate, '25.0.0.10', '<=');
  50. }
  51. public function run(IOutput $output): void {
  52. if ($this->shouldRun()) {
  53. try {
  54. $this->jobList->add(ClearGeneratedAvatarCacheJob::class, []);
  55. $output->info('Avatar cache clearing job added');
  56. } catch (\Exception $e) {
  57. $output->warning('Unable to clear the avatar cache');
  58. }
  59. }
  60. }
  61. }