You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.0 KiB

3 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
  4. *
  5. * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  6. * @author Julius Härtl <jus@bitgrid.net>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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\Template\JSCombiner;
  27. use OC\Template\SCSSCacher;
  28. use OCP\ICacheFactory;
  29. use OCP\Migration\IOutput;
  30. use OCP\Migration\IRepairStep;
  31. class ClearFrontendCaches implements IRepairStep {
  32. /** @var ICacheFactory */
  33. protected $cacheFactory;
  34. /** @var SCSSCacher */
  35. protected $scssCacher;
  36. /** @var JSCombiner */
  37. protected $jsCombiner;
  38. public function __construct(ICacheFactory $cacheFactory,
  39. SCSSCacher $SCSSCacher,
  40. JSCombiner $JSCombiner) {
  41. $this->cacheFactory = $cacheFactory;
  42. $this->scssCacher = $SCSSCacher;
  43. $this->jsCombiner = $JSCombiner;
  44. }
  45. public function getName() {
  46. return 'Clear frontend caches';
  47. }
  48. public function run(IOutput $output) {
  49. try {
  50. $c = $this->cacheFactory->createDistributed('imagePath');
  51. $c->clear();
  52. $output->info('Image cache cleared');
  53. $this->scssCacher->resetCache();
  54. $output->info('SCSS cache cleared');
  55. $this->jsCombiner->resetCache();
  56. $output->info('JS cache cleared');
  57. } catch (\Exception $e) {
  58. $output->warning('Unable to clear the frontend cache');
  59. }
  60. }
  61. }