diff --git a/phinx/src/Phinx/Migration/Manager/Environment.php b/phinx/src/Phinx/Migration/Manager/Environment.php deleted file mode 100644 index 43571ff..0000000 --- a/phinx/src/Phinx/Migration/Manager/Environment.php +++ /dev/null @@ -1,353 +0,0 @@ -name = $name; - $this->options = $options; - } - - /** - * Executes the specified migration on this environment. - * - * @param MigrationInterface $migration Migration - * @param string $direction Direction - * @return void - */ - public function executeMigration(MigrationInterface $migration, $direction = MigrationInterface::UP) - { - $startTime = time(); - $direction = ($direction === MigrationInterface::UP) ? MigrationInterface::UP : MigrationInterface::DOWN; - $migration->setAdapter($this->getAdapter()); - - // begin the transaction if the adapter supports it - if ($this->getAdapter()->hasTransactions()) { - $this->getAdapter()->beginTransaction(); - } - - // Run the migration - if (method_exists($migration, MigrationInterface::CHANGE)) { - if ($direction === MigrationInterface::DOWN) { - // Create an instance of the ProxyAdapter so we can record all - // of the migration commands for reverse playback - $proxyAdapter = AdapterFactory::instance() - ->getWrapper('proxy', $this->getAdapter()); - $migration->setAdapter($proxyAdapter); - /** @noinspection PhpUndefinedMethodInspection */ - $migration->change(); - $proxyAdapter->executeInvertedCommands(); - $migration->setAdapter($this->getAdapter()); - } else { - /** @noinspection PhpUndefinedMethodInspection */ - $migration->change(); - } - } else { - $migration->{$direction}(); - } - - // commit the transaction if the adapter supports it - if ($this->getAdapter()->hasTransactions()) { - $this->getAdapter()->commitTransaction(); - } - - // Record it in the database - $this->getAdapter()->migrated($migration, $direction, date('Y-m-d H:i:s', $startTime), date('Y-m-d H:i:s', time())); - } - - /** - * Executes the specified seeder on this environment. - * - * @param MigrationInterface $migration Migration - * @param string $direction Direction - * @return void - */ - public function executeSeed(SeedInterface $seed) - { - $startTime = time(); - $seed->setAdapter($this->getAdapter()); - - // begin the transaction if the adapter supports it - if ($this->getAdapter()->hasTransactions()) { - $this->getAdapter()->beginTransaction(); - } - - // Run the seeder - if (method_exists($seed, SeedInterface::RUN)) { - $seed->run(); - } - - // commit the transaction if the adapter supports it - if ($this->getAdapter()->hasTransactions()) { - $this->getAdapter()->commitTransaction(); - } - } - - /** - * Sets the environment's name. - * - * @param string $name Environment Name - * @return Environment - */ - public function setName($name) - { - $this->name = $name; - return $this; - } - - /** - * Gets the environment name. - * - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Sets the environment's options. - * - * @param array $options Environment Options - * @return Environment - */ - public function setOptions($options) - { - $this->options = $options; - return $this; - } - - /** - * Gets the environment's options. - * - * @return array - */ - public function getOptions() - { - return $this->options; - } - - /** - * Sets the console output. - * - * @param OutputInterface $output Output - * @return Environment - */ - public function setOutput(OutputInterface $output) - { - $this->output = $output; - return $this; - } - - /** - * Gets the console output. - * - * @return OutputInterface - */ - public function getOutput() - { - return $this->output; - } - - /** - * Gets all migrated version numbers. - * - * @return array - */ - public function getVersions() - { - return $this->getAdapter()->getVersions(); - } - - /** - * Get all migration log entries, indexed by version number. - * - * @return array - */ - public function getVersionLog() - { - return $this->getAdapter()->getVersionLog(); - } - - /** - * Sets the current version of the environment. - * - * @param int $version Environment Version - * @return Environment - */ - public function setCurrentVersion($version) - { - $this->currentVersion = $version; - return $this; - } - - /** - * Gets the current version of the environment. - * - * @return int - */ - public function getCurrentVersion() - { - // We don't cache this code as the current version is pretty volatile. - // TODO - that means they're no point in a setter then? - // maybe we should cache and call a reset() method everytime a migration is run - $versions = $this->getVersions(); - $version = 0; - - if (!empty($versions)) { - $version = end($versions); - } - - $this->setCurrentVersion($version); - return $this->currentVersion; - } - - /** - * Sets the database adapter. - * - * @param AdapterInterface $adapter Database Adapter - * @return Environment - */ - public function setAdapter(AdapterInterface $adapter) - { - $this->adapter = $adapter; - return $this; - } - - /** - * Gets the database adapter. - * - * @return AdapterInterface - */ - public function getAdapter() - { - if (isset($this->adapter)) { - return $this->adapter; - } - if (isset($this->options['connection'])) { - if (!($this->options['connection'] instanceof \PDO)) { - throw new \RuntimeException('The specified connection is not a PDO instance'); - } - - $this->options['adapter'] = $this->options['connection']->getAttribute(\PDO::ATTR_DRIVER_NAME); - } - if (!isset($this->options['adapter'])) { - throw new \RuntimeException('No adapter was specified for environment: ' . $this->getName()); - } - - $adapter = AdapterFactory::instance() - ->getAdapter($this->options['adapter'], $this->options); - - if (isset($this->options['wrapper'])) { - $adapter = AdapterFactory::instance() - ->getWrapper($this->options['wrapper'], $adapter); - } - - if ($this->getOutput()) { - $adapter->setOutput($this->getOutput()); - } - - // Use the TablePrefixAdapter if table prefix/suffixes are in use - if ($adapter->hasOption('table_prefix') || $adapter->hasOption('table_suffix')) { - $adapter = AdapterFactory::instance() - ->getWrapper('prefix', $adapter); - } - - $this->setAdapter($adapter); - - return $adapter; - } - - /** - * Sets the schema table name. - * - * @param string $schemaTableName Schema Table Name - * @return Environment - */ - public function setSchemaTableName($schemaTableName) - { - $this->schemaTableName = $schemaTableName; - return $this; - } - - /** - * Gets the schema table name. - * - * @return string - */ - public function getSchemaTableName() - { - return $this->schemaTableName; - } -}