public function doSave($con = null)
 {
     parent::doSave($con);
     $enabled_ids = $this->getValue('enabled_modules');
     $all_dependencies = sfConfig::get('app_pm_module_enabler_dependencies', array());
     foreach ($this->getObject()->getpmModules() as $pm_module) {
         $pm_module->setIsEnabled(in_array($pm_module->getId(), $enabled_ids) || $pm_module->getName() == 'pmconfiguration' ? true : false);
         $pm_module->save();
     }
     foreach ($all_dependencies as $pm_module_name => $dependency) {
         $pm_module = pmModulePeer::retrieveByName($pm_module_name);
         if ($pm_module->getIsEnabled()) {
             $dependencies = isset($all_dependencies[$pm_module_name]) ? $all_dependencies[$pm_module_name] : array();
             // save all module dependencies
             foreach ($dependencies as $dependency) {
                 $dependency = pmModulePeer::retrieveByName($dependency);
                 $dependency->setIsEnabled(true);
                 $dependency->save();
             }
         }
     }
     // clear cache
     $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_cache_dir')));
     $cache->clean();
 }
 public function execute($request)
 {
     $this->form = new sfForm();
     $this->culture = $this->context->user->getCulture();
     $this->globalForm = new SettingsGlobalForm();
     $this->siteInformationForm = new SettingsSiteInformationForm();
     $this->defaultTemplateForm = new SettingsDefaultTemplateForm();
     $this->uiLabelForm = new SettingsGenericForm(array(), array('settings' => QubitSetting::getByScope('ui_label'), 'scope' => 'ui_label', 'fieldsRequired' => false));
     $this->oaiRepositoryForm = new SettingsOaiRepositoryForm();
     $this->initializeDefaultPageElementsForm();
     // Handle POST data (form submit)
     if ($request->isMethod('post')) {
         // Clean cache
         $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_app_cache_dir') . '/settings'));
         $cache->clean();
         // Global settings form submission
         if (null !== $request->global_settings) {
             // Hack to populate "version" field so it displays
             // if validation fails. By default, their values are not included in
             // $request->parameterHolder (and thus are not bound) because their
             // <input> field is disabled.
             $version = null !== ($setting = QubitSetting::getSettingByName('version')) ? $setting->getValue(array('sourceCulture' => true)) : null;
             $this->globalForm->bind(array_merge($request->global_settings, array('version' => $version)));
             if ($this->globalForm->isValid()) {
                 // Do update and redirect to avoid repeat submit wackiness
                 $this->updateGlobalSettings();
                 $this->redirect('settings/list');
             }
         }
         // Handle site information form submission
         if (null !== $request->site_information) {
             $this->siteInformationForm->bind($request->site_information);
             if ($this->siteInformationForm->isValid()) {
                 // Do update and redirect to avoid repeat submit wackiness
                 $this->updateSiteInformationSettings();
                 $this->redirect('settings/list');
             }
         }
         // Handle default template form submission
         if (null !== $request->default_template) {
             $this->defaultTemplateForm->bind($request->default_template);
             if ($this->defaultTemplateForm->isValid()) {
                 // Do update and redirect to avoid repeat submit wackiness
                 $this->updateDefaultTemplateSettings($this->defaultTemplateForm);
                 $this->redirect('settings/list');
             }
         }
         // Handle default template form submission
         if (null !== $request->ui_label) {
             $this->uiLabelForm->bind($request->ui_label);
             if ($this->uiLabelForm->isValid()) {
                 // Do update and redirect to avoid repeat submit wackiness
                 $this->updateUiLabelSettings($this->uiLabelForm);
                 $this->redirect('settings/list');
             }
         }
         // Handle OAI Repository form submission
         if (null !== $request->oai_repository) {
             $this->oaiRepositoryForm->bind($request->oai_repository);
             if ($this->oaiRepositoryForm->isValid()) {
                 // Do update and redirect to avoid repeat submit wackiness
                 $this->updateOaiRepositorySettings($this->oaiRepositoryForm);
                 $this->redirect('settings/list');
             }
         }
         if (null !== ($languageCode = $request->languageCode)) {
             try {
                 format_language($languageCode, $languageCode);
             } catch (Exception $e) {
                 $this->redirect(array('module' => 'settings', 'action' => 'list'));
             }
             $setting = new QubitSetting();
             $setting->name = $languageCode;
             $setting->scope = 'i18n_languages';
             $setting->value = $languageCode;
             $setting->deleteable = true;
             $setting->editable = true;
             $setting->getCurrentSettingI18n()->setCulture('en');
             $setting->sourceCulture = 'en';
             $setting->save();
         }
     }
     // Populate forms
     $this->populateGlobalForm();
     $this->populateSiteInformationForm();
     $this->populateDefaultTemplateForm($this->defaultTemplateForm);
     $this->populateUiLabelForm($this->uiLabelForm);
     $this->populateOaiRepositoryForm($this->oaiRepositoryForm);
     // Last symfony 1.0 forms holdout
     $this->i18nLanguages = QubitSetting::getByScope('i18n_languages');
     $this->form->setValidator('languageCode', new sfValidatorI18nChoiceLanguage());
     $this->form->setWidget('languageCode', new sfWidgetFormI18nChoiceLanguage(array('add_empty' => true, 'culture' => $this->context->user->getCulture())));
     // make vars available to template
     $this->availableLanguages = self::$availableLanguges;
 }
Esempio n. 3
0
 /**
  * Clear the cache
  */
 public static function emptyCache()
 {
     try {
         $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_cache_dir')));
         $cache->clean();
         self::clearAll();
     } catch (Exception $e) {
     }
 }
 protected function refreshSettings()
 {
     // clear the file cache containing the settings
     $fileCache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_app_cache_dir') . '/settings'));
     $fileCache->clean();
 }
Esempio n. 5
0
 protected function execute($arguments = array(), $options = array())
 {
     $frontend_cache_dir = sfConfig::get('sf_cache_dir') . '/frontend/prod/template';
     $cache = new sfFileCache(array('cache_dir' => $frontend_cache_dir));
     $cache->clean();
 }
 /**
  * SyncRepositoryTask::execute()
  *
  * @param array $arguments
  * @param array $options
  * @return
  */
 protected function execute($arguments = array(), $options = array())
 {
     // ログファイルの設定
     $file_logger = new sfFileLogger($this->dispatcher, array('file' => $this->configuration->getRootDir() . '/log/' . $this->getName() . '.log'));
     $this->dispatcher->connect('application.log', array($file_logger, 'listenToLogEvent'));
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     // 更新フラグのあるリポジトリの最初の1件を取得する。
     $repository = RepositoryTable::getInstance()->findOneByForceUpdate(1);
     if (!$repository) {
         return false;
     }
     // 更新フラグを消しておく。
     $repository->setForceUpdate(0);
     $repository->save();
     // リポジトリを同期する。
     $this->log(sprintf('リポジトリ %s の同期を開始します', $repository->getRepositoryName()));
     // リポジトリキャッシュルートディレクトリ
     $cache_root = sfConfig::get('sf_root_dir') . '/../data/repos/';
     $dir_root = $cache_root . $repository->getCacheKey();
     $do_clone = false;
     if ($repository->getForceClone()) {
         // 一旦このディレクトリ配下をすべて削除する
         sfToolkit::clearDirectory($dir_root_repo);
         // 強制clone
         $do_clone = true;
     } else {
         if (!is_dir($dir_root)) {
             // ディレクトリがない。
             mkdir($dir_root, 0777, true);
             // このディレクトリ配下にcloneを取得する。
             $do_clone = true;
         } else {
             // リポジトリは取得済か?
             $dir_root_repo = $dir_root . DIRECTORY_SEPARATOR . $repository->getRepositoryName();
             try {
                 $git = new myVersionControl_Git($dir_root_repo);
                 $git->setGitCommandPath('git');
                 // pullする。
                 $this->log('リポジトリをpullしています');
                 $pullMessage = $git->getCommand('pull')->execute();
                 if (preg_match('/up\\-to\\-date/i', $pullMessage)) {
                     $this->log('更新はありません');
                     return;
                 }
             } catch (Exception $e) {
                 // 一旦このディレクトリ配下をすべて削除する
                 sfToolkit::clearDirectory($dir_root_repo);
                 // cloneする
                 $do_clone = true;
             }
         }
     }
     if ($do_clone) {
         $this->log('リポジトリをcloneしています');
         $git = new myVersionControl_Git($dir_root);
         $git->setGitCommandPath('git');
         $git->createClone($repository->getRepository());
         // リポジトリ
         $dir_root_repo = $dir_root . DIRECTORY_SEPARATOR . $repository->getRepositoryName();
         try {
             $git = new myVersionControl_Git($dir_root_repo);
             $git->setGitCommandPath('git');
         } catch (Exception $e) {
             // 一旦このディレクトリ配下をすべて削除する
             sfToolkit::clearDirectory($dir_root_repo);
             return;
         }
     }
     // このリポジトリの対象ファイルリストを取得する。
     $files = sfFinder::type('file')->prune('.git')->discard('.git')->relative()->in($search_dir = $dir_root . DIRECTORY_SEPARATOR . $repository->getRepositoryName() . $repository->getSubdirectory());
     $page_path_root = $repository->getBindPath();
     // ---------------------------------------------
     // ファイル別に処理
     $new_commit_found = false;
     foreach ($files as $file) {
         $this->log(sprintf('ファイル:%s', $file));
         $info = pathinfo($file);
         $file_path = $search_dir . DIRECTORY_SEPARATOR . $file;
         // ファイルの更新タイムスタンプが新しいものだけ処理する
         if (filemtime($file_path) < time() - 86400) {
             $this->log('更新なし');
             continue;
         }
         //  このファイルが対象かどうかチェックする。
         if (!PageTable::needProcess($file)) {
             $this->log('ページ取り込み対象外');
             // 画像データなら、パブリックディレクトリにコピーする。
             if (preg_match('/^(png|jpg|gif)$/', $info['extension'])) {
                 $target_path = $repository->getImagePublicPath($file);
                 $target_dir = dirname($target_path);
                 if (!is_dir($target_dir)) {
                     mkdir($target_dir, 0777, true);
                 }
                 $this->log('ファイルをパブリックディレクトリにコピーします。');
                 copy($file_path, $target_path);
                 chmod($target_path, 0666);
             }
             continue;
         }
         //  各ページに対応するURLパスを求める。
         if ('.' !== $info['dirname']) {
             $page_path = strtolower($page_path_root . '/' . $info['dirname'] . '/' . $info['filename']);
         } else {
             $page_path = strtolower($page_path_root . '/' . $info['filename']);
         }
         // ページに対応するレコードを取得する。
         $page = Doctrine_Core::getTable('Page')->findOneByPath($page_path);
         if (!$page) {
             $page = new Page();
             $page->setPath($page_path);
             $page->setRepository($repository);
         }
         echo $file;
         // ページごとにコミット履歴を取得する。
         $commits = $git->getCommits('master', $file_path);
         foreach ($commits as $commit) {
             // 既存ページの場合はコミットがすでに取り込み済かチェックする。
             $commit_record = null;
             if (!$page->isNew()) {
                 $commit_record = Doctrine_Core::getTable('Commit')->findOneByCommitKeyAndPageId($commit->__toString(), $page->getId());
             }
             if (!$commit_record) {
                 // コミットを登録する。
                 $new_commit_found = true;
                 $this->log(sprintf('コミット %s を取得しています', $commit));
                 $commit_record = new Commit();
                 $commit_record->setAuthorHandle($commit->getAuthorHandle());
                 $commit_record->setAuthorEmail($commit->getAuthorEmail());
                 $commit_record->setCommitterHandle($commit->getCommitterHandle());
                 $commit_record->setCommitterEmail($commit->getCommitterEmail());
                 $commit_record->setCommittedAt(date('Y/m/d H:i:s', $commit->getCommittedAt()));
                 $commit_record->setCommitKey($commit);
                 $commit_record->setPage($page);
                 $commit_record->save();
                 $commit_record->free();
                 unset($commit_record);
             }
         }
         //  新規のコミットが無い場合は、処理をスキップする。
         if (!$new_commit_found) {
             continue;
         }
         $new_commit_found = true;
         $page->setContentType($type = PageTable::checkType($file));
         $content = file_get_contents($file_path);
         if ('UTF-8' !== ($encoding = mb_detect_encoding($content))) {
             $content = mb_convert_encoding($content, 'UTF-8', $encoding);
         }
         $page->setContentRaw($content);
         // ページのレンダリングモードに合わせてレンダリングする。
         $page->setContentRendered($rendered = PageTable::renderContent($content, $type));
         // DOMパース用に、特殊文字を置換する。
         $html = mb_convert_encoding($rendered, 'HTML-ENTITIES', 'ASCII, JIS, UTF-8, EUC-JP, SJIS');
         // レンダリング結果をパースする。
         $dom = new DomDocument();
         $dom->loadHTML($html);
         $xpath = new DOMXPath($dom);
         // タイトルを探す。
         $domElements = $xpath->query('//title | //h1');
         if (count($domElements)) {
             $page->setTitle($domElements->item(0)->nodeValue);
         }
         // 見出しをパースする
         $domElements = $xpath->query('//h1 | //h2 | //h3');
         $indexes = array();
         $now_h1 = array();
         $now_h2 = array();
         foreach ($domElements as $domElement) {
             switch ($domElement->nodeName) {
                 case 'h1':
                     $indexes[] = array('type' => 'h1', 'text' => $domElement->nodeValue, 'id' => $domElement->getAttribute('id'), 'children' => array());
                     $now_h1 =& $indexes[count($indexes) - 1]['children'];
                     break;
                 case 'h2':
                     $now_h1[] = array('type' => 'h2', 'text' => $domElement->nodeValue, 'id' => $domElement->getAttribute('id'), 'children' => array());
                     $now_h2 =& $now_h1[count($now_h1) - 1]['children'];
                     break;
                 case 'h3':
                     $now_h2[] = array('type' => 'h3', 'text' => $domElement->nodeValue, 'id' => $domElement->getAttribute('id'), 'children' => array());
                     break;
                 default:
                     break;
             }
         }
         $page->setIndexJson(json_encode($indexes));
         // 保存する。
         $page->save();
         $page->free();
         unset($page);
     }
     // 新しいコミットがあった場合、キャッシュを削除する。
     if ($new_commit_found) {
         $frontend_cache_dir = sfConfig::get('sf_cache_dir') . '/frontend/prod/template';
         $cache = new sfFileCache(array('cache_dir' => $frontend_cache_dir));
         $cache->clean();
     }
     $this->log(sprintf('リポジトリ %s の同期が完了しました', $repository->getRepositoryName()));
 }
 /**
  * Cleans the cache.
  *
  * If no namespace is specified all cache files will be destroyed
  * else only cache files of the specified namespace will be destroyed.
  *
  * @param string The name of the cache namespace
  *
  * @return boolean true if no problem
  */
 public function clean($namespace = null, $mode = 'all')
 {
     // We will just flush the ENTIRE memcache
     try {
         foreach (self::$mem as $bucket) {
             if (!@$bucket->flush()) {
                 throw new Exception('Error flushing');
             }
         }
     } catch (Exception $e) {
         parent::clean($namespace, $mode);
     }
 }