public function testExplicitRename()
 {
     $this->markTestSkipped('evauate concept for explicit field rename with doctrine2 schema tool');
     $em = Setup_SchemaTool::getEntityManager('Inventory');
     $sm = $em->getConnection()->getSchemaManager();
     // NOTE: the DBAL schema is stateless and 'just' describes a schema in a plattform independend way
     //       thus, all schema upgrade is based on schema comparisim
     $fromSchema = $sm->createSchema();
     $toSchema = clone $fromSchema;
     $table = $toSchema->getTable('tine20_inventory_item');
     // workaround -> might have problems?!
     $col = $table->getColumn('id');
     $table->dropColumn('id');
     $table->addColumn('ident', $col->getType()->getName(), $col->toArray());
     // better create, copy, delete?
     // @TODO ask some insider
     //  ? Schema tool can't rename cols, but schema diff with compare (at least with mysql plattform) alters table name correctly when col is renamed in annotations
     // non rename updates are a lot more easy
     $table->changeColumn('name', array('length' => 200));
     $comparator = new Comparator();
     $schemaDiff = $comparator->compare($fromSchema, $toSchema);
     $updateSql = $schemaDiff->toSql($em->getConnection()->getDatabasePlatform());
     //        print_r($updateSql);
 }
 /**
  * update schema of modelconfig enabled app
  *
  * @param string $appName
  * @param array $modelNames
  * @throws Setup_Exception_NotFound
  */
 public function updateSchema($appName, $modelNames)
 {
     $updateRequired = false;
     $setNewVersions = array();
     foreach ($modelNames as $modelName) {
         $modelConfig = $modelName::getConfiguration();
         $tableName = Tinebase_Helper::array_value('name', $modelConfig->getTable());
         $currentVersion = $this->getTableVersion($tableName);
         $schemaVersion = $modelConfig->getVersion();
         if ($currentVersion < $schemaVersion) {
             $updateRequired = true;
             $setNewVersions[$tableName] = $schemaVersion;
         }
     }
     if ($updateRequired) {
         Setup_SchemaTool::updateSchema($appName, $modelNames);
         foreach ($setNewVersions as $table => $version) {
             $this->setTableVersion($table, $version);
         }
     }
 }
 /**
  * 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();
         // traditional xml declaration
         if (isset($_xml->tables)) {
             foreach ($_xml->tables[0] as $tableXML) {
                 $table = Setup_Backend_Schema_Table_Factory::factory('Xml', $tableXML);
                 $this->_createTable($table);
                 $createdTables[] = $table;
             }
         } else {
             $application = Setup_Core::getApplicationInstance($_xml->name, '', true);
             $models = $application->getModels(true);
             if (count($models) > 0) {
                 // create tables using doctrine 2
                 Setup_SchemaTool::createSchema($_xml->name, $models);
                 // adopt to old workflow
                 foreach ($models as $model) {
                     $modelConfiguration = $model::getConfiguration();
                     $createdTables[] = (object) array('name' => Tinebase_Helper::array_value('name', $modelConfiguration->getTable()), 'version' => $modelConfiguration->getVersion());
                 }
             }
         }
         $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;
     }
 }