/** * Activate plugin if path matches to the configured one. */ public function onPluginsInitialized() { if ($this->isAdmin()) { $this->active = false; return; } /** @var Uri $uri */ $uri = $this->grav['uri']; $route = $this->config->get('plugins.cachebuster.route'); if ($route && $route == $uri->path()) { \Grav\Common\Cache::clearCache('all'); echo 'Your cache has been cleared.'; exit; } }
/** * @param InputInterface $input * @param OutputInterface $output */ private function cleanPaths(InputInterface $input, OutputInterface $output) { $output->writeln(''); $output->writeln('<magenta>Clearing cache</magenta>'); $output->writeln(''); if ($input->getOption('all')) { $remove = 'all'; } elseif ($input->getOption('assets-only')) { $remove = 'assets-only'; } elseif ($input->getOption('images-only')) { $remove = 'images-only'; } elseif ($input->getOption('cache-only')) { $remove = 'cache-only'; } else { $remove = 'standard'; } foreach (Cache::clearCache($remove) as $result) { $output->writeln($result); } }
/** * loops over the array of paths and deletes the files/folders */ private function cleanPaths() { $this->output->writeln(''); $this->output->writeln('<magenta>Clearing cache</magenta>'); $this->output->writeln(''); if ($this->input->getOption('all')) { $remove = 'all'; } elseif ($this->input->getOption('assets-only')) { $remove = 'assets-only'; } elseif ($this->input->getOption('images-only')) { $remove = 'images-only'; } elseif ($this->input->getOption('cache-only')) { $remove = 'cache-only'; } elseif ($this->input->getOption('tmp-only')) { $remove = 'tmp-only'; } else { $remove = 'standard'; } foreach (Cache::clearCache($remove) as $result) { $this->output->writeln($result); } }
/** * Delete page. * * @return bool True if the action was performed. * @throws \RuntimeException */ protected function taskDelete() { if (!$this->authorizeTask('delete page', ['admin.pages', 'admin.super'])) { return; } // Only applies to pages. if ($this->view != 'pages') { return false; } /** @var Uri $uri */ $uri = $this->grav['uri']; try { $page = $this->admin->page(); if (count($page->translatedLanguages()) > 1) { $page->file()->delete(); } else { Folder::delete($page->path()); } $results = Cache::clearCache('standard'); // Set redirect to either referrer or pages list. $redirect = 'pages'; $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.SUCCESSFULLY_DELETED'), 'info'); $this->setRedirect($redirect); } catch (\Exception $e) { throw new \RuntimeException('Deleting page failed on error: ' . $e->getMessage()); } return true; }
/** * Delete page. * * @return bool True if the action was performed. * @throws \RuntimeException */ protected function taskDelete() { if (!$this->authoriseTask('delete page', ['admin.pages', 'admin.super'])) { return; } // Only applies to pages. if ($this->view != 'pages') { return false; } /** @var Uri $uri */ $uri = $this->grav['uri']; try { $page = $this->admin->page(); Folder::delete($page->path()); $results = Cache::clearCache('standard'); // Set redirect to either referrer or pages list. $redirect = $uri->referrer(); if ($redirect == $uri->route()) { $redirect = 'pages'; } $this->admin->setMessage('Successfully deleted', 'info'); $this->setRedirect($redirect); } catch (\Exception $e) { throw new \RuntimeException('Deleting page failed on error: ' . $e->getMessage()); } return true; }
/** * Clear the cache. * * @return bool True if the action was performed. */ protected function taskClearCache() { if (!$this->authoriseTask('clear cache', ['admin.cache', 'admin.super'])) { return; } $results = Cache::clearCache('standard'); if (count($results) > 0) { $this->admin->json_response = ['status' => 'success', 'message' => 'Cache cleared']; } else { $this->admin->json_response = ['status' => 'error', 'message' => 'Error clearing cache']; } return true; }