/** * Worker function for the first time installation. Absolutely nothing has been done yet. * @param string $site_module_file The site module file * @param boolean $verbose_errors. defaults to true. */ protected static function install($site_module_file, $restart, $verbose_errors = true) { $db = MDB2::singleton(); I2CE::raiseError("Beginning new installation"); I2CE::longExecution(); I2CE::getFileSearch()->addPath('MODULES', dirname(dirname(__FILE__)), 'EVEN_HIGHER'); $configurator = new I2CE_Configurator(I2CE::getConfig()); $site_module = $configurator->processConfigFile($site_module_file, false, $verbose_errors, true); I2CE::raiseError("Site module is: {$site_module}"); //we don't want to process the site config data at the moment, just the meta data if (!(is_string($site_module) && strlen($site_module) > 0)) { I2CE::raiseError("Installation Failed for site. Invalid configuration file {$site_module_file}. No name given.", E_USER_ERROR); return false; } I2CE::raiseError("Enabling I2CE"); I2CE::raiseError("Setting site module to {$site_module}"); I2CE::getConfig()->config->site->module = $site_module; $mod_factory = I2CE_ModuleFactory::instance(); $success = self::_updateModules('I2CE'); if (!$success) { I2CE::raiseError("Installation Failed for I2CE", E_USER_ERROR); return false; } if (I2CE::getConfig()->setIfIsSet($site_module, '/config/site/module')) { I2CE::getConfig()->config->data->{$site_module}->file = I2CE_FileSearch::relativePath($site_module_file); } else { I2CE::raiseError("Site is not set"); return false; } I2CE::getConfig()->config->I2CE->update->times->last = time(); I2CE::setupFileSearch(array("CLASSES" => "./", 'MODULES' => array(dirname(dirname(__FILE__)), dirname($site_module_file))), true); $mod_factory->resetStoredLoadedPaths(); if ($restart) { //make sure all of our classes are loaded in case this was a restart $mod_factory->loadPaths(null, 'CLASSES'); } else { $mod_factory->loadPaths('I2CE', array('CLASSES', 'MODULES'), true); } I2CE::raiseError("Begining initializiation of site {$site_module}", E_USER_NOTICE); if (!self::_updateModules($site_module)) { I2CE::raiseError("Site Module Installation Failed", E_USER_ERROR); return false; } //we got through I2CE's installation if ($db->in_transaction) { I2CE::raiseError("Warning: ending installation still in transaction -- committing"); $db->commit(); } if (I2CE::hasWarnings()) { I2CE::raiseError("Your site was not initialized. Please refer to the warning messages above."); flush(); return false; } else { if (array_key_exists('HTTP_HOST', $_SERVER)) { $url = array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : "/"; I2CE::raiseError("Congratulations, your site has been initialized. You may <a href='{$url}'>continue</a> onto the site."); echo "<script type='text/javascript'>window.location= '{$url}';</script>"; //reload the requested page. flush(); } return true; } }