/**
  * Bootstraps the Innomatic container.
  *
  * @param string $home Complete path of the directory containing the
  * Innomatic webapp.
  * @param string $configuration Complete path of the Innomatic
  * configuration file.
  */
 public function bootstrap($home, $configuration)
 {
     if ($this->bootstrapped) {
         return;
     }
     $this->home = $home;
     // Reads the configuration
     $this->configurationFile = $configuration;
     $this->config = new InnomaticSettings($configuration);
     // *********************************************************************
     // PHP environment
     // *********************************************************************
     // PHP
     $timelimit = $this->config->value('PHPExecutionTimeLimit');
     if (!strlen($timelimit)) {
         $timelimit = 0;
     }
     set_time_limit($timelimit);
     ignore_user_abort(true);
     // Adds global override classes folder to the include path.
     set_include_path($this->home . 'core/overrides/classes/' . PATH_SEPARATOR . get_include_path());
     // *********************************************************************
     // Innomatic state, environment, mode, interface and edition
     // *********************************************************************
     // Waits until system is in upgrade phase
     if ($this->lockOverride == false) {
         while (file_exists($this->home . 'core/temp/upgrading_system_lock')) {
             $this->state = \Innomatic\Core\InnomaticContainer::STATE_UPGRADE;
             clearstatcache();
             sleep(1);
         }
     }
     // Checks if system is in setup phase and sets the state
     if (file_exists($this->home . 'core/temp/setup_lock')) {
         $this->state = \Innomatic\Core\InnomaticContainer::STATE_SETUP;
         if (extension_loaded('APD')) {
             apd_set_session_trace(35);
         }
     } else {
         switch ($this->config->value('PlatformState')) {
             case 'debug':
                 $this->state = \Innomatic\Core\InnomaticContainer::STATE_DEBUG;
                 if (extension_loaded('APD')) {
                     apd_set_session_trace(35);
                 }
                 break;
             case 'production':
                 $this->state = \Innomatic\Core\InnomaticContainer::STATE_PRODUCTION;
                 break;
             default:
                 $this->state = \Innomatic\Core\InnomaticContainer::STATE_PRODUCTION;
         }
     }
     // Environment
     switch ($this->config->value('PlatformEnvironment')) {
         case 'development':
             $this->environment = \Innomatic\Core\InnomaticContainer::ENVIRONMENT_DEVELOPMENT;
             break;
         case 'integration':
             $this->environment = \Innomatic\Core\InnomaticContainer::ENVIRONMENT_INTEGRATION;
             break;
         case 'staging':
             $this->environment = \Innomatic\Core\InnomaticContainer::ENVIRONMENT_STAGING;
             break;
         case 'production':
             $this->environment = \Innomatic\Core\InnomaticContainer::ENVIRONMENT_PRODUCTION;
             break;
         default:
             $this->environment = \Innomatic\Core\InnomaticContainer::ENVIRONMENT_PRODUCTION;
     }
     // Interface
     //$this->interface = \Innomatic\Core\InnomaticContainer::INTERFACE_UNKNOWN;
     // Mode
     //$this->mode = \Innomatic\Core\InnomaticContainer::MODE_ROOT;
     // Edition
     if ($this->config->value('PlatformEdition') == 'enterprise' or $this->config->value('PlatformEdition') == 'singletenant') {
         $this->edition = \Innomatic\Core\InnomaticContainer::EDITION_SINGLETENANT;
     }
     // *********************************************************************
     // Pid and shutdown function
     // *********************************************************************
     if ($this->state != \Innomatic\Core\InnomaticContainer::STATE_SETUP) {
         $this->pid = md5(microtime());
         if (!file_exists($this->home . 'core/temp/pids/')) {
             @mkdir($this->home . 'core/temp/pids/');
         }
         touch($this->home . 'core/temp/pids/' . $this->pid, time());
         register_shutdown_function(array($this, 'shutdown'));
     }
     // *********************************************************************
     // Innomatic platform name
     // *********************************************************************
     $this->platformName = $this->config->value('PlatformName');
     $this->platformGroup = $this->config->value('PlatformGroup');
     // *********************************************************************
     // Innomatic error handler
     // *********************************************************************
     //set_error_handler(array($this, 'errorHandler'));
     // *********************************************************************
     // Innomatic root
     // *********************************************************************
     $this->country = $this->config->value('RootCountry');
     $this->language = $this->config->value('RootLanguage');
     if ($this->state != \Innomatic\Core\InnomaticContainer::STATE_SETUP) {
         // Innomatic central database
         //
         $dasnString = $this->config->value('RootDatabaseType') . '://' . $this->config->value('RootDatabaseUser') . ':' . $this->config->value('RootDatabasePassword') . '@' . $this->config->value('RootDatabaseHost') . ':' . $this->config->value('RootDatabasePort') . '/' . $this->config->value('RootDatabaseName') . '?' . 'logfile=' . $this->getHome() . 'core/log/innomatic_root_db.log';
         $this->rootDb = \Innomatic\Dataaccess\DataAccessFactory::getDataAccess(new \Innomatic\Dataaccess\DataAccessSourceName($dasnString));
         if (!$this->rootDb->connect()) {
             $this->abort('Database not connected');
         }
     }
     // *********************************************************************
     // Run time state and interface defined data
     // *********************************************************************
     // Debugger
     if ($this->state == \Innomatic\Core\InnomaticContainer::STATE_DEBUG) {
         $this->loadTimer = new \Innomatic\Debug\LoadTime(LoadTime::LOADTIME_MODE_CONTINUOUS);
         $this->loadTimer->Mark('start');
         $this->dbLoadTimer = new \Innomatic\Debug\LoadTime(LoadTime::LOADTIME_MODE_STARTSTOP);
     }
     // Security
     $securityReportsInterval = $this->config->value('SecurityReportsInterval');
     if ($securityReportsInterval > 0) {
         $lastSecurityReport = $this->config->value('SecurityLastReportTime');
         if (!$lastSecurityReport or $lastSecurityReport < time() - $securityReportsInterval * 3600 * 24) {
             $innomaticSecurity = new \Innomatic\Security\SecurityManager();
             $innomaticSecurity->sendReport();
             unset($innomaticSecurity);
         }
     }
     unset($securityReportsInterval);
     // Maintenance
     $maintenanceHandler = new \Innomatic\Maintenance\MaintenanceHandler();
     $maintenanceInterval = $maintenanceHandler->getMaintenanceInterval();
     if ($this->state != \Innomatic\Core\InnomaticContainer::STATE_MAINTENANCE and $maintenanceInterval > 0) {
         $lastMaintenance = $maintenanceHandler->getLastMaintenanceTime();
         if (!$lastMaintenance or $lastMaintenance < time() - $maintenanceInterval * 3600 * 24) {
             $innomaticMaintenance = new \Innomatic\Maintenance\MaintenanceHandler();
             $innomaticMaintenance->doMaintenance();
             $innomaticMaintenance->sendReport();
             unset($innomaticMaintenance);
         }
     }
     unset($maintenanceInterval);
     // *********************************************************************
     // Auto exec routines
     // *********************************************************************
     // Application reupdate check
     if (file_exists($this->home . 'core/temp/appinst/reupdate')) {
         $tmpmod = new \Innomatic\Application\Application($this->rootDb, '');
         $tmpmod->install($this->home . 'core/temp/appinst/reupdate');
         clearstatcache();
         if (file_exists($this->home . 'core/temp/appinst/reupdate')) {
             unlink($this->home . 'core/temp/appinst/reupdate');
         }
     }
     // Startup hook
     if ($this->state != \Innomatic\Core\InnomaticContainer::STATE_SETUP) {
         $hook = new \Innomatic\Process\Hook($this->rootDb, 'innomatic', 'instance');
         $null = '';
         switch ($hook->callHooks('startup', $null, '')) {
             case \Innomatic\Process\Hook::RESULT_ABORT:
                 $this->abort('Bootstrap aborted');
                 break;
         }
     }
     // Bootstrap end
     $this->bootstrapped = true;
 }