/**
  * init setup framework
  */
 public static function initFramework()
 {
     Setup_Core::setupConfig();
     Setup_Core::setupTempDir();
     //Database Connection must be setup before cache because setupCache uses constant "SQL_TABLE_PREFIX"
     Setup_Core::setupDatabaseConnection();
     Setup_Core::setupStreamWrapper();
     //Cache must be setup before User Locale because otherwise Zend_Locale tries to setup
     //its own cache handler which might result in a open_basedir restriction depending on the php.ini settings
     Setup_Core::setupCache();
     Setup_Core::setupBuildConstants();
     // setup a temporary user locale/timezone. This will be overwritten later but we
     // need to handle exceptions during initialisation process such as seesion timeout
     Setup_Core::set('locale', new Zend_Locale('en_US'));
     Setup_Core::set(Tinebase_Core::USERTIMEZONE, 'UTC');
     Setup_Core::setupUserLocale();
     header('X-API: http://www.tine20.org/apidocs/tine20/');
 }
 /**
  * nagios monitoring for tine 2.0 database connection
  * 
  * @return integer
  * @see http://nagiosplug.sourceforge.net/developer-guidelines.html#PLUGOUTPUT
  */
 public function monitoringCheckDB()
 {
     $message = 'DB CONNECTION FAIL';
     try {
         if (!Setup_Core::isRegistered(Setup_Core::CONFIG)) {
             Setup_Core::setupConfig();
         }
         if (!Setup_Core::isRegistered(Setup_Core::LOGGER)) {
             Setup_Core::setupLogger();
         }
         $time_start = microtime(true);
         $dbcheck = Setup_Core::setupDatabaseConnection();
         $time = (microtime(true) - $time_start) * 1000;
     } catch (Exception $e) {
         $message .= ': ' . $e->getMessage();
         $dbcheck = FALSE;
     }
     if ($dbcheck) {
         echo "DB CONNECTION OK | connecttime={$time}ms;;;;\n";
         return 0;
     }
     echo $message . "\n";
     return 2;
 }
 /**
  * restore
  *
  * @param $options array(
  *      'backupDir'  => string // location of backup to restore
  *      'config'     => bool   // restore config
  *      'db'         => bool   // restore database
  *      'files'      => bool   // restore files
  *    )
  *
  * @param $options
  * @throws Exception
  */
 public function restore($options)
 {
     if (!isset($options['backupDir'])) {
         throw new Exception("you need to specify the backupDir");
     }
     if ($options['config']) {
         $configBackupFile = $options['backupDir'] . '/tine20_config.tar.bz2';
         if (!file_exists($configBackupFile)) {
             throw new Exception("{$configBackupFile} not found");
         }
         $configDir = isset($options['configDir']) ? $options['configDir'] : false;
         if (!$configDir) {
             $configFile = stream_resolve_include_path('config.inc.php');
             if (!$configFile) {
                 throw new Exception("can't detect configDir, please use configDir option");
             }
             $configDir = dirname($configFile);
         }
         `cd {$configDir}; tar xf {$configBackupFile}`;
     }
     Setup_Core::setupConfig();
     $config = Setup_Core::getConfig();
     if ($options['db']) {
         $this->_backend->restore($options['backupDir']);
     }
     $filesDir = isset($config->filesdir) ? $config->filesdir : false;
     if ($options['files']) {
         $filesBackupFile = $options['backupDir'] . '/tine20_files.tar.bz2';
         if (!file_exists($filesBackupFile)) {
             throw new Exception("{$filesBackupFile} not found");
         }
         `cd {$filesDir}; tar xf {$filesBackupFile}`;
     }
 }