Since: 2.0
Author: Jonathan H. Wage (jonwage@gmail.com)
示例#1
0
 /**
  * @param Connection $connection
  * @param AppKernel  $kernel
  */
 public function preUpdate(Connection $connection, AppKernel $kernel)
 {
     /** @var \Symfony\Component\HttpKernel\Bundle\Bundle[] $bundles */
     $bundles = $kernel->getBundles();
     $isPortfolioBundleInstalled = false;
     foreach ($bundles as $bundle) {
         if ('IcapPortfolioBundle' === $bundle->getName()) {
             $isPortfolioBundleInstalled = true;
         }
     }
     if ($connection->getSchemaManager()->tablesExist(['icap__portfolio_widget_badges'])) {
         if ($isPortfolioBundleInstalled) {
             $this->log('Found existing database schema: skipping install migration...');
             $config = new Configuration($connection);
             $config->setMigrationsTableName('doctrine_icapbadgebundle_versions');
             $config->setMigrationsNamespace('claro_badge');
             // required but useless
             $config->setMigrationsDirectory('claro_badge');
             // idem
             try {
                 $version = new Version($config, '20150929141509', 'stdClass');
                 $version->markMigrated();
             } catch (\Exception $e) {
                 $this->log('Already migrated');
             }
         } else {
             $this->log('Deleting badges tables for portfolio...');
             $connection->getSchemaManager()->dropTable('icap__portfolio_widget_badges_badge');
             $connection->getSchemaManager()->dropTable('icap__portfolio_widget_badges');
             $this->log('badges tables for portfolio deleted.');
         }
     }
 }
示例#2
0
 /**
  * Create migration with description
  */
 public function testCreateVersionWithCustomName()
 {
     $versionName = '003';
     $versionDescription = 'My super migration';
     $version = new Version(new Configuration($this->getSqliteConnection()), $versionName, 'Doctrine\\DBAL\\Migrations\\Tests\\VersionTest_MigrationDescription');
     $this->assertEquals($versionName, $version->getVersion());
     $this->assertEquals($versionDescription, $version->getMigration()->getDescription());
 }
示例#3
0
 public function __construct(Version $version)
 {
     $this->_configuration = $version->getConfiguration();
     $this->_outputWriter = $this->_configuration->getOutputWriter();
     $this->_connection = $this->_configuration->getConnection();
     $this->_sm = $this->_connection->getSchemaManager();
     $this->_platform = $this->_connection->getDatabasePlatform();
     $this->_version = $version;
 }
 public function preInstall()
 {
     if ($this->conn->getSchemaManager()->tablesExist(['claro_message'])) {
         $this->log('Found existing database schema: skipping install migration...');
         $config = new Configuration($this->conn);
         $config->setMigrationsTableName('doctrine_clarolinemessagebundle_versions');
         $config->setMigrationsNamespace('claro_message');
         // required but useless
         $config->setMigrationsDirectory('claro_message');
         // idem
         $version = new Version($config, '20150429114010', 'stdClass');
         $version->markMigrated();
     }
 }
 private function skipInstallIfMigratingFromCore()
 {
     if ($this->conn->getSchemaManager()->tablesExist(['claro_event'])) {
         $this->log('Found existing database schema: skipping install migration...');
         $config = new Configuration($this->conn);
         $config->setMigrationsTableName('doctrine_clarolineagendabundle_versions');
         $config->setMigrationsNamespace('claro_event');
         // required but useless
         $config->setMigrationsDirectory('claro_event');
         // idem
         $version = new Version($config, '20150429110105', 'stdClass');
         $version->markMigrated();
     }
 }
 /**
  * Print a warning message if the condition evalutes to TRUE.
  *
  * @param bool $condition
  * @param string $message
  */
 public function warnIf($condition, $message = '')
 {
     $message = strlen($message) ? $message : 'Unknown Reason';
     if ($condition === true) {
         $this->outputWriter->write('    <warning>Warning during ' . $this->version->getExecutionState() . ': ' . $message . '</warning>');
     }
 }
示例#7
0
 /**
  * @param         $versionName
  * @param Version $version
  * @param bool    $timeQueries
  * @param string  $verb
  */
 protected function note($versionName, Version $version, $timeQueries = false, $verb = 'Migrated')
 {
     $msg = "<info>{$verb}:</info> {$versionName}";
     if ($timeQueries) {
         $msg .= " ({$version->getTime()}s)";
     }
     $this->notes[] = $msg;
 }
 protected function addSql($sql, array $params = array(), array $types = array())
 {
     $this->version->addSql($sql, $params, $types);
 }
 /**
  * Tries to find out a package key which the Version belongs to. If no
  * package could be found, an empty string is returned.
  *
  * @param Version $version
  * @return string
  */
 protected function getPackageKeyFromMigrationVersion(Version $version)
 {
     $sortedAvailablePackages = $this->packageManager->getAvailablePackages();
     usort($sortedAvailablePackages, function (PackageInterface $packageOne, PackageInterface $packageTwo) {
         return strlen($packageTwo->getPackagePath()) - strlen($packageOne->getPackagePath());
     });
     $reflectedClass = new \ReflectionClass($version->getMigration());
     $classPathAndFilename = Files::getUnixStylePath($reflectedClass->getFileName());
     /** @var $package PackageInterface */
     foreach ($sortedAvailablePackages as $package) {
         $packagePath = Files::getUnixStylePath($package->getPackagePath());
         if (strpos($classPathAndFilename, $packagePath) === 0) {
             return $package->getPackageKey();
         }
     }
     return '';
 }
示例#10
0
 /**
  * Check if we should execute a migration for a given direction and target
  * migration version.
  *
  * @param string  $direction The direction we are migrating.
  * @param Version $version   The Version instance to check.
  * @param string  $to        The version we are migrating to.
  * @param array   $migrated  Migrated versions array.
  *
  * @return boolean
  */
 private function shouldExecuteMigration($direction, Version $version, $to, $migrated)
 {
     if ($direction === 'down') {
         if (!in_array($version->getVersion(), $migrated)) {
             return false;
         }
         return $version->getVersion() > $to;
     }
     if ($direction === 'up') {
         if (in_array($version->getVersion(), $migrated)) {
             return false;
         }
         return $version->getVersion() <= $to;
     }
 }
 /**
  * Check if we should execute a migration for a given direction and target
  * migration version.
  *
  * @param string  $direction The direction we are migrating.
  * @param Version $version   The Version instance to check.
  * @param string  $to        The version we are migrating to.
  * @param array   $migrated  Migrated versions array.
  *
  * @return boolean
  */
 private function shouldExecuteMigration($direction, Version $version, $to, $migrated)
 {
     if ($direction === Version::DIRECTION_DOWN) {
         if (!in_array($version->getVersion(), $migrated)) {
             return false;
         }
         return $version->getVersion() > $to;
     }
     if ($direction === Version::DIRECTION_UP) {
         if (in_array($version->getVersion(), $migrated)) {
             return false;
         }
         return $version->getVersion() <= $to;
     }
 }
示例#12
0
 /**
  * Create migration with custom name
  */
 public function testCreateVersionWithCustomName()
 {
     $versionName = 'CustomVersionName';
     $version = new Version(new Configuration($this->getSqliteConnection()), '003', 'Doctrine\\DBAL\\Migrations\\Tests\\VersionTest_MigrationCustom');
     $this->assertEquals($versionName, $version->getVersion());
 }
 /**
  * Returns the description of a migration.
  *
  * If available it is fetched from the getDescription() method, if that returns an empty value
  * the class docblock is used instead.
  *
  * @param Version $version
  * @param DocCommentParser $parser
  * @return string
  */
 protected function getMigrationDescription(Version $version, DocCommentParser $parser)
 {
     if ($version->getMigration()->getDescription()) {
         return $version->getMigration()->getDescription();
     } else {
         $reflectedClass = new \ReflectionClass($version->getMigration());
         $parser->parseDocComment($reflectedClass->getDocComment());
         return str_replace([chr(10), chr(13)], ' ', $parser->getDescription());
     }
 }
示例#14
0
 protected function checkResultExists($sql, array $params = array(), array $types = array())
 {
     return $this->version->checkResultExists($sql, $params, $types);
 }
示例#15
0
 public function testCatchExceptionDuringMigration()
 {
     $this->outputWriter = $this->getOutputWriter();
     $this->config = new Configuration($this->getSqliteConnection(), $this->outputWriter);
     $this->config->setMigrationsDirectory(\sys_get_temp_dir());
     $this->config->setMigrationsNamespace('DoctrineMigrations\\');
     $version = new Version($this->config, $versionName = '004', 'Doctrine\\DBAL\\Migrations\\Tests\\Stub\\VersionDummyException');
     try {
         $version->execute('up');
     } catch (\Exception $e) {
         $this->assertContains('Migration 004 failed during Execution. Error Super Exception', $this->getOutputStreamContent($this->output));
     }
 }
示例#16
0
 /**
  * Register a single migration version to be executed by a AbstractMigration
  * class.
  *
  * @param string $version  The version of the migration in the format YYYYMMDDHHMMSS.
  * @param string $class    The migration class to execute for the version.
  */
 public function registerMigration($version, $class)
 {
     $version = (string) $version;
     $class = (string) $class;
     if (isset($this->migrations[$version])) {
         throw MigrationException::duplicateMigrationVersion($version, get_class($this->migrations[$version]));
     }
     $version = new Version($this, $version, $class);
     $this->migrations[$version->getVersion()] = $version;
     ksort($this->migrations);
     return $version;
 }