Ignore:
Timestamp:
2013/03/10 00:23:31 (11 years ago)
Author:
Yammy
Message:

プラグインの競合チェック関数を Utils に移行

refs #2179

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/camp/camp-2_13-plugin/data/class/plugin/SC_Plugin_Util.php

    r22641 r22663  
    152152    } 
    153153 
    154     function getPluginHookPointList() 
     154    /** 
     155     *  プラグインフックポイントを取得する. 
     156     * 
     157     * @param integer $use_type 1=有効のみ 2=無効のみ 3=全て 
     158     * @return array フックポイントの一覧 
     159     */ 
     160    function getPluginHookPointList($use_type = 3) 
    155161    { 
    156162        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     
    158164        $cols = 'dtb_plugin_hookpoint.*, dtb_plugin.priority, dtb_plugin.plugin_name'; 
    159165        $from = 'dtb_plugin_hookpoint LEFT JOIN dtb_plugin USING(plugin_id)'; 
    160         $where = 'enable = 1'; 
    161         $arrRet = $objQuery->select($cols, $from, $where); 
    162         $arrList = array(); 
    163         foreach ($arrRet AS $key=>$val) { 
    164             $arrList[$val['hook_point']][$val['plugin_id']] = $val; 
    165         } 
    166         return $arrList; 
     166        switch ($use_type) { 
     167            case 1: 
     168                $where = 'enable = 1 AND use_flg = true'; 
     169            break; 
     170 
     171            case 2: 
     172                $where = 'enable = 1 AND use_flg = false'; 
     173            break; 
     174 
     175            case 3: 
     176            default: 
     177                $where = ''; 
     178            break; 
     179        } 
     180        return $objQuery->select($cols, $from, $where); 
     181        //$arrList = array(); 
     182        //foreach ($arrRet AS $key=>$val) { 
     183        //    $arrList[$val['hook_point']][$val['plugin_id']] = $val; 
     184        //} 
     185        //return $arrList; 
    167186    } 
    168187 
     
    205224        $objQuery->update('dtb_plugin_hookpoint', $sqlval, 'plugin_hookpoint_id = ?', array($plugin_hookpoint_id)); 
    206225    } 
     226 
     227    /** 
     228     * フックポイントで衝突する可能性のあるプラグインを判定.メッセージを返します. 
     229     * 
     230     * @param int $plugin_id プラグインID 
     231     * @return string $conflict_alert_message メッセージ 
     232     */ 
     233    function checkConflictPlugin($plugin_id = '') 
     234    { 
     235        // フックポイントを取得します. 
     236        if ($plugin_id > 0) { 
     237            $hookPoints = SC_Plugin_Util::getPluginHookPoint($plugin_id); 
     238        } else { 
     239            $hookPoints = SC_Plugin_Util::getPluginHookPointList(1); 
     240        } 
     241 
     242        $conflict_alert_message = ''; 
     243        $arrConflictPluginName = array(); 
     244        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     245        foreach ($hookPoints as $hookPoint) { 
     246            // 競合するプラグインを取得する, 
     247            $table = 'dtb_plugin_hookpoint AS T1 LEFT JOIN dtb_plugin AS T2 ON T1.plugin_id = T2.plugin_id'; 
     248            $where = 'T1.hook_point = ? AND NOT T1.plugin_id = ? AND T2.enable = ' . PLUGIN_ENABLE_TRUE; 
     249            $objQuery->setGroupBy('T1.plugin_id, T2.plugin_name'); 
     250            $conflictPlugins = $objQuery->select('T1.plugin_id, T2.plugin_name', $table, $where, array($hookPoint['hook_point'], $hookPoint['plugin_id'])); 
     251 
     252            // プラグイン名重複を削除する為、専用の配列に格納し直す. 
     253            foreach ($conflictPlugins as $conflictPlugin) { 
     254                // プラグイン名が見つからなければ配列に格納 
     255                if (!in_array($conflictPlugin['plugin_name'], $arrConflictPluginName)) { 
     256                    $arrConflictPluginName[] = $conflictPlugin['plugin_name']; 
     257                } 
     258            } 
     259        } 
     260        // メッセージをセットします. 
     261        foreach ($arrConflictPluginName as $conflictPluginName) { 
     262            $conflict_alert_message .= '* ' .  $conflictPluginName . 'と競合する可能性があります。<br/>'; 
     263        } 
     264        return $conflict_alert_message; 
     265    } 
     266 
    207267} 
Note: See TracChangeset for help on using the changeset viewer.