Example #1
0
 protected static function _updateSite($site_module_file, $verbose_errors = true)
 {
     $config = I2CE::getConfig();
     $status = I2CE::allSystemsAreGoGo($site_module_file, true);
     I2CE::raiseError("Updating site for {$site_module_file}: {$status}");
     if (substr($status, 0, 11) == 'in_progress') {
         if (array_key_exists('HTTP_HOST', $_SERVER)) {
             if (array_key_exists('restart', $_GET)) {
                 $status = 'restart_' . substr($status, 12);
             }
         } else {
             if (I2CE::getRuntimeVariable('force-restart')) {
                 $status = 'restart_' . substr($status, 12);
             }
         }
     }
     switch ($status) {
         case 'done':
             return true;
         case 'no_site':
             I2CE::raiseError("Cannot determine the site");
             return false;
         case 'restart_install':
         case 'needs_install':
             $config->__set("/config/site/installation", 'in_progress_install');
             if (!self::install($site_module_file, substr($status, 0, 7) == 'restart', $verbose_errors)) {
                 I2CE::raiseError("Unseting at " . $config->getPath());
                 if (isset($config->config) && isset($config->config->site) && isset($config->config->site->installation)) {
                     unset($config->config->site->installation);
                 }
                 I2CE::raiseError("Installation of the site failed", E_USER_ERROR);
                 return false;
             }
             return !I2CE::hasWarnings();
         case 'restart_reinstall':
         case 'needs_reinstall':
             $config->__set("/config/site/installation", 'in_progress_reinstall');
             if (!self::reinstall($site_module_file, substr($status, 0, 7) == 'restart', $verbose_errors)) {
                 I2CE::raiseError("Reintiaizliation of site to new file {$site_module_file} failed", E_USER_ERROR);
                 return false;
             }
             return !I2CE::hasWarnings();
         case 'restart_reenable':
         case 'needs_reenable':
             $config->__set("/config/site/installation", 'in_progress_reenable');
             I2CE::setupFileSearch(array("CLASSES" => "./", 'MODULES' => array(dirname($site_module_file), dirname(dirname(__FILE__)))), true);
             if ($config->setIfIsSet($site_module, '/config/site/module')) {
                 I2CE::raiseError("Somehow the site module {$site_module} was disabled.  Attempting to enable");
                 $mod_factory = I2CE_ModuleFactory::instance();
                 $mod_factory->resetStoredLoadedPaths();
                 //$mod_factory->loadPaths(null,'CLASSES'); //make sure all of our classes are loaded.
                 //somehow the site module got disabled.  this could happen, for example, if the paths got screwed up.  lets try and correct things
                 if (!self::_updateModules($site_module)) {
                     I2CE::raiseError("Renabling failed for {$site_module} ", E_USER_ERROR);
                     return false;
                 }
                 return !I2CE::hasWarnings();
             }
             I2CE::raiseError("Lost the site module");
             return false;
         case 'restart_upgrade':
         case 'needs_upgrade':
             $config->__set("/config/site/installation", 'in_progress_upgrade');
             $mod_factory = I2CE_ModuleFactory::instance();
             $mod_factory->resetStoredLoadedPaths();
             //$mod_factory->loadPaths(null,'CLASSES'); //make sure all of our classes are loaded.
             I2CE::setupFileSearch(array("CLASSES" => "./", 'MODULES' => array(dirname($site_module_file), dirname(dirname(__FILE__)))), true);
             if (!self::updateOutOfDateConfigFiles()) {
                 I2CE::raiseError("Error in checking configuration files", E_USER_ERROR);
                 return false;
             }
             $config->__set("/I2CE/update/times/last", time());
             return !I2CE::hasWarnings();
             //Ireturn true;
         //Ireturn true;
         case 'in_progress_reenable':
         case 'in_progress_upgrade':
         case 'in_progress_install':
         case 'in_progress_reinstall':
             if (array_key_exists('HTTP_HOST', $_SERVER)) {
                 I2CE::raiseError("System update is already in progress");
                 $url = $_SERVER['REQUEST_URI'];
                 if (!array_key_exists('restart', $_GET)) {
                     if (strlen($_SERVER['QUERY_STRING']) > 0) {
                         $url .= '&restart';
                     } else {
                         $url .= '?restart';
                     }
                 }
                 echo "<br/>Site update in progress.  <a href='{$url}'>Restart</a>?";
                 $msg = "Site update in progress. Restart?";
                 echo "<script type='text/javascript'>if (confirm('{$msg}')) {setTimeout(function() {window.location= '{$url}';},500)}</script>";
                 //reload the requested page after 5 seconds
                 flush();
             } else {
                 I2CE::raiseError("System update is already in progress.  To force the restart add  --force-restart=1");
             }
             return false;
         default:
             I2CE::raiseError("Unrecognized site status: {$status}");
             return false;
     }
 }