/** * 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}`; } }
/** * uninstall app * * @param Tinebase_Model_Application $_application */ protected function _uninstallApplication(Tinebase_Model_Application $_application) { Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Uninstall ' . $_application); $applicationTables = Tinebase_Application::getInstance()->getApplicationTables($_application); do { $oldCount = count($applicationTables); if ($_application->name == 'Tinebase') { $installedApplications = Tinebase_Application::getInstance()->getApplications(NULL, 'id'); if (count($installedApplications) !== 1) { throw new Setup_Exception_Dependency('Failed to uninstall application "Tinebase" because of dependencies to other installed applications.'); } } foreach ($applicationTables as $key => $table) { Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Remove table: {$table}"); try { $this->_backend->dropTable($table); if ($_application->name != 'Tinebase') { Tinebase_Application::getInstance()->removeApplicationTable($_application, $table); } unset($applicationTables[$key]); } catch (Zend_Db_Statement_Exception $e) { // we need to catch exceptions here, as we don't want to break here, as a table // might still have some foreign keys $message = $e->getMessage(); Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " Could not drop table {$table} - " . $message); // remove app table if table not found in db if (preg_match('/SQLSTATE\\[42S02\\]: Base table or view not found/', $message) && $_application->name != 'Tinebase') { Tinebase_Application::getInstance()->removeApplicationTable($_application, $table); unset($applicationTables[$key]); } } } if ($oldCount > 0 && count($applicationTables) == $oldCount) { throw new Setup_Exception('dead lock detected oldCount: ' . $oldCount); } } while (count($applicationTables) > 0); if ($_application->name != 'Tinebase') { // delete containers, config options and other data for app Tinebase_Application::getInstance()->removeApplicationData($_application); // remove application from table of installed applications Tinebase_Application::getInstance()->deleteApplication($_application); } Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Removed app: " . $_application->name); }
/** * Initializes database procedures * * @param Setup_Backend_Interface $backend */ public function initProcedures(Setup_Backend_Interface $backend) { $md5 = "CREATE OR REPLACE\n function md5( input varchar2 ) return sys.dbms_obfuscation_toolkit.varchar2_checksum as\n begin\n return lower(rawtohex(utl_raw.cast_to_raw(sys.dbms_obfuscation_toolkit.md5( input_string => input ))));\n end;"; $backend->execQueryVoid($md5); $now = "CREATE OR REPLACE\n function NOW return DATE as\n begin\n return SYSDATE;\n end;"; $backend->execQueryVoid($now); $typeStringAgg = "CREATE OR REPLACE TYPE t_string_agg AS OBJECT\n (\n g_string VARCHAR2(32767),\n\n STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg)\n RETURN NUMBER,\n\n MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg, value IN VARCHAR2 )\n RETURN NUMBER,\n\n MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg,\n returnValue OUT VARCHAR2,\n flags IN NUMBER)\n RETURN NUMBER,\n\n MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg,\n ctx2 IN t_string_agg)\n RETURN NUMBER\n );"; $backend->execQueryVoid($typeStringAgg); $typeStringAgg = "CREATE OR REPLACE TYPE BODY t_string_agg IS\n STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg)\n RETURN NUMBER IS\n BEGIN\n sctx := t_string_agg(NULL);\n RETURN ODCIConst.Success;\n END;\n\n MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg,\n value IN VARCHAR2 )\n RETURN NUMBER IS\n BEGIN\n SELF.g_string := self.g_string || ',' || value;\n RETURN ODCIConst.Success;\n END;\n\n MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg,\n returnValue OUT VARCHAR2,\n flags IN NUMBER)\n RETURN NUMBER IS\n BEGIN\n returnValue := RTRIM(LTRIM(SELF.g_string, ','), ',');\n RETURN ODCIConst.Success;\n END;\n\n MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg,\n ctx2 IN t_string_agg)\n RETURN NUMBER IS\n BEGIN\n SELF.g_string := SELF.g_string || ',' || ctx2.g_string;\n RETURN ODCIConst.Success;\n END;\n END;"; $backend->execQueryVoid($typeStringAgg); $group_concat = "CREATE OR REPLACE\n FUNCTION GROUP_CONCAT (p_input VARCHAR2)\n RETURN VARCHAR2\n PARALLEL_ENABLE AGGREGATE USING t_string_agg;"; $backend->execQueryVoid($group_concat); }