Ignore:
Timestamp:
2012/09/19 19:21:32 (12 years ago)
Author:
h_yoshimoto
Message:

refs #1944 プラグイン管理のリファクタリング

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_12-dev/data/class/pages/admin/ownersstore/LC_Page_Admin_OwnersStore.php

    r22033 r22034  
    8282                $this->arrErr = $this->checkUploadFile($file_key); 
    8383                if ($this->isError($this->arrErr) === false) { 
    84                     $upload_file = $_FILES[$file_key]; 
    85                     $upload_file_file_name = $upload_file['name']; 
     84                    $archive_file_name = $_FILES[$file_key]['name']; 
    8685                    // インストール処理. 
    87                     $this->arrErr = $this->installPlugin($upload_file_file_name, 'plugin_file'); 
     86                    $this->arrErr = $this->installPlugin($archive_file_name, 'plugin_file'); 
    8887                    if ($this->isError($this->arrErr) === false) { 
    8988                        // コンパイルファイルのクリア処理 
     
    112111            // 有効化 
    113112            case 'enable': 
    114  
    115113                // エラーチェック 
    116114                $this->arrErr = $objFormParam->checkError(); 
     
    315313     */ 
    316314    function getHtmlPluginDir($plugin_code) { 
    317         $plugin_dir_path = PLUGIN_HTML_REALDIR . $plugin_code . '/'; 
    318         return $plugin_dir_path; 
     315        $plugin_html_dir_path = PLUGIN_HTML_REALDIR . $plugin_code . '/'; 
     316        return $plugin_html_dir_path; 
    319317    } 
    320318 
     
    323321     * 
    324322     * @param string $plugin_code プラグインコード 
     323     * @param string $plugin_class プラグインクラス名 
    325324     * @return string $plugin_file_path クラスファイルのパス. 
    326325     */ 
    327     function getPluginFilePath($plugin_code) { 
    328         $plugin_file_path = $this->getPluginDir($plugin_code) . $plugin_code . '.php'; 
     326    function getPluginFilePath($plugin_code , $plugin_class) { 
     327        $plugin_file_path = $this->getPluginDir($plugin_code) . $plugin_class . '.php'; 
    329328        return $plugin_file_path; 
    330329    } 
     
    333332     * プラグインをインストールします. 
    334333     * 
    335      * @param string $plugin_code プラグインコード. 
     334     * @param string $archive_file_name アーカイブファイル名. 
    336335     * @param string $key キー. 
    337336     * @return array エラー情報を格納した連想配列. 
    338337     */ 
    339     function installPlugin($upload_file_file_name, $key) { 
    340         // インストール前に不要なファイルを消しておきます. 
    341         SC_Helper_FileManager_Ex::deleteFile(DOWNLOADS_TEMP_PLUGIN_INSTALL_DIR, false); 
    342  
     338    function installPlugin($archive_file_name, $key) { 
     339        // 一時展開ディレクトリにファイルがある場合は事前に削除. 
     340        $arrFileHash = SC_Helper_FileManager_Ex::sfGetFileList(DOWNLOADS_TEMP_PLUGIN_INSTALL_DIR); 
     341        if(count($arrFileHash) > 0) { 
     342            SC_Helper_FileManager_Ex::deleteFile(DOWNLOADS_TEMP_PLUGIN_INSTALL_DIR, false); 
     343        } 
     344         
    343345        //シンタックスエラーがあるtar.gzをアップ後、削除するとたまにディレクトリが消えるので追加 
    344346        $this->makeDir(PLUGIN_UPLOAD_REALDIR); 
     
    351353        } 
    352354        // ファイルをチェックし一時展開用ディレクトリに展開します. 
    353         $arrErr = $this->unpackPluginFile($upload_file_file_name, DOWNLOADS_TEMP_PLUGIN_INSTALL_DIR, $key); 
     355        $arrErr = $this->unpackPluginFile($archive_file_name, DOWNLOADS_TEMP_PLUGIN_INSTALL_DIR, $key); 
    354356        if ($this->isError($arrErr) === true) { 
    355357            return $arrErr; 
     
    372374        } 
    373375 
    374         // プラグインコード 
    375         $plugin_code = $arrPluginInfo['PLUGIN_CODE']; 
    376         // プラグイン名 
    377         $plugin_name = $arrPluginInfo['PLUGIN_NAME']; 
    378  
    379376        // 既にインストールされていないかを判定. 
    380         if ($this->isInstalledPlugin($plugin_code) === true) { 
     377        if ($this->isInstalledPlugin($arrPluginInfo['PLUGIN_CODE']) === true) { 
    381378            $this->rollBack(DOWNLOADS_TEMP_PLUGIN_INSTALL_DIR); 
    382             $arrErr['plugin_file'] = '※ ' . $plugin_name . 'は既にインストールされています。<br/>'; 
     379            $arrErr['plugin_file'] = '※ ' . $arrPluginInfo['PLUGIN_NAME'] . 'は既にインストールされています。<br/>'; 
    383380            return $arrErr; 
    384381        } 
     
    392389 
    393390        // プラグイン保存ディレクトリを作成し、一時展開用ディレクトリから移動します. 
    394         $plugin_dir_path = PLUGIN_UPLOAD_REALDIR . $plugin_code . '/'; 
     391        $plugin_dir_path = $this->getPluginDir($arrPluginInfo['PLUGIN_CODE']); 
    395392        $this->makeDir($plugin_dir_path); 
    396393        SC_Utils_Ex::copyDirectory(DOWNLOADS_TEMP_PLUGIN_INSTALL_DIR, $plugin_dir_path); 
    397394 
    398395        // プラグイン情報を取得 
    399         $plugin = SC_Plugin_Util_Ex::getPluginByPluginCode($plugin_code); 
     396        $plugin = SC_Plugin_Util_Ex::getPluginByPluginCode($arrPluginInfo['PLUGIN_CODE']); 
    400397 
    401398        // クラスファイルを読み込み. 
    402         $plugin_class_file_path = $plugin_dir_path . $plugin['class_name'] . '.php'; 
     399        $plugin_class_file_path = $this->getPluginFilePath($plugin['plugin_code'], $plugin['class_name']); 
    403400        $arrErr = $this->requirePluginFile($plugin_class_file_path, $key); 
    404401        if ($this->isError($arrErr) === true) { 
     
    407404        } 
    408405        // プラグインhtmlディレクトリ作成 
    409         $plugin_html_dir = PLUGIN_HTML_REALDIR . $plugin_code; 
    410         $this->makeDir($plugin_html_dir); 
     406        $plugin_html_dir_path = $this->getHtmlPluginDir($plugin['plugin_code']); 
     407        $this->makeDir($plugin_html_dir_path); 
    411408 
    412409        $arrErr = $this->execPlugin($plugin, $plugin['class_name'], 'install'); 
    413410        if ($this->isError($arrErr) === true) { 
    414             $this->rollBack(DOWNLOADS_TEMP_PLUGIN_INSTALL_DIR, $plugin['plugin_id'], $plugin_html_dir); 
     411            $this->rollBack(DOWNLOADS_TEMP_PLUGIN_INSTALL_DIR, $plugin['plugin_id'], $plugin_html_dir_path); 
    415412            return $arrErr; 
    416413        } 
     
    427424     * @param string $temp_dir インストール・アップデート時の一時展開用ディレクトリのパス. 
    428425     * @param string $plugin_id プラグインID. 
    429      * @param string $plugin_html_dir プラグイン毎に生成されるhtmlディレクトリのパス. 
    430      */ 
    431     function rollBack($temp_dir, $plugin_id = '', $plugin_html_dir ='') { 
     426     * @param string $plugin_html_dir_path プラグイン毎に生成されるhtmlディレクトリのパス. 
     427     */ 
     428    function rollBack($temp_dir, $plugin_id = '', $plugin_html_dir_path ='') { 
    432429        // 一時ディレクトリを削除. 
    433430        SC_Helper_FileManager_Ex::deleteFile($temp_dir, false); 
     
    437434        } 
    438435        // htmlディレクトリを削除 
    439         if (empty($plugin_html_dir) === false) { 
    440             SC_Helper_FileManager_Ex::deleteFile($plugin_html_dir, true); 
     436        if (empty($plugin_html_dir_path) === false) { 
     437            SC_Helper_FileManager_Ex::deleteFile($plugin_html_dir_path, true); 
    441438        } 
    442439    } 
     
    483480     * 
    484481     * @param ReflectionClass $objReflection リフレクションオブジェクト 
     482     * @param string $dir_path チェックするプラグインディレクトリ 
    485483     * @return array エラー情報を格納した連想配列. 
    486484     */ 
    487     function checkPluginConstants(ReflectionClass $objReflection, $unpack_dir) { 
     485    function checkPluginConstants(ReflectionClass $objReflection, $dir_path) { 
    488486        $arrErr = array(); 
    489487        // プラグイン情報を取得 
     
    502500            return $arrErr; 
    503501        } 
    504         $class_path = $unpack_dir . $arrPluginInfo['CLASS_NAME'] . '.php'; 
    505         if (file_exists($class_path) === false) { 
     502        $plugin_class_file_path = $dir_path . $arrPluginInfo['CLASS_NAME'] . '.php'; 
     503        if (file_exists($plugin_class_file_path) === false) { 
    506504            $arrErr['plugin_file'] = '※ CLASS_NAMEが正しく定義されていません。<br/>'; 
    507505            return $arrErr; 
     
    550548     * プラグインをアップデートします. 
    551549     * 
    552      * @param string $target_plugin アップデートするプラグインコード. 
     550     * @param array $target_plugin アップデートするプラグイン情報の配列. 
    553551     * @param string $upload_file_name アップロードファイル名. 
    554552     * @return array エラー情報を格納した連想配列. 
     
    598596     * 
    599597     * @param string $unpack_file_name 解凍ファイル名 
    600      * @param string $unpack_dir 解凍先ディレクトリ 
     598     * @param string $unpack_dir_path 解凍先ディレクトリパス 
    601599     * @param string $file_key ファイルキー 
    602600     * @return array エラー情報を格納した連想配列. 
    603601     */ 
    604     function unpackPluginFile($unpack_file_name, $unpack_dir, $file_key) { 
     602    function unpackPluginFile($unpack_file_name, $unpack_dir_path, $file_key) { 
    605603        $arrErr = array(); 
    606604        // 解凍ディレクトリディレクトリを作成し、一時ディレクトリからファイルを移動 
    607         $objUpFile = new SC_UploadFile_Ex(PLUGIN_TEMP_REALDIR, $unpack_dir); 
     605        $objUpFile = new SC_UploadFile_Ex(PLUGIN_TEMP_REALDIR, $unpack_dir_path); 
    608606        $this->initUploadFile($objUpFile, $file_key); 
    609607        $arrErr = $objUpFile->makeTempFile($file_key, false); 
     
    619617        $objUpFile->moveTempFile(); 
    620618        // 解凍 
    621         $update_plugin_file_path = $unpack_dir . $unpack_file_name; 
    622         if (!$this->unpackPluginArchive($update_plugin_file_path)) { 
     619        $unpack_file_path = $unpack_dir_path . $unpack_file_name; 
     620        if (!$this->unpackPluginArchive($unpack_file_path)) { 
    623621            $arrErr['plugin_file'] = '※ 解凍に失敗しました。<br/>'; 
    624622            return $arrErr; 
     
    636634        $arrErr = array(); 
    637635        // プラグインファイルを読み込みます. 
    638         $plugin_class_file_path = PLUGIN_UPLOAD_REALDIR . $plugin['plugin_code'] . '/' . $plugin['class_name'] . '.php'; 
     636        $plugin_class_file_path = $this->getPluginFilePath($plugin['plugin_code'], $plugin['class_name']); 
    639637        $arrErr = $this->requirePluginFile($plugin_class_file_path, 'plugin_error'); 
    640638        if ($this->isError($arrErr) === true) { 
     
    670668        $arrErr = array(); 
    671669        // クラスファイルを読み込み. 
    672         $plugin_class_file_path = PLUGIN_UPLOAD_REALDIR . $plugin['plugin_code'] . '/' . $plugin['class_name'] . '.php'; 
     670        $plugin_class_file_path = $this->getPluginFilePath($plugin['plugin_code'], $plugin['class_name']); 
    673671        $arrErr = $this->requirePluginFile($plugin_class_file_path, 'plugin_error'); 
    674672        if ($this->isError($arrErr) === true) { 
     
    695693        $arrErr = array(); 
    696694        // クラスファイルを読み込み. 
    697         $plugin_class_file_path = PLUGIN_UPLOAD_REALDIR . $plugin['plugin_code'] . '/' . $plugin['class_name'] . '.php'; 
     695        $plugin_class_file_path =$this->getPluginFilePath($plugin['plugin_code'], $plugin['class_name']); 
    698696        $arrErr = $this->requirePluginFile($plugin_class_file_path, 'plugin_error'); 
    699697        if ($this->isError($arrErr) === true) { 
Note: See TracChangeset for help on using the changeset viewer.