public static function getInstance($type, Nextgen_Core_Database $db1, Nextgen_Core_Database $db2, array $params) { self::$db1 = $db1; self::$db2 = $db2; $className = __CLASS__ . 's_' . $type; return new $className($params); }
protected function compareConstraints() { $transformations = array(); list($newKeys, $deletedKeys, $changedKeys) = $this->compareTableKeyCollections($this->db1->getTable($this->tableName)->getConstraints(), $this->db2->getTable($this->tableName)->getConstraints()); $this->config->getLogger()->startSection("New constraints for {$this->tableName}"); $this->config->getLogger()->log($newKeys); $this->config->getLogger()->startSection("Deleted constraints for {$this->tableName}"); $this->config->getLogger()->log($deletedKeys); $this->config->getLogger()->startSection("Changed constraints for {$this->tableName}"); $this->config->getLogger()->log($changedKeys); foreach ($newKeys as $newKey) { $args = array('tableName' => $this->tableName, 'constraintName' => $newKey->getName()); $transformation = Nextgen_Core_Transformation::getInstance(Nextgen_Core_Transformation::ADD_CONSTRAINT, $this->db1, $this->db2, $args); $transformations[] = $transformation; } foreach ($deletedKeys as $deletedKey) { $args = array('tableName' => $this->tableName, 'constraintName' => $deletedKey->getName()); $transformation = Nextgen_Core_Transformation::getInstance(Nextgen_Core_Transformation::DROP_CONSTRAINT, $this->db1, $this->db2, $args); $transformations[] = $transformation; } foreach ($changedKeys as $changedKey) { $args = array('tableName' => $this->tableName, 'constraintName' => $changedKey->getName()); $transformation = Nextgen_Core_Transformation::getInstance(Nextgen_Core_Transformation::DROP_CONSTRAINT, $this->db1, $this->db2, $args); $transformations[] = $transformation; $transformation = Nextgen_Core_Transformation::getInstance(Nextgen_Core_Transformation::ADD_CONSTRAINT, $this->db1, $this->db2, $args); $transformations[] = $transformation; } return $transformations; }
public function getTransformations() { // these two arrays are computed without taking any renaming into account. // we are going to do that soon $potentialNewTables = $this->getPotentialNewTables(); $potentialDeletedTables = $this->getPotentialDeletedTables(); $this->config->getLogger()->startSection('Potential new tables'); $this->config->getLogger()->log(print_r($potentialNewTables, true)); $this->config->getLogger()->startSection('Potential deleted tables'); $this->config->getLogger()->log(print_r($potentialDeletedTables, true)); $renamedTablesMapping = array(); if (!$this->config->isUserInteractionDisabled()) { $renamedTablesMapping = $this->getRenamedTablesMapping($potentialNewTables, $potentialDeletedTables); } $this->config->getLogger()->startSection('Renamed tables mapping'); $this->config->getLogger()->log(print_r($renamedTablesMapping, true)); list($newTables, $deletedTables) = $this->changeEntitiesBecauseOfRenamedTables($renamedTablesMapping, $potentialNewTables, $potentialDeletedTables); $this->config->getLogger()->startSection('New tables'); $this->config->getLogger()->log(print_r($newTables, true)); $this->config->getLogger()->startSection('Deleted tables'); $this->config->getLogger()->log(print_r($deletedTables, true)); // this step can be counterintuitive. Please read the comment to this method $modifiedDb1 = $this->getNewDb1StructureBecauseOfRenamedTables($renamedTablesMapping); $transformations = array(); foreach ($newTables as $newTable) { $params = array('tableName' => $newTable); $transformation = Nextgen_Core_Transformation::getInstance(Nextgen_Core_Transformation::ADD_TABLE, $this->db1, $this->db2, $params); $transformations[] = $transformation; } foreach ($deletedTables as $deleteTable) { $params = array('tableName' => $deleteTable); $transformation = Nextgen_Core_Transformation::getInstance(Nextgen_Core_Transformation::DELETE_TABLE, $this->db1, $this->db2, $params); $transformations[] = $transformation; } foreach ($renamedTablesMapping as $key => $value) { $params = array('tableOldName' => $key, 'tableNewName' => $value); $transformation = Nextgen_Core_Transformation::getInstance(Nextgen_Core_Transformation::RENAME_TABLE, $this->db1, $this->db2, $params); $transformations[] = $transformation; } $tablesComparator = new Nextgen_Core_TablesComparator($this->config, $modifiedDb1, $this->db2); $tablesTransformations = $tablesComparator->getTransformations(); $transformations = array_merge($transformations, $tablesTransformations); return $transformations; }