Exemple #1
0
 /**
  * プラグイン情報を取得する
  *
  * @param array $datas プラグインのデータ配列
  * @param string $file プラグインファイルのパス
  * @return array
  */
 public function getPluginInfo($datas, $file)
 {
     $plugin = basename($file);
     $pluginData = array();
     $exists = false;
     foreach ($datas as $data) {
         if ($plugin == $data['Plugin']['name']) {
             $pluginData = $data;
             $exists = true;
             break;
         }
     }
     // プラグインのバージョンを取得
     $corePlugins = Configure::read('BcApp.corePlugins');
     $core = false;
     if (in_array($plugin, $corePlugins)) {
         $core = true;
         $version = getVersion();
     } else {
         $version = getVersion($plugin);
     }
     // 設定ファイル読み込み
     $title = $description = $author = $url = $adminLink = '';
     // TODO 互換性のため古いパスも対応
     $oldAppConfigPath = $file . DS . 'Config' . DS . 'config.php';
     $appConfigPath = $file . DS . 'config.php';
     if (!file_exists($appConfigPath)) {
         $appConfigPath = $oldAppConfigPath;
     }
     if (file_exists($appConfigPath)) {
         include $appConfigPath;
     } elseif (file_exists($oldAppConfigPath)) {
         include $oldAppConfigPath;
     }
     if (isset($title)) {
         $pluginData['Plugin']['title'] = $title;
     }
     if (isset($description)) {
         $pluginData['Plugin']['description'] = $description;
     }
     if (isset($author)) {
         $pluginData['Plugin']['author'] = $author;
     }
     if (isset($url)) {
         $pluginData['Plugin']['url'] = $url;
     }
     $pluginData['Plugin']['update'] = false;
     $pluginData['Plugin']['old_version'] = false;
     $pluginData['Plugin']['core'] = $core;
     if ($exists) {
         if (isset($adminLink)) {
             $pluginData['Plugin']['admin_link'] = $adminLink;
         }
         // バージョンにBaserから始まるプラグイン名が入っている場合は古いバージョン
         if (!$pluginData['Plugin']['version'] && preg_match('/^Baser[a-zA-Z]+\\s([0-9\\.]+)$/', $version, $matches)) {
             $pluginData['Plugin']['version'] = $matches[1];
             $pluginData['Plugin']['old_version'] = true;
         } elseif (verpoint($pluginData['Plugin']['version']) < verpoint($version) && !in_array($pluginData['Plugin']['name'], Configure::read('BcApp.corePlugins'))) {
             $pluginData['Plugin']['update'] = true;
         }
         $pluginData['Plugin']['registered'] = true;
     } else {
         // バージョンにBaserから始まるプラグイン名が入っている場合は古いバージョン
         if (preg_match('/^Baser[a-zA-Z]+\\s([0-9\\.]+)$/', $version, $matches)) {
             $version = $matches[1];
             $pluginData['Plugin']['old_version'] = true;
         }
         $pluginData['Plugin']['id'] = '';
         $pluginData['Plugin']['name'] = $plugin;
         $pluginData['Plugin']['created'] = '';
         $pluginData['Plugin']['version'] = $version;
         $pluginData['Plugin']['status'] = false;
         $pluginData['Plugin']['modified'] = '';
         $pluginData['Plugin']['admin_link'] = '';
         $pluginData['Plugin']['registered'] = false;
     }
     return $pluginData;
 }
 /**
  * バージョンを特定する一意の数値を取得する
  */
 public function testVerpoint()
 {
     $version = 'baserCMS 3.0.6.1';
     $result = verpoint($version);
     $this->assertEquals(3000006001, $result, '正しくバージョンを特定する一意の数値を取得できません');
     $version = 'baserCMS 3.0.6.1 beta';
     $result = verpoint($version);
     $this->assertEquals(false, $result, '正しくバージョンを特定する一意の数値を取得できません');
 }
 /**
  * アップデータのパスを取得する
  *
  * @param string $sourceVersion
  * @param string $targetVersion
  * @param string $plugin
  * @return array $updates
  * @access protected
  */
 function _getUpdaters($sourceVersion, $targetVersion, $plugin = '')
 {
     $sourceVerPoint = verpoint($sourceVersion);
     $targetVerPoint = verpoint($targetVersion);
     if ($sourceVerPoint === false || $targetVerPoint === false) {
         return false;
     }
     if (!$plugin) {
         $path = BASER_CONFIGS . 'update' . DS;
         if (!is_dir($path)) {
             return array();
         }
     } else {
         $appPath = APP . 'plugins' . DS . $plugin . DS . 'config' . DS . 'update' . DS;
         $baserPath = BASER_PLUGINS . $plugin . DS . 'config' . DS . 'update' . DS;
         if (is_dir($appPath)) {
             $path = $appPath;
         } elseif (is_dir($baserPath)) {
             $path = $baserPath;
         } else {
             return array();
         }
     }
     $folder = new Folder($path);
     $files = $folder->read(true, true);
     $updaters = array();
     $updateVerPoints = array();
     if (!empty($files[0])) {
         foreach ($files[0] as $folder) {
             $updateVersion = $folder;
             $updateVerPoints[$updateVersion] = verpoint($updateVersion);
         }
         asort($updateVerPoints);
         foreach ($updateVerPoints as $key => $updateVerPoint) {
             if ($updateVerPoint > $sourceVerPoint && $updateVerPoint <= $targetVerPoint || $key == 'test') {
                 if (file_exists($path . DS . $key . DS . 'updater.php')) {
                     $updaters[$key] = $updateVerPoint;
                 }
             }
         }
     }
     return $updaters;
 }
 /**
  * アップデータのパスを取得する
  *
  * @param string $sourceVersion
  * @param string $targetVersion
  * @param string $plugin
  * @return array $updates
  * @access protected
  */
 protected function _getScriptMessages($plugin = '')
 {
     $targetVerPoint = verpoint(preg_replace('/-beta$/', '', $this->getBaserVersion($plugin)));
     $sourceVerPoint = verpoint(preg_replace('/-beta$/', '', $this->getSiteVersion($plugin)));
     if ($sourceVerPoint === false || $targetVerPoint === false) {
         return array();
     }
     if (!$plugin) {
         $path = BASER_CONFIGS . 'update' . DS;
         if (!is_dir($path)) {
             return array();
         }
     } else {
         $paths = App::path('Plugin');
         foreach ($paths as $path) {
             $path .= $plugin . DS . 'Config' . DS . 'update' . DS;
             if (is_dir($path)) {
                 break;
             }
             $path = null;
         }
         if (!$path) {
             return array();
         }
     }
     $folder = new Folder($path);
     $files = $folder->read(true, true);
     $messages = array();
     $updateVerPoints = array();
     if (!empty($files[0])) {
         foreach ($files[0] as $folder) {
             $updateVersion = $folder;
             $updateVerPoints[$updateVersion] = verpoint($updateVersion);
         }
         asort($updateVerPoints);
         foreach ($updateVerPoints as $key => $updateVerPoint) {
             $updateMessage = '';
             if ($updateVerPoint > $sourceVerPoint && $updateVerPoint <= $targetVerPoint || $key == 'test') {
                 if (file_exists($path . DS . $key . DS . 'config.php')) {
                     include $path . DS . $key . DS . 'config.php';
                     if ($updateMessage) {
                         $messages[$key] = $updateMessage;
                     }
                 }
             }
         }
     }
     return $messages;
 }
Exemple #5
0
 /**
  * アップデート処理が必要かチェックする
  * TODO 別のヘルパに移動する
  * @return boolean
  * @access public
  */
 function checkUpdate()
 {
     $baserVerpoint = verpoint($this->_view->viewVars['baserVersion']);
     if (isset($this->siteConfig['version'])) {
         $siteVerpoint = verpoint($this->siteConfig['version']);
     } else {
         $siteVerpoint = 0;
     }
     return $baserVerpoint > $siteVerpoint;
 }
Exemple #6
0
 /**
  * アップデート処理が必要かチェックする
  * 
  * @return bool アップデートが必要な場合は true を返す
  * @todo 別のヘルパに移動する
  */
 public function checkUpdate()
 {
     $baserVerpoint = verpoint($this->_View->get('baserVersion'));
     if ($baserVerpoint === false) {
         return false;
     }
     if (!isset($this->siteConfig['version'])) {
         return $baserVerpoint > 0;
     }
     $siteVerpoint = verpoint($this->siteConfig['version']);
     return $siteVerpoint !== false && $baserVerpoint > $siteVerpoint;
 }
Exemple #7
0
/**
 * スキーマの読み込み
 */
if ($this->loadSchema('1.2.11', 'uploader', 'uploader_configs')) {
    $this->setMessage('uploader_configs テーブルの作成に成功しました。');
} else {
    $this->setMessage('uploader_configs テーブルの作成に失敗しました。', true);
}
if ($this->loadSchema('1.2.11', 'uploader', 'uploader_categories')) {
    $this->setMessage('uploader_categories テーブルの作成に成功しました。');
} else {
    $this->setMessage('uploader_categories テーブルの作成に失敗しました。', true);
}
/**
 * 初期データ読み込み
 * baserCMS 1.6.10 以下の場合、$this->loadCsv にバグがある為処理を分けた
 */
if (verpoint($this->getBaserVersion()) >= 1006011000) {
    if ($this->loadCsv('1.2.11', 'uploader')) {
        $this->setMessage('uploader_configs テーブルの初期データ作成に成功しました。');
    } else {
        $this->setMessage('uploader_configs テーブルの初期データ作成に失敗しました。', true);
    }
} else {
    $path = $this->_getUpdatePath('1.2.11', 'uploader');
    if ($this->Updater->loadCsv('plugin', $path)) {
        $this->setMessage('uploader_configs テーブルの初期データ作成に成功しました。');
    } else {
        $this->setMessage('uploader_configs テーブルの初期データ作成に失敗しました。', true);
    }
}
Exemple #8
0
 /**
  * プラグインの一覧を表示する
  *
  * @return void
  * @access public
  */
 function admin_index()
 {
     $listDatas = $this->Plugin->find('all');
     if (!$listDatas) {
         $listDatas = array();
     }
     // プラグインフォルダーのチェックを行う。
     // データベースに登録されていないプラグインをリストアップ
     $pluginFolder = new Folder(APP . 'plugins' . DS);
     $plugins = $pluginFolder->read(true, true);
     $unRegistereds = array();
     $registereds = array();
     foreach ($plugins[0] as $plugin) {
         $exists = false;
         $pluginData = array();
         foreach ($listDatas as $data) {
             if ($plugin == $data['Plugin']['name']) {
                 $pluginData = $data;
                 $exists = true;
                 break;
             }
         }
         // プラグインのバージョンを取得
         $version = $this->getBaserVersion($plugin);
         // 設定ファイル読み込み
         $title = $description = $author = $url = $adminLink = '';
         $appConfigPath = APP . DS . 'plugins' . DS . $plugin . DS . 'config' . DS . 'config.php';
         $baserConfigPath = BASER_PLUGINS . $plugin . DS . 'config' . DS . 'config.php';
         if (file_exists($appConfigPath)) {
             include $appConfigPath;
         } elseif (file_exists($baserConfigPath)) {
             include $baserConfigPath;
         }
         if (isset($title)) {
             $pluginData['Plugin']['title'] = $title;
         }
         if (isset($description)) {
             $pluginData['Plugin']['description'] = $description;
         }
         if (isset($author)) {
             $pluginData['Plugin']['author'] = $author;
         }
         if (isset($url)) {
             $pluginData['Plugin']['url'] = $url;
         }
         $pluginData['Plugin']['update'] = false;
         $pluginData['Plugin']['old_version'] = false;
         if ($exists) {
             if (isset($adminLink)) {
                 $pluginData['Plugin']['admin_link'] = $adminLink;
             }
             // バージョンにBaserから始まるプラグイン名が入っている場合は古いバージョン
             if (!$pluginData['Plugin']['version'] && preg_match('/^Baser[a-zA-Z]+\\s([0-9\\.]+)$/', $version, $matches)) {
                 $pluginData['Plugin']['version'] = $matches[1];
                 $pluginData['Plugin']['old_version'] = true;
             } elseif (verpoint($pluginData['Plugin']['version']) < verpoint($version) && !in_array($pluginData['Plugin']['name'], array('blog', 'feed', 'mail'))) {
                 $pluginData['Plugin']['update'] = true;
             }
             $registereds[] = $pluginData;
         } else {
             // バージョンにBaserから始まるプラグイン名が入っている場合は古いバージョン
             if (preg_match('/^Baser[a-zA-Z]+\\s([0-9\\.]+)$/', $version, $matches)) {
                 $version = $matches[1];
                 $pluginData['Plugin']['old_version'] = true;
             }
             $pluginData['Plugin']['id'] = '';
             $pluginData['Plugin']['name'] = $plugin;
             $pluginData['Plugin']['created'] = '';
             $pluginData['Plugin']['version'] = $version;
             $pluginData['Plugin']['status'] = false;
             $pluginData['Plugin']['modified'] = '';
             $pluginData['Plugin']['admin_link'] = '';
             $unRegistereds[] = $pluginData;
         }
     }
     $listDatas = array_merge($registereds, $unRegistereds);
     // 表示設定
     $this->set('listDatas', $listDatas);
     $this->subMenuElements = array('site_configs', 'plugins');
     $this->pageTitle = 'プラグイン一覧';
 }