public function indexAction()
 {
     Translation_Model_Manager::generate();
     Centurion_Signal::factory('clean_cache')->send($this);
     Centurion_Loader_PluginLoader::cleanCache(Centurion_Loader_PluginLoader::getIncludeFileCache());
     Centurion_Loader_PluginLoader::setStaticCachePlugin(null);
 }
 public function clearCacheAction()
 {
     //$caches = array();
     //        foreach (Centurion_Config_Manager::get('resources.cachemanager') as $key => $value) {
     //            Zend_Cache::_makeBackend($value['backend']['name'], $value['backend']['options'])->clean(Zend_Cache::CLEANING_MODE_ALL);
     //        }
     Centurion_Signal::factory('clean_cache')->send($this);
     Centurion_Loader_PluginLoader::cleanCache(Centurion_Loader_PluginLoader::getIncludeFileCache());
     Centurion_Loader_PluginLoader::setStaticCachePlugin(null);
 }
 public function testCleanCache()
 {
     $this->assertFileNotExists(self::$_classFileIncCache);
     Centurion_Loader_PluginLoader::shutdown();
     $this->assertFileExists(self::$_classFileIncCache);
     Centurion_Loader_PluginLoader::clean();
     $this->assertFileNotExists(self::$_classFileIncCache);
     Centurion_Loader_PluginLoader::shutdown();
     $this->assertFileExists(self::$_classFileIncCache);
 }
Example #4
0
 public function testCleanCache()
 {
     $this->assertFileNotExists(self::$_classFileIncCache);
     Centurion_Loader_PluginLoader::setCacheRotate(0);
     Centurion_Loader_PluginLoader::shutdown();
     $this->assertFileExists(self::$_classFileIncCache);
     Centurion_Loader_PluginLoader::clean();
     $this->assertEquals(file_get_contents(self::$_classFileIncCache), '');
     Centurion_Loader_PluginLoader::shutdown();
     $this->assertFileExists(self::$_classFileIncCache);
 }
 public function tearDown()
 {
     global $application;
     Centurion_Controller_Front::getInstance()->resetInstance();
     $this->resetRequest();
     $this->resetResponse();
     $this->request->setPost(array());
     $this->request->setQuery(array());
     Centurion_Signal::unregister();
     Centurion_Auth::getInstance()->clearIdentity();
     Centurion_Loader_PluginLoader::cleanCache();
     return $application->getBootstrap()->bootstrap('cachemanager');
 }
Example #6
0
 /**
  * Clear cache with "clear cache" command.
  */
 public function clear($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = null, $environment = self::DEFAULT_ENVIRONMENT)
 {
     $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
     define('APPLICATION_PATH', $this->_loadedProfile->search('applicationDirectory')->getPath());
     $config = Centurion_Config_Directory::loadConfig(APPLICATION_PATH . '/configs', $environment);
     $cacheManager = new Centurion_Cache_Manager();
     $options = $config['resources']['cachemanager'];
     foreach ($options as $key => $value) {
         if ($cacheManager->hasCacheTemplate($key)) {
             $cacheManager->setTemplateOptions($key, $value);
         } else {
             $cacheManager->setCacheTemplate($key, $value);
         }
     }
     if (null === $tags || !is_array($tags) && !is_string($tags)) {
         $tags = array();
     }
     if (is_string($tags)) {
         $tags = explode(',', $tags);
     }
     foreach ($cacheManager->getBackends() as $key => $cache) {
         $this->_registry->getResponse()->appendContent(sprintf(">>> (%s) %s", $key, get_class($cache)));
         if ($cache instanceof Zend_Cache_Backend_ExtendedInterface) {
             switch ($mode) {
                 case Zend_Cache::CLEANING_MODE_ALL:
                     $ids = $cache->getIds();
                     break;
                 case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
                     $ids = $cache->getIdsMatchingAnyTags($tags);
                     break;
                 case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
                     $ids = $cache->getIdsMatchingTags($tags);
                     break;
                 case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
                     $ids = $cache->getIdsNotMatchingTags($tags);
                     break;
                 case Zend_Cache::CLEANING_MODE_OLD:
                     $ids = $cache->getIds();
                     break;
             }
         } else {
             $this->_registry->getResponse()->appendContent('not extended');
         }
         $cache->clean($mode, $tags);
         if ($cache instanceof Zend_Cache_Backend_ExtendedInterface) {
             if ($mode === Zend_Cache::CLEANING_MODE_OLD) {
                 $ids = array_diff($ids, $cache->getIds());
             }
             if (count($ids)) {
                 foreach ($ids as $val) {
                     $this->_registry->getResponse()->appendContent(sprintf('>> %-9s %s', 'id-', $val));
                 }
             }
         }
     }
     if ($mode === Zend_Cache::CLEANING_MODE_ALL) {
         Centurion_Loader_PluginLoader::clean();
     }
 }
Example #7
0
 public function acl($env)
 {
     $this->bootstrap($env);
     $application = $this->_application;
     $bootstrap = $application->getBootstrap();
     $front = $bootstrap->getResource('FrontController');
     $modules = $front->getControllerDirectory();
     $default = $front->getDefaultModule();
     $curBootstrapClass = get_class($bootstrap);
     $options = $bootstrap->getOption('resources');
     $options = $options['modules'];
     if (is_array($options) && !empty($options[0])) {
         $diffs = array_diff($options, array_keys($modules));
         if (count($diffs)) {
             throw new Centurion_Application_Resource_Exception(sprintf("The modules %s is not found in your registry (%s)", implode(', ', $diffs), implode(PATH_SEPARATOR, $modules)));
         }
         foreach ($modules as $key => $module) {
             if (!in_array($key, $options) && $key !== $default) {
                 unset($modules[$key]);
                 $front->removeControllerDirectory($key);
             }
         }
         $modules = Centurion_Inflector::sortArrayByArray($modules, array_values($options));
     }
     require_once APPLICATION_PATH . '/../library/Centurion/Contrib/auth/models/DbTable/Permission.php';
     require_once APPLICATION_PATH . '/../library/Centurion/Contrib/auth/models/DbTable/Row/Permission.php';
     $permissionTable = Centurion_Db::getSingleton('auth/permission');
     foreach ($modules as $module => $moduleDirectory) {
         echo "\n\n" . 'Scan new module: ' . $module . "\n";
         $bootstrapClass = $this->_formatModuleName($module) . '_Bootstrap';
         $modulePath = dirname($moduleDirectory);
         $dataPath = $modulePath . '/controllers/';
         if (is_dir($dataPath)) {
             $db = Zend_Db_Table::getDefaultAdapter();
             foreach (new DirectoryIterator($dataPath) as $file) {
                 if ($file->isDot() || !$file->isFile()) {
                     continue;
                 }
                 if (substr($file, 0, 5) !== 'Admin') {
                     continue;
                 }
                 $controllerName = substr($file, 5, -14);
                 $object = Centurion_Inflector::tableize($controllerName, '-');
                 $tab = array('index' => 'View %s %s index', 'list' => 'View %s %s list', 'get' => 'View an %s %s', 'post' => 'Create an %s %s', 'new' => 'Access to creation of an %s %s', 'delete' => 'Delete an %s %s', 'put' => 'Update an %s %s', 'batch' => 'Batch an %s %s', 'switch' => 'Switch an %s %s');
                 foreach ($tab as $key => $description) {
                     list($row, $created) = $permissionTable->getOrCreate(array('name' => $module . '_' . $object . '_' . $key));
                     if ($created) {
                         echo 'Create permission: ' . $module . '_' . $object . '_' . $key . "\n";
                         $row->description = sprintf($description, $module, $object);
                         $row->save();
                     }
                 }
             }
         }
     }
     Centurion_Loader_PluginLoader::clean();
     Centurion_Signal::factory('clean_cache')->send($this);
 }
Example #8
0
 /**
  * @param $env
  * @param bool $acceptAll
  * @param bool $ignoreLaunched
  * @throws Exception
  * @throws Centurion_Application_Resource_Exception
  *
  * @todo: rajouter la gestion des php
  * @todo: refractoring
  */
 public function update($env, $acceptAll = false, $ignoreLaunched = true)
 {
     if ($acceptAll === 'true') {
         $acceptAll = true;
     }
     if ($ignoreLaunched === 'true') {
         $ignoreLaunched = true;
     }
     if ($acceptAll === 'false') {
         $acceptAll = false;
     }
     if ($ignoreLaunched === 'false') {
         $ignoreLaunched = false;
     }
     $this->bootstrap($env);
     $application = $this->_application;
     $bootstrap = $application->getBootstrap();
     $front = $bootstrap->getResource('FrontController');
     $modules = $front->getControllerDirectory();
     $default = $front->getDefaultModule();
     $options = $bootstrap->getOption('resources');
     $options = $options['modules'];
     if (is_array($options) && !empty($options[0])) {
         $diffs = array_diff($options, array_keys($modules));
         if (count($diffs)) {
             throw new Centurion_Application_Resource_Exception(sprintf("The modules %s is not found in your registry (%s)", implode(', ', $diffs), implode(PATH_SEPARATOR, $modules)));
         }
         foreach ($modules as $key => $module) {
             if (!in_array($key, $options) && $key !== $default) {
                 unset($modules[$key]);
                 $front->removeControllerDirectory($key);
             }
         }
         $modules = Centurion_Inflector::sortArrayByArray($modules, array_values($options));
     }
     $db = Zend_Db_Table::getDefaultAdapter();
     foreach ($modules as $module => $moduleDirectory) {
         $modulePath = dirname($moduleDirectory);
         $dataPath = $modulePath . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR;
         echo $dataPath;
         if (is_dir($dataPath)) {
             echo 'Open ' . $dataPath . "\n";
             $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dataPath, FilesystemIterator::SKIP_DOTS | FilesystemIterator::KEY_AS_FILENAME));
             $files = iterator_to_array($files);
             ksort($files);
             $files = array_merge(array('schema.sql' => null, 'data.sql' => null), $files);
             foreach ($files as $file) {
                 if (null == $file) {
                     continue;
                 }
                 if ($file->isDir()) {
                     continue;
                 }
                 if (Centurion_Inflector::extension($file) !== '.sql') {
                     continue;
                 }
                 $choice = null;
                 if (file_exists($file->getPathname() . '.' . APPLICATION_ENV . '.done')) {
                     if ($ignoreLaunched) {
                         continue;
                     }
                     if (!$acceptAll) {
                         echo sprintf('The file %s seems to be already executed. Do you want to launch it?' . "\n", $file->getPathname());
                     }
                 }
                 if (!$acceptAll) {
                     echo sprintf('Find a new file file %s. Do you want to launch it?' . "\n", $file->getPathname());
                 } else {
                     $choice = '1';
                 }
                 if (null == $choice) {
                     do {
                         echo '1) Execute' . "\n";
                         echo '2) Ignore' . "\n";
                         echo '3) Mark it without execute it' . "\n";
                         echo '? ';
                         $choice = trim(fgets(STDIN));
                     } while (!in_array($choice, array('1', '2', '3')));
                 }
                 if ($choice == '2') {
                     echo "\n\n";
                     continue;
                 }
                 if ($choice == '1') {
                     echo sprintf('Exec the file %s' . "\n", $file->getPathname());
                     try {
                         $db->beginTransaction();
                         $query = '';
                         foreach (new SplFileObject($file->getPathname()) as $line) {
                             $query .= $line;
                             if (substr(rtrim($query), -1) == ';') {
                                 $statement = $db->query($query);
                                 $statement->closeCursor();
                                 unset($statement);
                                 $query = '';
                             }
                         }
                         $db->commit();
                     } catch (Exception $e) {
                         $db->rollback();
                         throw $e;
                     }
                 }
                 touch($file->getPathname() . '.' . APPLICATION_ENV . '.done');
                 echo "\n\n";
             }
         }
     }
     Centurion_Loader_PluginLoader::clean();
     Centurion_Signal::factory('clean_cache')->send($this);
 }
Example #9
0
 protected static function _registerShutDown()
 {
     if (!self::$_shutdownRegister) {
         register_shutdown_function(array('Centurion_Loader_PluginLoader', 'shutdown'));
         self::$_shutdownRegister = true;
     }
 }