From 31313178a56d6c173a45e7e89546da1f5d43052a Mon Sep 17 00:00:00 2001 From: Julius Härtl Date: Fri, 26 Jan 2018 17:46:42 +0100 Subject: Add repair step to clear frontend related caches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/private/Repair/ClearFrontendCaches.php | 78 ++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 lib/private/Repair/ClearFrontendCaches.php (limited to 'lib/private/Repair') diff --git a/lib/private/Repair/ClearFrontendCaches.php b/lib/private/Repair/ClearFrontendCaches.php new file mode 100644 index 00000000000..8d109462f6a --- /dev/null +++ b/lib/private/Repair/ClearFrontendCaches.php @@ -0,0 +1,78 @@ + + * + * @author Julius Härtl + * + * @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 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * 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 . + * + */ + +namespace OC\Repair; + +use OC\Core\Command\Maintenance\ClearCacheJSCSS; +use OC\Template\JSCombiner; +use OC\Template\SCSSCacher; +use OCP\AppFramework\QueryException; +use OCP\ICacheFactory; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; +use Symfony\Component\Console\Input\StringInput; +use Symfony\Component\Console\Output\BufferedOutput; + +class ClearFrontendCaches implements IRepairStep { + + /** @var ICacheFactory */ + protected $cacheFactory; + + /** @var SCSSCacher */ + protected $scssCacher; + + /** @var JSCombiner */ + protected $jsCombiner; + + public function __construct(ICacheFactory $cacheFactory, + SCSSCacher $SCSSCacher, + JSCombiner $JSCombiner) { + $this->cacheFactory = $cacheFactory; + $this->scssCacher = $SCSSCacher; + $this->jsCombiner = $JSCombiner; + } + + public function getName() { + return 'Clear frontend caches'; + } + + public function run(IOutput $output) { + try { + $c = $this->cacheFactory->createDistributed('imagePath'); + $c->clear(''); + $output->info('Image cache cleared'); + + $this->scssCacher->resetCache(); + $c = $this->cacheFactory->createDistributed('SCSS'); + $c->clear(''); + $output->info('SCSS cache cleared'); + + $this->jsCombiner->resetCache(); + $c = $this->cacheFactory->createDistributed('JS'); + $c->clear(''); + $output->info('JS cache cleared'); + } catch (\Exception $e) { + $output->warning('Unable to clear the frontend cache'); + } + } +} -- cgit v1.2.3