コード例 #1
0
ファイル: module_manager.php プロジェクト: cretzu89/EPESI
 /**
  * Installs module given as first parameter.
  * Additionally, this function calls upgrade to version given as second parameter.
  *
  * @param string $module module name or module class name - both / and _ separated.
  * @param integer $version module version
  * @return bool true if installation success, false otherwise
  */
 public static final function install($module, $version = null, $check = null, $include_common = true)
 {
     if ($check === null) {
         if (defined('UPDATING_EPESI')) {
             $check = false;
         } else {
             $check = true;
         }
     }
     $module_class_name = self::get_module_class_name($module);
     self::include_install($module_class_name);
     if (!isset(self::$modules_install[$module_class_name])) {
         return false;
     }
     $func_version = array(self::$modules_install[$module_class_name], 'version');
     if (is_callable($func_version)) {
         $inst_ver = call_user_func($func_version);
     } else {
         $inst_ver = 0;
     }
     if (is_array($inst_ver)) {
         $inst_ver = count($inst_ver);
     } else {
         $inst_ver = intval($inst_ver);
     }
     if (!isset($version)) {
         $version = $inst_ver - 1;
     } else {
         if ($inst_ver < $version) {
             print 'Module ' . '<b>' . $module_class_name . '</b>' . ' is too old. Please download newer version<br>';
             return false;
         }
     }
     if (self::is_installed($module_class_name) >= $version) {
         return true;
     }
     if (!self::exists($module_class_name, $version)) {
         return false;
     }
     //check dependecies
     if (!self::satisfy_dependencies($module_class_name, $version, $check)) {
         print '<b>' . $module_class_name . '</b>' . ': dependencies not satisfied.<br>';
         return false;
     }
     if (DB::is_mysql()) {
         DB::Execute('SET FOREIGN_KEY_CHECKS = 0');
     }
     //call install script and fill database
     if (!call_user_func(array(self::$modules_install[$module_class_name], 'install'))) {
         call_user_func(array(self::$modules_install[$module_class_name], 'uninstall'));
         self::remove_data_dir($module_class_name);
         print '<b>' . $module_class_name . '</b>' . ': uninstalled<br>';
         if (DB::is_mysql()) {
             DB::Execute('SET FOREIGN_KEY_CHECKS = 1');
         }
         return false;
     }
     if (DB::is_mysql()) {
         DB::Execute('SET FOREIGN_KEY_CHECKS = 1');
     }
     $ret = DB::Execute('insert into modules(name, version) values(%s,0)', $module_class_name);
     if (!$ret) {
         print '<b>' . $module_class_name . '</b>' . ' module installation failed: database<br>';
         return false;
     }
     self::register($module_class_name, $version, self::$modules);
     PatchUtil::mark_applied($module_class_name);
     if ($check) {
         self::create_load_priority_array();
     }
     print '<b>' . $module_class_name . '</b>' . ' module installed!<br>';
     if ($version != 0) {
         $up = self::upgrade($module_class_name, $version);
         if (!$up) {
             return false;
         }
     }
     if ($include_common) {
         self::include_common($module_class_name, $version);
         //    		self::create_common_cache();
     }
     if (file_exists(DATA_DIR . '/cache/common.php')) {
         unlink(DATA_DIR . '/cache/common.php');
     }
     Cache::clear();
     self::$processed_modules['install'][$module_class_name] = $version;
     return true;
 }