Ejemplo n.º 1
0
 /**
  * Gets the core system going.  
  * @param string $dsn dsn string to connect to the database
  * @param string $user_access_init the init string for the user access mechanism
  * @param string $site_module_file  the configttion file for the site module
  * @returns boolean.  True on sucess
  */
 public static function initializeDSN($dsn, $user_access_init, $site_module_file, $bring_up_system = true)
 {
     if (empty($dsn)) {
         self::raiseError("Please set the dsn string", E_USER_ERROR);
         if (!array_key_exists('HTTP_HOST', $_SERVER)) {
             //command line
             exit(11);
         } else {
             return false;
         }
     }
     $mdb2 = new MDB2();
     $dsn_info = $mdb2->parseDSN($dsn);
     if (I2CE_Dumper::dumpStaticURL($dsn_info['database'], 'file')) {
         exit;
     }
     if (!self::dbConnect($dsn_info)) {
         self::raiseError("Could not connect to the database");
         if (!array_key_exists('HTTP_HOST', $_SERVER)) {
             //command line
             exit(13);
         } else {
             return false;
         }
     }
     self::setupSession();
     $clear = false;
     if (!array_key_exists('HTTP_HOST', $_SERVER)) {
         //command line
         $clear = self::getRuntimeVariable('clear_cache', '0');
     } else {
         $URL = self::getAccessedBaseURL(false) . 'clear_cache.php';
         $clear = substr($_SERVER['REQUEST_URI'], 0, strlen($URL)) == $URL;
     }
     if ($clear) {
         $config = self::setupMagicData();
         $config->setIfIsSet(self::$email, "/I2CE/feedback/to");
         session_destroy();
         if (function_exists('apc_clear_cache')) {
             apc_clear_cache('user');
             I2CE::raiseError("Cleared APC User Cache");
         }
         I2CE::raiseError("Session destroyed");
         I2CE::getConfig()->clearCache();
         I2CE::raiseError("Magic data cleared -- Execution stopping");
         die(0);
     }
     $update = false;
     if (!array_key_exists('HTTP_HOST', $_SERVER)) {
         //command line
         $update = self::getRuntimeVariable('update', '0');
     } else {
         $URL = self::getAccessedBaseURL(false) . 'update.php';
         $update = substr($_SERVER['REQUEST_URI'], 0, strlen($URL)) == $URL;
     }
     if (self::siteInitialized()) {
         self::raiseError("Already initialized!", E_USER_WARNING);
         return true;
     }
     $db = MDB2::singleton();
     //get the instance we just created.
     if (!$update && $bring_up_system) {
         // just assume it is until we know otherwise.  This error
         // message to don't dumped to the screen.
         self::siteInitialized(true);
     }
     /*
     if (I2CE_Dumper::dumpStaticURL($db->database_name, 'file')) {
         exit();
     }
     */
     I2CE_Error::resetStoredMessages();
     if (empty($site_module_file)) {
         self::raiseError("Please set the site module's config file", E_USER_ERROR);
         if (!array_key_exists('HTTP_HOST', $_SERVER)) {
             //command line
             exit(14);
         } else {
             return false;
         }
     }
     $config = self::setupMagicData();
     $config->setIfIsSet(self::$email, "/I2CE/feedback/to");
     $site_module_file = I2CE_FileSearch::absolut($site_module_file, 1);
     self::setupFileSearch(array('MODULES' => array(dirname(dirname(__FILE__)), dirname($site_module_file)), 'CLASSES' => dirname(__FILE__)));
     self::setUserAccessInit($user_access_init, null, true);
     if ($update) {
         require_once 'I2CE_Updater.php';
         if (!I2CE_Updater::updateSite($site_module_file)) {
             if (array_key_exists('HTTP_HOST', $_SERVER)) {
                 die("<br/>Could not update site");
             } else {
                 I2CE::raiseError("\nCould not update site\n");
                 exit(15);
             }
         } else {
             if (!array_key_exists('HTTP_HOST', $_SERVER)) {
                 //command line
                 exit(0);
             }
         }
         return true;
     } else {
         if ($bring_up_system && !self::bringUpSystem($site_module_file)) {
             self::raiseError("Could not bring up system", E_USER_ERROR);
             exit(15);
         }
         I2CE::$ob_level = ob_get_level();
         return true;
     }
 }