Ejemplo n.º 1
0
 public function save($item, $value, $environment, $group, $namespace = null)
 {
     $path = $this->getStorageDirectory();
     if (!$this->files->exists($path)) {
         $this->files->makeDirectory($path, 0777);
     } elseif (!$this->files->isDirectory($path)) {
         $this->files->delete($path);
         $this->files->makeDirectory($path, 0777);
     }
     $ns_string = 'null';
     if ($namespace) {
         $ns_string = $namespace;
         $path = "{$path}/{$namespace}";
         if (!$this->files->exists($path)) {
             $this->files->makeDirectory($path, 0777);
         } elseif (!$this->files->isDirectory($path)) {
             $this->files->delete($path);
             $this->files->makeDirectory($path, 0777);
         }
     }
     $file = $this->getFilename($group, $path);
     $current = array();
     if ($this->files->exists($file)) {
         if (\Config::get('concrete.config.temp_save', true)) {
             // Make sure that we miss cache.
             $temp_file = tempnam($path, $group . '_');
             $contents = $this->files->get($file);
             $this->files->put($temp_file, $contents);
             $current = $this->files->getRequire($temp_file);
             $this->files->delete($temp_file);
         } else {
             $current = $this->files->getRequire($file);
         }
     }
     array_set($current, $item, $value);
     $renderer = new Renderer($current);
     $header = array("<?php", "", "/**", " * -----------------------------------------------------------------------------", " * Generated " . date(DATE_ATOM), " *", " * DO NOT EDIT THIS FILE DIRECTLY", " *", " * @item      {$item}", " * @group     {$group}", " * @namespace {$ns_string}", " * -----------------------------------------------------------------------------", " */", "return ");
     $rendered = $renderer->render(PHP_EOL, '    ', implode(PHP_EOL, $header));
     $result = $this->files->put($file, $rendered) !== false;
     if ($result) {
         OpCache::clear($file);
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * Utility method for clearing all application caches.
  */
 public function clearCaches()
 {
     \Events::dispatch('on_cache_flush');
     $this['cache']->flush();
     $this['cache/expensive']->flush();
     $config = $this['config'];
     // Delete and re-create the cache directory
     $cacheDir = $config->get('concrete.cache.directory');
     if (is_dir($cacheDir)) {
         $fh = Core::make('helper/file');
         $fh->removeAll($cacheDir, true);
     }
     $this->setupFilesystem();
     $pageCache = PageCache::getLibrary();
     if (is_object($pageCache)) {
         $pageCache->flush();
     }
     // clear the environment overrides cache
     $env = \Environment::get();
     $env->clearOverrideCache();
     // Clear localization cache
     Localization::clearCache();
     // clear block type cache
     BlockType::clearCache();
     // Clear precompiled script bytecode caches
     OpCache::clear();
 }
Ejemplo n.º 3
0
 /**
  * Utility method for clearing all application caches.
  */
 public function clearCaches()
 {
     \Events::dispatch('on_cache_flush');
     $this['cache']->flush();
     $this['cache/expensive']->flush();
     $config = $this['config'];
     // Delete and re-create the cache directory
     $cacheDir = $config->get('concrete.cache.directory');
     if (is_dir($cacheDir)) {
         $fh = Core::make('helper/file');
         $fh->removeAll($cacheDir, true);
     }
     $this->setupFilesystem();
     $pageCache = PageCache::getLibrary();
     if (is_object($pageCache)) {
         $pageCache->flush();
     }
     // Clear the file thumbnail path cache
     $connection = $this['database'];
     $sql = $connection->getDatabasePlatform()->getTruncateTableSQL('FileImageThumbnailPaths');
     try {
         $connection->executeUpdate($sql);
     } catch (\Exception $e) {
     }
     // clear the environment overrides cache
     $env = \Environment::get();
     $env->clearOverrideCache();
     // Clear localization cache
     Localization::clearCache();
     // clear block type cache
     BlockType::clearCache();
     // Clear precompiled script bytecode caches
     OpCache::clear();
     \Events::dispatch('on_cache_flush_end');
 }
 /**
  * Writes the core pointer into config/update.php.
  * 
  * @return true|int Returns true if the configuration file was updated, otherwise it returns the error code (one of the ApplicationUpdate::E_... constants)
  */
 public function apply()
 {
     $updates = array();
     $update_file = DIR_CONFIG_SITE . '/update.php';
     if (file_exists($update_file)) {
         if (!is_writable($update_file)) {
             return self::E_UPDATE_WRITE_CONFIG;
         }
         $updates = (array) (include $update_file);
     }
     $updates['core'] = $this->getUpdateIdentifier();
     \Config::clear('concrete.version');
     $renderer = new Renderer($updates);
     file_put_contents($update_file, $renderer->render());
     OpCache::clear($update_file);
     return true;
 }