Esempio n. 1
0
 public function validate($data)
 {
     if (DEMO_MODE) {
         print 'You cannot modify installed modules in demo';
         return false;
     }
     @set_time_limit(0);
     $installed = array();
     $install = array();
     $uninstall = array();
     $anonymous_setup = false;
     foreach ($data as $k => $v) {
         ${$k} = $v;
     }
     foreach ($installed as $name => $new_version) {
         $old_version = ModuleManager::is_installed($name);
         if ($old_version == $new_version) {
             continue;
         }
         if ($old_version == -1 && $new_version >= 0) {
             $install[$name] = $new_version;
             continue;
         }
         if ($new_version == -2) {
             $uninstall[$name] = 1;
             $install[$name] = $old_version;
             continue;
         }
         if ($old_version >= 0 && $new_version == -1) {
             $uninstall[$name] = 1;
             continue;
         }
         if ($old_version < $new_version) {
             if (!ModuleManager::upgrade($name, $new_version)) {
                 return false;
             }
             continue;
         }
         if ($old_version > $new_version) {
             if (!ModuleManager::downgrade($name, $new_version)) {
                 return false;
             }
             continue;
         }
     }
     //uninstall
     $modules_prio_rev = array();
     foreach (ModuleManager::$modules as $k => $v) {
         $modules_prio_rev[] = $k;
     }
     $modules_prio_rev = array_reverse($modules_prio_rev);
     foreach ($modules_prio_rev as $k) {
         if (array_key_exists($k, $uninstall)) {
             if (!ModuleManager::uninstall($k)) {
                 return false;
             }
             if (count(ModuleManager::$modules) == 0) {
                 print 'No modules installed';
             }
         }
     }
     //install
     foreach ($install as $i => $v) {
         $post_install[$i] = $v;
         if (isset($uninstall[$i])) {
             if (!ModuleManager::install($i, $v, true, false)) {
                 return false;
             }
         } else {
             if (!ModuleManager::install($i, $v)) {
                 return false;
             }
         }
     }
     $processed = ModuleManager::get_processed_modules();
     $this->set_module_variable('post-install', $processed['install']);
     Base_ThemeCommon::create_cache();
     if (empty($post_install)) {
         Epesi::redirect();
     }
     return true;
 }