Пример #1
0
 public function index()
 {
     /** @var UniformResourceLocator $locator */
     $locator = $this->container['locator'];
     Folder::delete($locator('gantry-cache://'), false);
     return new JsonResponse(['html' => 'Cache was successfully cleared', 'title' => 'Cache Cleared']);
 }
Пример #2
0
 /**
  * Update all CSS files in the theme.
  *
  * @param array $configurations
  * @return array List of CSS warnings.
  */
 public function updateCss(array $configurations = null)
 {
     $gantry = static::gantry();
     $compiler = $this->compiler();
     if (is_null($configurations)) {
         /** @var UniformResourceLocator $locator */
         $locator = $gantry['locator'];
         $path = $locator->findResource($compiler->getTarget(), true, true);
         // Make sure that all the CSS files get deleted.
         if (is_dir($path)) {
             Folder::delete($path, false);
         }
         $configurations = $gantry['configurations'];
     }
     // Make sure that PHP has the latest data of the files.
     clearstatcache();
     $warnings = [];
     foreach ($configurations as $configuration => $title) {
         $config = ConfigServiceProvider::load($gantry, $configuration);
         $compiler->reset()->setConfiguration($configuration)->setVariables($config->flatten('styles', '-'));
         $results = $compiler->compileAll()->getWarnings();
         if ($results) {
             $warnings[$configuration] = $results;
         }
     }
     return $warnings;
 }
Пример #3
0
 public function index()
 {
     /** @var UniformResourceLocator $locator */
     $locator = $this->container['locator'];
     Folder::delete($locator('gantry-cache://theme'), false);
     Folder::delete($locator('gantry-cache://admin'), false);
     // Make sure that PHP has the latest data of the files.
     clearstatcache();
     return new JsonResponse(['html' => 'Cache was successfully cleared', 'title' => 'Cache Cleared']);
 }
Пример #4
0
 public static function delete($id)
 {
     $gantry = Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $path = $locator->findResource('gantry-config://' . $id, true, true);
     if (is_dir($path)) {
         Folder::delete($path, true);
     }
 }
Пример #5
0
 /**
  * Update all CSS files in the theme.
  */
 public function updateCss()
 {
     $gantry = static::gantry();
     $compiler = $this->compiler();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $path = $locator->findResource($compiler->getTarget(), true, true);
     // Make sure that all the CSS files get deleted.
     if (is_dir($path)) {
         Folder::delete($path, false);
     }
     /** @var Configurations $configurations */
     $configurations = $gantry['configurations'];
     foreach ($configurations as $configuration => $title) {
         $config = ConfigServiceProvider::load($gantry, $configuration);
         $compiler->reset()->setConfiguration($configuration)->setVariables($config->flatten('styles', '-'));
         $compiler->compileAll();
     }
 }
Пример #6
0
 public function delete($id)
 {
     $model = StyleHelper::loadModel();
     $item = $model->getTable();
     $item->load($id);
     if (!$item->id) {
         throw new \RuntimeException('Outline not found', 404);
     }
     try {
         if (!$model->delete($id)) {
             $error = $model->getError();
             // Well, Joomla can always send enqueue message instead!
             if (!$error) {
                 $messages = \JFactory::getApplication()->getMessageQueue();
                 $message = reset($messages);
                 $error = $message ? $message['message'] : 'Unknown error';
             }
             throw new \RuntimeException($error);
         }
     } catch (\Exception $e) {
         throw new \RuntimeException('Deleting outline failed: ' . $e->getMessage(), 400, $e);
     }
     // Remove configuration directory.
     $gantry = $this->container;
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $path = $locator->findResource("{$this->path}/{$item->id}", true, true);
     if ($path) {
         if (file_exists($path)) {
             Folder::delete($path);
         }
     }
 }
Пример #7
0
 public function cleanup()
 {
     $name = $this->extension->name;
     $path = JPATH_SITE . '/templates/' . $name;
     // Remove compiled CSS files if they exist.
     $cssPath = $path . '/custom/css-compiled';
     if (is_dir($cssPath)) {
         \JFolder::delete($cssPath);
     } elseif (is_file($cssPath)) {
         \JFile::delete($cssPath);
     }
     // Remove wrongly named file if it exists.
     $md5path = $path . '/MD5SUM';
     if (is_file($md5path)) {
         \JFile::delete($md5path);
     }
     // Restart Gantry and initialize it.
     $gantry = Gantry::restart();
     $gantry['theme.name'] = $name;
     $gantry['streams']->register();
     // Only add error service if debug mode has been enabled.
     if ($gantry->debug()) {
         $gantry->register(new ErrorServiceProvider());
     }
     /** @var Platform $patform */
     $patform = $gantry['platform'];
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     // Initialize theme stream.
     $details = new ThemeDetails($name);
     $locator->addPath('gantry-theme', '', $details->getPaths(), false, true);
     // Initialize theme cache stream and clear theme cache.
     $cachePath = $patform->getCachePath() . '/' . $name;
     if (is_dir($cachePath)) {
         Folder::delete($cachePath);
     }
     Folder::create($cachePath);
     $locator->addPath('gantry-cache', 'theme', [$cachePath], true, true);
     $gantry['file.yaml.cache.path'] = $locator->findResource('gantry-cache://theme/compiled/yaml', true, true);
     /** @var Outlines $outlines */
     $outlines = $gantry['configurations'];
     // Update positions in manifest file.
     $positions = $outlines->positions();
     $manifest = new Manifest($name);
     $manifest->setPositions(array_keys($positions));
     $manifest->save();
 }
Пример #8
0
 /**
  * @param string $id
  * @throws \RuntimeException
  */
 public function delete($id)
 {
     if (!$this->canDelete($id)) {
         throw new \RuntimeException("Outline '{$id}' cannot be deleted", 400);
     }
     $gantry = $this->container;
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $path = $locator->findResource("{$this->path}/{$id}", true, true);
     if (!is_dir($path)) {
         throw new \RuntimeException('Outline not found', 404);
     }
     if (file_exists($path)) {
         Folder::delete($path);
     }
 }