Exemple #1
0
 /**
  * デモ用のCSVデータを初期化する
  */
 function initcsv()
 {
     // データベース初期化
     if (!$this->BaserManager->initDb()) {
         echo "データベースの初期化に失敗しました\n";
         return;
     }
     // キャッシュ削除
     clearAllCache();
     // ユーザー作成
     if (!$this->_initUsers()) {
         echo "ユーザー「operator」の作成に失敗しました\n";
         return;
     }
     // サイト設定
     if (!$this->_initSiteConfigs()) {
         echo "システム設定の更新に失敗しました\n";
         return;
     }
     // プラグインの有効化
     if (!$this->_initPlugin()) {
         echo "プラグインの有効化に失敗しました\n";
         return;
     }
     // ブログ記事の投稿日更新
     if (!$this->_initBlogPosts()) {
         echo "ブログ記事の投稿日の更新に失敗しました\n";
         return;
     }
     // でもテーマの配置
     if (!$this->BaserManager->deployTheme()) {
         echo "デモテーマの配置に失敗しました。\n";
         return;
     }
     // スケルトンテーマの配置
     if (!$this->BaserManager->deployTheme('skelton')) {
         echo "テーマの配置に失敗しました。\n";
         return;
     }
     // ページ初期化
     if ($this->_initPages()) {
         echo "デモデータの初期化に成功しました\n";
     } else {
         echo "ページテンプレートの更新に失敗しました\n";
     }
 }
Exemple #2
0
 /**
  * バックアップファイルを復元する
  *
  * @param array $data
  * @return boolean
  * @access protected
  */
 protected function _restoreDb($data)
 {
     if (empty($data['Tool']['backup']['tmp_name'])) {
         return false;
     }
     $tmpPath = TMP . 'schemas' . DS;
     $targetPath = $tmpPath . $data['Tool']['backup']['name'];
     if (!move_uploaded_file($data['Tool']['backup']['tmp_name'], $targetPath)) {
         return false;
     }
     /* ZIPファイルを解凍する */
     $Simplezip = new Simplezip();
     if (!$Simplezip->unzip($targetPath, $tmpPath)) {
         return false;
     }
     @unlink($targetPath);
     $result = true;
     if (!$this->_loadBackup($tmpPath . 'baser' . DS, 'baser')) {
         $result = false;
     }
     if (!$this->_loadBackup($tmpPath . 'plugin' . DS, 'plugin')) {
         $result = false;
     }
     $this->_resetTmpSchemaFolder();
     clearAllCache();
     return $result;
 }
 /**
  * キャッシュファイルを全て削除する
  */
 public function testClearAllCache()
 {
     // ダミーのキャッシュファイルを生成
     $coreConf = Cache::config('_cake_core_');
     $coreConf = $coreConf['settings'];
     $modelConf = Cache::config('_cake_model_');
     $modelConf = $modelConf['settings'];
     $envConf = Cache::config('_cake_env_');
     $envConf = $envConf['settings'];
     $coreCache = new File($coreConf['path'] . $coreConf['prefix'] . 'cache', true);
     $modelCache = new File($modelConf['path'] . $modelConf['prefix'] . 'cache', true);
     $envCache = new File($envConf['path'] . $envConf['prefix'] . 'cache', true);
     $viewCache = new File(CACHE . 'views' . DS . 'cache', true);
     $dataCache = new File(CACHE . 'datas' . DS . 'cache', true);
     // キャッシュ削除
     clearAllCache();
     $this->assertFalse($coreCache->exists());
     $this->assertFalse($modelCache->exists());
     $this->assertFalse($envCache->exists());
     $this->assertFalse($viewCache->exists());
     $this->assertFalse($dataCache->exists());
     $coreCache->close();
     $modelCache->close();
     $envCache->close();
     $viewCache->close();
     $dataCache->close();
 }
 /**
  * 初期データセットをダウンロードする 
  */
 public function admin_download_default_data_pattern()
 {
     /* コアのCSVを生成 */
     $tmpDir = TMP . 'csv' . DS;
     $Folder = new Folder();
     $Folder->create($tmpDir);
     emptyFolder($tmpDir);
     clearAllCache();
     $excludes = array('plugins', 'dblogs', 'users', 'favorites');
     $this->_writeCsv('baser', 'core', $tmpDir, $excludes);
     /* プラグインのCSVを生成 */
     $plugins = CakePlugin::loaded();
     foreach ($plugins as $plugin) {
         $Folder->create($tmpDir . $plugin);
         emptyFolder($tmpDir . $plugin);
         $this->_writeCsv('plugin', $plugin, $tmpDir . $plugin . DS);
     }
     /* site_configsの編集 (email / google_analytics_id / version) */
     $targets = array('email', 'google_analytics_id', 'version');
     $path = $tmpDir . 'site_configs.csv';
     $fp = fopen($path, 'a+');
     $records = array();
     while (($record = fgetcsvReg($fp, 10240)) !== false) {
         if (in_array($record[1], $targets)) {
             $record[2] = '';
         }
         $records[] = '"' . implode('","', $record) . '"';
     }
     ftruncate($fp, 0);
     fwrite($fp, implode("\n", $records));
     /* ZIPに固めてダウンロード */
     $fileName = 'default';
     $Simplezip = new Simplezip();
     $Simplezip->addFolder($tmpDir);
     $Simplezip->download($fileName);
     emptyFolder($tmpDir);
     exit;
 }
 /**
  * BaserCMSを初期化する
  * debug フラグが -1 の場合のみ実行可能
  *
  * @return	void
  * @access	public
  */
 function reset()
 {
     $this->pageTitle = 'BaserCMSの初期化';
     $this->layoutPath = 'admin';
     $this->layout = 'default';
     $this->subDir = 'admin';
     if (!empty($this->data['Installation']['reset'])) {
         $messages = array();
         $file = new File(CONFIGS . 'core.php');
         $data = $file->read();
         $pattern = '/Configure\\:\\:write[\\s]*\\([\\s]*\'App\\.baseUrl\'[\\s]*,[\\s]*\'\'[\\s]*\\);\\n/is';
         if (preg_match($pattern, $data)) {
             $data = preg_replace($pattern, "Configure::write('App.baseUrl', env('SCRIPT_NAME'));\n", $data);
             if (!$file->write($data)) {
                 $messages[] = 'スマートURLの設定を正常に初期化できませんでした。';
             }
             $file->close();
         }
         if (!$this->writeSmartUrl(false)) {
             $messages[] = 'スマートURLの設定を正常に初期化できませんでした。';
         }
         if (file_exists(CONFIGS . 'database.php')) {
             // データベースのデータを削除
             $this->BaserManager->deleteAllTables();
             unlink(CONFIGS . 'database.php');
         }
         if (file_exists(CONFIGS . 'install.php')) {
             unlink(CONFIGS . 'install.php');
         }
         $themeFolder = new Folder(WWW_ROOT . 'themed');
         $themeFiles = $themeFolder->read(true, true, true);
         foreach ($themeFiles[0] as $theme) {
             $pagesFolder = new Folder($theme . DS . 'pages');
             $pathes = $pagesFolder->read(true, true, true);
             foreach ($pathes[0] as $path) {
                 $folder = new Folder();
                 $folder->delete($path);
                 $folder = null;
             }
             foreach ($pathes[1] as $path) {
                 if (basename($path) != 'empty') {
                     unlink($path);
                 }
             }
             $pagesFolder = null;
         }
         $themeFolder = null;
         if ($messages) {
             $messages[] = '手動でサーバー上より上記ファイルを削除して初期化を完了させてください。';
         }
         $messages = am(array('BaserCMSを初期化しました。', ''), $messages);
         $message = implode('<br />', $messages);
         clearAllCache();
         $this->Session->setFlash($message);
         $complete = true;
     } else {
         $complete = false;
     }
     $this->set('complete', $complete);
 }
 /**
  * プラグインをアンインストールする
  * 
  * @param string $name
  * @return boolean
  */
 public function uninstallPlugin($name)
 {
     $Plugin = ClassRegistry::init('Plugin');
     $data = $Plugin->find('first', array('conditions' => array('Plugin.name' => $name), 'recursive' => -1));
     $data['Plugin']['status'] = false;
     if ($Plugin->save($data)) {
         clearAllCache();
         return true;
     } else {
         return false;
     }
 }
Exemple #7
0
 /**
  * [ADMIN] 固定ページファイルを登録する
  *
  * @return void
  * @access public
  */
 public function admin_entry_page_files()
 {
     // 現在のテーマの固定ページファイルのパスを取得
     $pagesPath = getViewPath() . 'Pages';
     $result = $this->Page->entryPageFiles($pagesPath);
     clearAllCache();
     $this->setMessage($result['all'] . ' ページ中 ' . $result['insert'] . ' ページの新規登録、 ' . $result['update'] . ' ページの更新に成功しました。');
     $this->redirect(array('action' => 'index'));
 }
 /**
  * 再インストール
  * 
  * コマンドはインストールと同じ
  */
 public function reinstall()
 {
     if (Configure::read('debug') != -1) {
         $this->err('baserCMSの初期化を行うには、debug を -1 に設定する必要があります。');
         return false;
     }
     $result = true;
     if (!$this->_reset()) {
         $result = false;
     }
     clearAllCache();
     if (!$this->_install()) {
         $result = false;
     }
     if (!$result) {
         $this->err("baserCMSの再インストールに失敗しました。ログファイルを確認してください。");
     }
 }
Exemple #9
0
 /**
  * 一括無効
  * 
  * @param array $ids プラグインIDの配列
  * @return bool
  */
 protected function _batch_del($ids)
 {
     if ($ids) {
         foreach ($ids as $id) {
             $data = $this->Plugin->read(null, $id);
             if ($this->BcManager->uninstallPlugin($data['Plugin']['name'])) {
                 $this->Plugin->saveDbLog('プラグイン「' . $data['Plugin']['title'] . '」 を 無効化しました。');
             }
         }
         clearAllCache();
     }
     return true;
 }
Exemple #10
0
     // separate date from time
     $time = explode(" ", $date);
     $get_time = $time[1];
     // joining date and time
     $date = dateToGregDB($date) . ' ' . $get_time;
 } else {
     $date = $_POST['new_post_date'];
 }
 $desc = $_POST['new_post_desc'];
 $status = $_POST['new_post_status'];
 $comment_status = $_POST['new_post_comment_status'];
 $link_title = escapeSingleQuotes($_POST['new_post_link_title']);
 $link_title = urlencode(str_replace(' ', '-', $link_title));
 $type = $_POST['post_type'];
 // clearing all cache files so that they will rebuilt
 clearAllCache();
 $res = $post->updatePost($id, $date, $title, $link_title, $content, $excerpt, $desc, $status, $comment_status);
 if (!$res) {
     goToError('?switch=new_post', _e('cant_make_new_post_or_page', '', '', true));
 }
 $conn = MySQL::open_conn();
 if (isset($_POST['category'])) {
     $post_id = $id;
     foreach ($_POST['category'] as $cat_id) {
         if (is_numeric($cat_id)) {
             $values[] = "({$post_id}, " . (int) $cat_id . ')';
         }
     }
     $query = "DELETE FROM c_posts_cats WHERE post_id = {$post_id}";
     // remove all rows where post_id = this post
     $res = $conn->query($query);
 /**
  * スキーマファイルを読み込みデータベースのテーブル構造を変更する
  *
  * @param string $version アップデート対象のバージョン番号を指定します。(例)'4.0.0'
  * @param tring $plugin プラグイン内のスキーマを読み込むにはプラグイン名を指定します。(例)'Mail'
  * @param string $filterTable 指定したテーブルのみを追加・更新する場合は、プレフィックス部分を除外したテーブル名を指定します。(例)'permissions'
  *		指定しない場合は全てのスキーマファイルが対象となります。
  * @param string $filterType 指定した更新タイプ(create / alter / drop)のみを対象とする場合は更新タイプを指定します。(例)'create'
  *		指定しない場合は全てのスキーマファイルが対象となります。
  * @return boolean
  * @access	public
  */
 public function loadSchema($version, $plugin = '', $filterTable = '', $filterType = '')
 {
     $path = $this->_getUpdatePath($version, $plugin);
     if (!$path) {
         return false;
     }
     // アップデートの場合 drop field は実行しない
     $result = $this->Updater->loadSchema('default', $path, $filterTable, $filterType, array('updater.php'), false);
     clearAllCache();
     return $result;
 }
 /**
  * キャッシュファイルを全て削除する
  * 
  * @return void
  * @access public
  */
 function admin_del_cache()
 {
     clearAllCache();
     $this->Session->setFlash('サーバーキャッシュを削除しました。');
     $this->redirect(array('action' => 'form'));
 }
Exemple #13
0
 /**
  * CSVを読み込む
  *
  * @param	array	データベース設定名
  * @param	string	CSVパス
  * @param	string	テーブル指定
  * @return 	boolean
  */
 public function loadCsv($dbConfigName, $path, $options = [])
 {
     $options = array_merge(['filterTable' => ''], $options);
     // テーブルリストを取得
     $db = ConnectionManager::getDataSource($dbConfigName);
     $db->cacheSources = false;
     $listSources = $db->listSources();
     $prefix = $db->config['prefix'];
     $Folder = new Folder($path);
     $files = $Folder->read(true, true);
     $result = true;
     foreach ($files[1] as $file) {
         if (preg_match('/^(.*?)\\.csv$/', $file, $matches)) {
             $table = $matches[1];
             if (in_array($prefix . $table, $listSources)) {
                 if ($options['filterTable'] && $options['filterTable'] != $table) {
                     continue;
                 }
                 if (!$db->loadCsv(['path' => $path . DS . $file, 'encoding' => 'SJIS'])) {
                     $result = false;
                     break;
                 }
             }
         }
     }
     ClassRegistry::flush();
     BcSite::flash();
     clearAllCache();
     return $result;
 }
 /**
  * 一括無効
  * 
  * @param array $ids
  * @return boolean
  * @access protected
  */
 function _batch_del($ids)
 {
     if ($ids) {
         foreach ($ids as $id) {
             $data = $this->Plugin->read(null, $id);
             $data['Plugin']['status'] = false;
             $this->Plugin->set($data);
             if ($this->Plugin->save()) {
                 $this->Plugin->saveDbLog('プラグイン「' . $data['Plugin']['title'] . '」 を 無効化しました。');
             }
         }
         clearAllCache();
     }
     return true;
 }
 /**
  * [ADMIN] 固定ページファイルを登録する
  *
  * @return void
  */
 public function admin_entry_page_files()
 {
     $this->_checkSubmitToken();
     $pagesPath = APP . 'View' . DS . 'Pages';
     $result = $this->Page->entryPageFiles($pagesPath);
     clearAllCache();
     $this->setMessage($result['all'] . ' ページ中 ' . $result['insert'] . ' ページの新規登録、 ' . $result['update'] . ' ページの更新に成功しました。');
     $this->redirect(array('controller' => 'tools', 'action' => 'index'));
 }
 /**
  * キャッシュファイルを全て削除する
  */
 public function admin_del_cache()
 {
     clearAllCache();
     $this->setMessage('サーバーキャッシュを削除しました。');
     $this->redirect($this->referer());
 }
 /**
  * DB構造を変更する
  *
  * @param string $version
  * @param tring $plugin
  * @param string $filterTable
  * @param string $filterType
  * @return boolean
  * @access	public
  */
 function loadSchema($version, $plugin = '', $filterTable = '', $filterType = '')
 {
     $path = $this->_getUpdatePath($version, $plugin);
     if (!$path) {
         return false;
     }
     if ($plugin) {
         $dbConfigName = 'plugin';
     } else {
         $dbConfigName = 'baser';
     }
     // アップデートの場合 drop field は実行しない
     $result = $this->Updater->loadSchema($dbConfigName, $path, $filterTable, $filterType, array('updater.php'), false);
     clearAllCache();
     return $result;
 }
Exemple #18
0
 /**
  * スキーマファイルを利用してデータベース構造を変更する
  *
  * @param	array	データベース設定名
  * @param	string	スキーマファイルのパス
  * @param	string	テーブル指定
  * @param	string	更新タイプ指定
  * @return 	boolean
  */
 public function loadSchema($dbConfigName, $path, $filterTable = '', $filterType = '', $excludePath = array(), $dropField = true)
 {
     // テーブルリストを取得
     $db = ConnectionManager::getDataSource($dbConfigName);
     $db->cacheSources = false;
     $listSources = $db->listSources();
     $prefix = $db->config['prefix'];
     $Folder = new Folder($path);
     $files = $Folder->read(true, true);
     $result = true;
     foreach ($files[1] as $file) {
         if (in_array($file, $excludePath)) {
             continue;
         }
         if (preg_match('/^(.*?)\\.php$/', $file, $matches)) {
             $type = 'create';
             $table = $matches[1];
             if (preg_match('/^create_(.*?)\\.php$/', $file, $matches)) {
                 $type = 'create';
                 $table = $matches[1];
                 if (in_array($prefix . $table, $listSources)) {
                     continue;
                 }
             } elseif (preg_match('/^alter_(.*?)\\.php$/', $file, $matches)) {
                 $type = 'alter';
                 $table = $matches[1];
                 if (!in_array($prefix . $table, $listSources)) {
                     continue;
                 }
             } elseif (preg_match('/^drop_(.*?)\\.php$/', $file, $matches)) {
                 $type = 'drop';
                 $table = $matches[1];
                 if (!in_array($prefix . $table, $listSources)) {
                     continue;
                 }
             } else {
                 if (in_array($prefix . $table, $listSources)) {
                     continue;
                 }
             }
             if ($filterTable && $filterTable != $table) {
                 continue;
             }
             if ($filterType && $filterType != $type) {
                 continue;
             }
             $tmpdir = TMP . 'schemas' . DS;
             copy($path . DS . $file, $tmpdir . $table . '.php');
             if (!$db->loadSchema(array('type' => $type, 'path' => $tmpdir, 'file' => $table . '.php', 'dropField' => $dropField))) {
                 $result = false;
             }
             @unlink($tmpdir . $table . '.php');
         }
     }
     clearAllCache();
     return $result;
 }
 /**
  * Step 5: 設定ファイルの生成
  * データベース設定ファイル[database.php]
  * インストールファイル[install.php]
  * 
  * @return void
  * @access public
  */
 public function step5()
 {
     $this->pageTitle = 'baserCMSのインストール完了!';
     Cache::config('default', array('engine' => 'File'));
     if (!BC_INSTALLED) {
         $installationData = $this->Session->read('Installation');
         $installationData['lastStep'] = true;
         checkTmpFolders();
         Configure::write('Cache.disable', false);
         // インストールファイルでセッションの保存方法を切り替える為、インストール情報をキャッシュに保存
         Cache::write('Installation', $installationData, 'default');
         // データベース設定を書き込む
         $this->BcManager->createDatabaseConfig($this->_readDbSetting());
         // インストールファイルを生成する
         $secritySalt = $this->Session->read('Installation.salt');
         $secrityCipherSeed = $this->Session->read('Installation.cipherSeed');
         $this->BcManager->createInstallFile($secritySalt, $secrityCipherSeed);
         //==================================================================
         // BcManagerComponent::createPageTemplates() を実行する際、
         // 固定ページでプラグインを利用している場合あり、プラグインがロードされていないとエラーになる為、
         // リダイレクト前にコアプラグインの有効化とテーマ保有のプラグインのインストールを完了させておく
         // =================================================================
         // データベースのデータを初期設定に更新
         $this->BcManager->executeDefaultUpdates($this->_readDbSetting(Cache::read('Installation', 'default')));
         // テーマを配置する
         $this->BcManager->deployTheme();
         $dbDataPattern = $this->Session->read('Installation.dbDataPattern');
         list($theme, $pattern) = explode('.', $dbDataPattern);
         loadSiteConfig();
         App::build(array('Plugin' => array_merge(array(BASER_THEMES . Configure::read('BcSite.theme') . DS . 'Plugin' . DS), App::path('Plugin'))));
         $themesPlugins = BcUtil::getCurrentThemesPlugins();
         if ($themesPlugins) {
             foreach ($themesPlugins as $plugin) {
                 $this->BcManager->installPlugin($plugin);
                 CakePlugin::load($plugin);
                 $this->BcManager->resetTables('plugin', $dbConfig = null, $plugin);
                 $this->BcManager->loadDefaultDataPattern('plugin', null, $pattern, $theme, $plugin);
             }
         }
         clearAllCache();
         if (function_exists('opcache_reset')) {
             opcache_reset();
         }
         $this->redirect('step5');
     } else {
         $installationData = Cache::read('Installation', 'default');
         if (empty($installationData['lastStep'])) {
             return;
         }
     }
     // ログイン
     $this->_login();
     // テーマに管理画面のアセットへのシンボリックリンクを作成する
     $this->BcManager->deployAdminAssets();
     // アップロード用初期フォルダを作成する
     $this->BcManager->createDefaultFiles();
     // エディタテンプレート用の画像を配置
     $this->BcManager->deployEditorTemplateImage();
     // Pagesファイルを生成する
     $this->BcManager->createPageTemplates();
     $this->Session->delete('InstallLastStep');
 }
Exemple #20
0
 /**
  * [ADMIN] 固定ページファイルを登録する
  *
  * @return void
  * @access public
  */
 public function admin_entry_page_files()
 {
     if (function_exists('ini_set')) {
         ini_set('max_execution_time', 0);
         ini_set('max_input_time', 0);
         ini_set('memory_limit ', '256M');
     }
     // 現在のテーマの固定ページファイルのパスを取得
     $pagesPath = getViewPath() . 'Pages';
     $result = $this->Page->entryPageFiles($pagesPath);
     clearAllCache();
     $this->setMessage($result['all'] . ' ページ中 ' . $result['insert'] . ' ページの新規登録、 ' . $result['update'] . ' ページの更新に成功しました。');
     $this->redirect(array('action' => 'index'));
 }