getDefaultDataPath() public static method

初期データのフォルダは アンダースコア区切り推奨
public static getDefaultDataPath ( string $plugin = null, string $theme = null, string $pattern = null ) : string
$plugin string プラグイン名
$theme string テーマ名
$pattern string 初期データの類型
return string Or false
Esempio n. 1
0
 protected function _applyTheme($theme)
 {
     $plugins = BcUtil::getCurrentThemesPlugins();
     // テーマ梱包のプラグインをアンインストール
     foreach ($plugins as $plugin) {
         $this->BcManager->uninstallPlugin($plugin);
     }
     $siteConfig['SiteConfig']['theme'] = $theme;
     $this->SiteConfig->saveKeyValue($siteConfig);
     clearViewCache();
     $info = array();
     $themePath = BASER_THEMES . $theme . DS;
     $Folder = new Folder($themePath . 'Plugin');
     $files = $Folder->read(true, true, false);
     if (!empty($files[0])) {
         $info = array_merge($info, array('このテーマは下記のプラグインを同梱しています。'));
         foreach ($files[0] as $file) {
             $info[] = '	・' . $file;
         }
     }
     Configure::write('BcSite.theme', $theme);
     $plugins = BcUtil::getCurrentThemesPlugins();
     App::build(array('Plugin' => array_merge(array(BASER_THEMES . $theme . DS . 'Plugin' . DS), App::path('Plugin'))));
     // テーマ梱包のプラグインをインストール
     foreach ($plugins as $plugin) {
         $this->BcManager->installPlugin($plugin);
     }
     $path = BcUtil::getDefaultDataPath('Core', $theme);
     if (strpos($path, '/theme/' . $theme . '/') !== false) {
         if ($info) {
             $info = array_merge($info, array(''));
         }
         $info = array_merge($info, array('このテーマは初期データを保有しています。', 'Webサイトにテーマに合ったデータを適用するには、初期データ読込を実行してください。'));
     }
     if (!$this->Page->createAllPageTemplate()) {
         $message = array('テーマ変更中にページテンプレートの生成に失敗しました。', '「Pages」フォルダに書き込み権限が付与されていない可能性があります。', '権限設定後、テーマの適用をやり直すか、表示できないページについて固定ページ管理より更新処理を行ってください。');
         if ($info) {
             $message = array_merge($message, array(''), $info);
         }
         $this->setMessage(implode('<br />', $message), true);
     } else {
         $message = array('テーマ「' . $theme . '」を適用しました。');
         if ($info) {
             $message = array_merge($message, array(''), $info);
         }
         $this->setMessage(implode('<br />', $message));
     }
     return true;
 }
Esempio n. 2
0
 /**
  * 初期データを読み込む
  * 
  * @param string $dbConfigKeyName
  * @param array $dbConfig
  * @param string $pattern
  * @param string $theme
  * @param string $plugin
  * @return boolean 
  */
 public function loadDefaultDataPattern($dbConfigKeyName, $dbConfig, $pattern, $theme = 'core', $plugin = 'core', $excludes = array())
 {
     $db = $this->_getDataSource($dbConfigKeyName, $dbConfig);
     $path = BcUtil::getDefaultDataPath($plugin, $theme, $pattern);
     if (!$path) {
         return false;
     }
     $corePath = BcUtil::getDefaultDataPath($plugin, 'core', 'default');
     $targetTables = array();
     if ($corePath) {
         $Folder = new Folder($corePath);
         $files = $Folder->read(true, true);
         $targetTables = $files[1];
     }
     $Folder = new Folder($path);
     $files = $Folder->read(true, true, true);
     if (!$targetTables) {
         $targetTables = $files[1];
     }
     $result = true;
     foreach ($targetTables as $targetTable) {
         $targetTable = basename($targetTable, '.csv');
         $loaded = false;
         if (!in_array($targetTable, $excludes)) {
             // 初期データ投入
             foreach ($files[1] as $file) {
                 if (!preg_match('/\\.csv$/', $file)) {
                     continue;
                 }
                 $table = basename($file, '.csv');
                 if ($table == $targetTable) {
                     if (!$db->loadCsv(array('path' => $file, 'encoding' => 'SJIS'))) {
                         $this->log($file . ' の読み込みに失敗。');
                         $result = false;
                     } else {
                         $loaded = true;
                         break;
                     }
                 }
             }
             // 存在しなかった場合は、コアのファイルを読み込む
             if (!$loaded && $corePath) {
                 if (!$db->loadCsv(array('path' => $corePath . DS . $targetTable . '.csv', 'encoding' => 'SJIS'))) {
                     $this->log($corePath . DS . $targetTable . ' の読み込みに失敗。');
                     $result = false;
                 }
             }
         }
     }
     App::uses('Page', 'Model');
     App::uses('PageCategory', 'Model');
     $Page = new Page();
     $Page->PageCategory = new PageCategory();
     // モバイルのID書き換え(ClearDB対策)
     $agents = array(1 => 'mobile', 2 => 'smartphone');
     foreach ($agents as $key => $agent) {
         $agentId = $Page->PageCategory->getAgentId($agent);
         if ($agentId != $key) {
             $pages = $Page->find('all', array('conditions' => array('Page.page_category_id' => $key), 'recursive' => -1));
             foreach ($pages as $page) {
                 $page['Page']['page_category_id'] = $agentId;
                 $Page->fileSave = false;
                 $Page->contentSaving = false;
                 $Page->set($page);
                 if (!$Page->save()) {
                     $result = false;
                 }
             }
         }
     }
     return $result;
 }
Esempio n. 3
0
 /**
  * データベースを初期化
  *
  * 既に存在するテーブルは上書きしない
  *
  * @param	array	データベース設定名
  * @param	string	プラグイン名
  * @return 	boolean
  */
 public function initDb($dbConfigName, $pluginName = '', $loadCsv = true, $filterTable = '', $filterType = '')
 {
     // 初期データフォルダを走査
     if (!$pluginName) {
         $path = BASER_CONFIGS . 'Schema';
     } else {
         $path = BcUtil::getSchemaPath($pluginName);
         if (!$path) {
             return true;
         }
     }
     if ($this->loadSchema($dbConfigName, $path, $filterTable, $filterType, array(), $dropField = false)) {
         if ($loadCsv) {
             $path = BcUtil::getDefaultDataPath($pluginName);
             if ($path) {
                 return $this->loadCsv($dbConfigName, $path);
             } else {
                 return true;
             }
         } else {
             return true;
         }
     } else {
         return false;
     }
 }
Esempio n. 4
0
 /**
  * 初期データのパスを取得する
  * 
  * 初期データのフォルダは アンダースコア区切り推奨
  * 
  * @param string $plugin プラグイン名
  * @param string $theme テーマ名
  * @param string $pattern 初期データの類型
  * @param string $expect 期待値
  * @dataProvider getDefaultDataPathDataProvider
  */
 public function testGetDefaultDataPath($plugin, $theme, $pattern, $expect)
 {
     $isset_ptt = isset($pattern) && isset($theme);
     $isset_plt = isset($plugin) && isset($theme);
     $isset_plptt = isset($plugin) && isset($pattern) && isset($theme);
     $Folder = new Folder();
     // 初期データ用のダミーディレクトリを作成
     if ($isset_ptt) {
         $Folder->create(BASER_THEMES . $theme . DS . 'Config' . DS . 'data' . DS . $pattern);
     }
     if ($isset_plt && !$isset_plptt) {
         $Folder->create(BASER_THEMES . $theme . DS . 'Config' . DS . 'data' . DS . 'default' . DS . $plugin);
     }
     if ($isset_plptt) {
         $Folder->create(BASER_THEMES . $theme . DS . 'Config' . DS . 'data' . DS . $pattern . DS . $plugin);
     }
     $result = BcUtil::getDefaultDataPath($plugin, $theme, $pattern);
     // 初期データ用のダミーディレクトリを削除
     if ($isset_ptt) {
         $Folder->delete(BASER_THEMES . $theme . DS . 'Config' . DS . 'data' . DS . $pattern);
     }
     if ($isset_plt && !$isset_plptt) {
         $Folder->delete(BASER_THEMES . $theme . DS . 'Config' . DS . 'data' . DS . 'default' . DS . $plugin);
     }
     if ($isset_plptt) {
         $Folder->delete(BASER_THEMES . $theme . DS . 'Config' . DS . 'data' . DS . $pattern . DS . $plugin);
     }
     $this->assertEquals($expect, $result, '初期データのパスを正しく取得できません');
 }
Esempio n. 5
0
 /**
  * データベースを初期化
  *
  * 既に存在するテーブルは上書きしない
  *
  * @param	array	データベース設定名
  * @param	string	プラグイン名
  * @return 	boolean
  */
 public function initDb($pluginName = '', $options = [])
 {
     $options = array_merge(['loadCsv' => true, 'filterTable' => '', 'filterType' => '', 'dbDataPattern' => ''], $options);
     // 初期データフォルダを走査
     if (!$pluginName) {
         $path = BASER_CONFIGS . 'Schema';
     } else {
         $path = BcUtil::getSchemaPath($pluginName);
         if (!$path) {
             return true;
         }
     }
     $dbDataPattern = null;
     if (!empty($options['dbDataPattern'])) {
         $dbDataPattern = $options['dbDataPattern'];
     } elseif (!empty($_SESSION['dbDataPattern'])) {
         $dbDataPattern = $_SESSION['dbDataPattern'];
         unset($_SESSION['dbDataPattern']);
     }
     if ($this->loadSchema('default', $path, $options['filterTable'], $options['filterType'], [], $dropField = false)) {
         if ($options['loadCsv']) {
             $theme = $pattern = null;
             if ($dbDataPattern) {
                 list($theme, $pattern) = explode('.', $dbDataPattern);
             }
             $path = BcUtil::getDefaultDataPath($pluginName, $theme, $pattern);
             if ($path) {
                 return $this->loadCsv('default', $path);
             } else {
                 return true;
             }
         } else {
             return true;
         }
     } else {
         return false;
     }
 }
 /**
  * 初期データチェックする
  *
  * @param string $dbConfigKeyName
  * @param array $dbConfig
  * @param string $pattern
  * @param string $theme
  * @param string $plugin
  * @return boolean
  */
 public function checkDefaultDataPattern($pattern, $theme = 'core')
 {
     $path = BcUtil::getDefaultDataPath('core', $theme, $pattern);
     if (!$path) {
         return false;
     }
     $corePath = BcUtil::getDefaultDataPath('core', 'core', 'default');
     $Folder = new Folder($corePath);
     $files = $Folder->read(true, true);
     $coreTables = $files[1];
     $Folder = new Folder($path);
     $files = $Folder->read(true, true);
     if (empty($files[1])) {
         return false;
     }
     // よく使う項目は、user_groups より生成するのでなくてもよい
     $excludes = ['favorites.csv'];
     $targetTables = $files[1];
     foreach ($coreTables as $coreTable) {
         if (in_array($coreTable, $excludes)) {
             continue;
         }
         if (!in_array($coreTable, $targetTables)) {
             return false;
         }
     }
     return true;
 }