/**
  * get create table statement
  * 
  * @param Setup_Backend_Schema_Table_Abstract $_table
  * @return string
  */
 public function getCreateStatement(Setup_Backend_Schema_Table_Abstract $_table)
 {
     $statement = "CREATE TABLE IF NOT EXISTS `" . SQL_TABLE_PREFIX . $_table->name . "` (\n";
     $statementSnippets = array();
     foreach ($_table->fields as $field) {
         if (isset($field->name)) {
             $statementSnippets[] = $this->getFieldDeclarations($field);
         }
     }
     foreach ($_table->indices as $index) {
         if ($index->foreign) {
             $statementSnippets[] = $this->getForeignKeyDeclarations($index);
         } else {
             $statementSnippets[] = $this->getIndexDeclarations($index);
         }
     }
     $statement .= implode(",\n", $statementSnippets) . "\n)";
     if (isset($_table->engine)) {
         $statement .= " ENGINE=" . $_table->engine . " DEFAULT CHARSET=" . $_table->charset;
     } else {
         $statement .= " ENGINE=InnoDB DEFAULT CHARSET=utf8 ";
     }
     if (isset($_table->comment)) {
         $statement .= " COMMENT='" . $_table->comment . "'";
     }
     if (Setup_Core::isLogLevel(Zend_Log::TRACE)) {
         Setup_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $statement);
     }
     return $statement;
 }
 protected function _createTable($table)
 {
     if (Setup_Core::isLogLevel(Zend_Log::DEBUG)) {
         Setup_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Creating table: ' . $table->name);
     }
     try {
         $this->_backend->createTable($table);
     } catch (Zend_Db_Statement_Exception $zdse) {
         throw new Tinebase_Exception_Backend_Database('Could not create table: ' . $zdse->getMessage());
     } catch (Zend_Db_Adapter_Exception $zdae) {
         throw new Tinebase_Exception_Backend_Database('Could not create table: ' . $zdae->getMessage());
     }
 }
 /**
  * install given application
  *
  * @param  SimpleXMLElement $_xml
  * @param  array | optional $_options
  * @return void
  * @throws Tinebase_Exception_Backend_Database
  */
 protected function _installApplication(SimpleXMLElement $_xml, $_options = null)
 {
     if ($this->_backend === NULL) {
         throw new Tinebase_Exception_Backend_Database('Need configured and working database backend for install.');
     }
     try {
         if (Setup_Core::isLogLevel(Zend_Log::INFO)) {
             Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Installing application: ' . $_xml->name);
         }
         $createdTables = array();
         if (isset($_xml->tables)) {
             foreach ($_xml->tables[0] as $tableXML) {
                 $table = Setup_Backend_Schema_Table_Factory::factory('Xml', $tableXML);
                 $currentTable = $table->name;
                 if (Setup_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Setup_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Creating table: ' . $currentTable);
                 }
                 try {
                     $this->_backend->createTable($table);
                 } catch (Zend_Db_Statement_Exception $zdse) {
                     throw new Tinebase_Exception_Backend_Database('Could not create table: ' . $zdse->getMessage());
                 } catch (Zend_Db_Adapter_Exception $zdae) {
                     throw new Tinebase_Exception_Backend_Database('Could not create table: ' . $zdae->getMessage());
                 }
                 $createdTables[] = $table;
             }
         }
         $application = new Tinebase_Model_Application(array('name' => (string) $_xml->name, 'status' => $_xml->status ? (string) $_xml->status : Tinebase_Application::ENABLED, 'order' => $_xml->order ? (string) $_xml->order : 99, 'version' => (string) $_xml->version));
         $application = Tinebase_Application::getInstance()->addApplication($application);
         // keep track of tables belonging to this application
         foreach ($createdTables as $table) {
             Tinebase_Application::getInstance()->addApplicationTable($application, (string) $table->name, (int) $table->version);
         }
         // insert default records
         if (isset($_xml->defaultRecords)) {
             foreach ($_xml->defaultRecords[0] as $record) {
                 $this->_backend->execInsertStatement($record);
             }
         }
         // look for import definitions and put them into the db
         $this->createImportExportDefinitions($application);
         Setup_Initialize::initialize($application, $_options);
     } catch (Exception $e) {
         Tinebase_Exception::log($e, false);
         throw $e;
     }
 }
Esempio n. 4
0
 /**
  * clear the cache
  */
 protected function _clearCache()
 {
     if (Setup_Core::isLogLevel(Zend_Log::DEBUG)) {
         Setup_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' clearing cache ... ');
     }
     Tinebase_Core::getCache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('config'));
 }
 /**
  * removes a key from database table
  * 
  * @param string tableName 
  * @param string key name
  */
 public function dropIndex($_tableName, $_indexName)
 {
     $statement = "ALTER TABLE " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . $_tableName) . " DROP INDEX " . $this->_db->quoteIdentifier($_indexName);
     try {
         $this->execQueryVoid($statement);
     } catch (Zend_Db_Statement_Exception $zdse) {
         if (Setup_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' ' . $zdse);
         }
         // try it again with table prefix
         $statement = "ALTER TABLE " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . $_tableName) . " DROP INDEX " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . $_indexName);
         $this->execQueryVoid($statement);
     }
 }