PK (CVds phpunit.xml.distnu W+A
./tests/Doctrine/
./lib/
200
10
PK (CVDu * lib/Doctrine/DBAL/Migrations/Migration.phpnu W+A .
*/
namespace Doctrine\DBAL\Migrations;
use Doctrine\DBAL\Migrations\Configuration\Configuration;
/**
* Class for running migrations to the current version or a manually specified version.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @author Jonathan H. Wage
*/
class Migration
{
/**
* The OutputWriter object instance used for outputting information
*
* @var OutputWriter
*/
private $outputWriter;
/**
* @var Configuration
*/
private $configuration;
/**
* @var boolean
*/
private $noMigrationException;
/**
* Construct a Migration instance
*
* @param Configuration $configuration A migration Configuration instance
*/
public function __construct(Configuration $configuration)
{
$this->configuration = $configuration;
$this->outputWriter = $configuration->getOutputWriter();
$this->noMigrationException = false;
}
/**
* Get the array of versions and SQL queries that would be executed for
* each version but do not execute anything.
*
* @param string $to The version to migrate to.
*
* @return array $sql The array of SQL queries.
*/
public function getSql($to = null)
{
return $this->migrate($to, true);
}
/**
* Write a migration SQL file to the given path
*
* @param string $path The path to write the migration SQL file.
* @param string $to The version to migrate to.
*
* @return boolean $written
*/
public function writeSqlFile($path, $to = null)
{
$sql = $this->getSql($to);
$from = $this->configuration->getCurrentVersion();
if ($to === null) {
$to = $this->configuration->getLatestVersion();
}
$direction = $from > $to ? Version::DIRECTION_DOWN : Version::DIRECTION_UP;
$this->outputWriter->write(sprintf("# Migrating from %s to %s\n", $from, $to));
$sqlWriter = new SqlFileWriter(
$this->configuration->getMigrationsColumnName(),
$this->configuration->getMigrationsTableName(),
$path,
$this->outputWriter
);
return $sqlWriter->write($sql, $direction);
}
/**
* @param boolean $noMigrationException Throw an exception or not if no migration is found. Mostly for Continuous Integration.
*/
public function setNoMigrationException($noMigrationException = false)
{
$this->noMigrationException = $noMigrationException;
}
/**
* Run a migration to the current version or the given target version.
*
* @param string $to The version to migrate to.
* @param boolean $dryRun Whether or not to make this a dry run and not execute anything.
* @param boolean $timeAllQueries Measuring or not the execution time of each SQL query.
*
* @return array $sql The array of migration sql statements
*
* @throws MigrationException
*/
public function migrate($to = null, $dryRun = false, $timeAllQueries = false)
{
/**
* If no version to migrate to is given we default to the last available one.
*/
if ($to === null) {
$to = $this->configuration->getLatestVersion();
}
$from = (string) $this->configuration->getCurrentVersion();
$to = (string) $to;
/**
* Throw an error if we can't find the migration to migrate to in the registered
* migrations.
*/
$migrations = $this->configuration->getMigrations();
if (!isset($migrations[$to]) && $to > 0) {
throw MigrationException::unknownMigrationVersion($to);
}
$direction = $from > $to ? Version::DIRECTION_DOWN : Version::DIRECTION_UP;
$migrationsToExecute = $this->configuration->getMigrationsToExecute($direction, $to);
/**
* If
* there are no migrations to execute
* and there are migrations,
* and the migration from and to are the same
* means we are already at the destination return an empty array()
* to signify that there is nothing left to do.
*/
if ($from === $to && empty($migrationsToExecute) && !empty($migrations)) {
return [];
}
$output = $dryRun ? 'Executing dry run of migration' : 'Migrating';
$output .= ' %s to %s from %s';
$this->outputWriter->write(sprintf($output, $direction, $to, $from));
/**
* If there are no migrations to execute throw an exception.
*/
if (empty($migrationsToExecute) && !$this->noMigrationException) {
throw MigrationException::noMigrationsToExecute();
}
$sql = [];
$time = 0;
foreach ($migrationsToExecute as $version) {
$versionSql = $version->execute($direction, $dryRun, $timeAllQueries);
$sql[$version->getVersion()] = $versionSql;
$time += $version->getTime();
}
$this->outputWriter->write("\n ------------------------\n");
$this->outputWriter->write(sprintf(" ++ finished in %ss", $time));
$this->outputWriter->write(sprintf(" ++ %s migrations executed", count($migrationsToExecute)));
$this->outputWriter->write(sprintf(" ++ %s sql queries", count($sql, true) - count($sql)));
return $sql;
}
}
PK (CVYPL_g g @ lib/Doctrine/DBAL/Migrations/Configuration/YamlConfiguration.phpnu W+A .
*/
namespace Doctrine\DBAL\Migrations\Configuration;
use Symfony\Component\Yaml\Yaml;
/**
* Load migration configuration information from a YAML configuration file.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @author Jonathan H. Wage
*/
class YamlConfiguration extends AbstractFileConfiguration
{
/**
* @inheritdoc
*/
protected function doLoad($file)
{
$config = Yaml::parse(file_get_contents($file));
if (!is_array($config)) {
throw new \InvalidArgumentException('Not valid configuration.');
}
if (isset($config['migrations_directory'])) {
$config['migrations_directory'] = $this->getDirectoryRelativeToFile($file, $config['migrations_directory']);
}
$this->setConfiguration($config);
}
}
PK (CV H lib/Doctrine/DBAL/Migrations/Configuration/AbstractFileConfiguration.phpnu W+A .
*/
namespace Doctrine\DBAL\Migrations\Configuration;
use Doctrine\DBAL\Migrations\MigrationException;
/**
* Abstract Migration Configuration class for loading configuration information
* from a configuration file (xml or yml).
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @author Jonathan H. Wage
*/
abstract class AbstractFileConfiguration extends Configuration
{
/**
* The configuration file used to load configuration information
*
* @var string
*/
private $file;
/**
* Whether or not the configuration file has been loaded yet or not
*
* @var boolean
*/
private $loaded = false;
/**
* @var array of possible configuration properties in migrations configuration.
*/
private $configurationProperties = [
'migrations_namespace' => 'setMigrationsNamespace',
'table_name' => 'setMigrationsTableName',
'column_name' => 'setMigrationsColumnName',
'organize_migrations' => 'setMigrationOrganisation',
'name' => 'setName',
'migrations_directory' => 'loadMigrationsFromDirectory',
'migrations' => 'loadMigrations',
];
protected function setConfiguration(Array $config)
{
foreach($config as $configurationKey => $configurationValue) {
if (!isset($this->configurationProperties[$configurationKey])) {
$msg = sprintf('Migrations configuration key "%s" does not exists.', $configurationKey);
throw MigrationException::configurationNotValid($msg);
}
}
foreach($this->configurationProperties as $configurationKey => $configurationSetter) {
if (isset($config[$configurationKey])) {
$this->{$configurationSetter}($config[$configurationKey]);
}
}
}
private function loadMigrationsFromDirectory($migrationsDirectory)
{
$this->setMigrationsDirectory($migrationsDirectory);
$this->registerMigrationsFromDirectory($migrationsDirectory);
}
private function loadMigrations($migrations)
{
if (is_array($migrations)) {
foreach ($migrations as $migration) {
$this->registerMigration($migration['version'], $migration['class']);
}
}
}
private function setMigrationOrganisation($migrationOrganisation)
{
if (strcasecmp($migrationOrganisation, static::VERSIONS_ORGANIZATION_BY_YEAR) == 0) {
$this->setMigrationsAreOrganizedByYear();
} else if (strcasecmp($migrationOrganisation, static::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH) == 0) {
$this->setMigrationsAreOrganizedByYearAndMonth();
} else {
$msg = 'Unknown ' . var_export($migrationOrganisation, true) . ' for configuration "organize_migrations".';
throw MigrationException::configurationNotValid($msg);
}
}
/**
* Load the information from the passed configuration file
*
* @param string $file The path to the configuration file
*
* @throws MigrationException Throws exception if configuration file was already loaded
*/
public function load($file)
{
if ($this->loaded) {
throw MigrationException::configurationFileAlreadyLoaded();
}
if (file_exists($path = getcwd() . '/' . $file)) {
$file = $path;
}
$this->file = $file;
if (!file_exists($file)) {
throw new \InvalidArgumentException('Given config file does not exist');
}
$this->doLoad($file);
$this->loaded = true;
}
protected function getDirectoryRelativeToFile($file, $input)
{
$path = realpath(dirname($file) . '/' . $input);
return ($path !== false) ? $path : $input;
}
public function getFile()
{
return $this->file;
}
/**
* Abstract method that each file configuration driver must implement to
* load the given configuration file whether it be xml, yaml, etc. or something
* else.
*
* @param string $file The path to a configuration file.
*/
abstract protected function doLoad($file);
}
PK (CVxb b ^ lib/Doctrine/DBAL/Migrations/Configuration/Connection/Loader/ConnectionConfigurationLoader.phpnu W+A .
*/
namespace Doctrine\DBAL\Migrations\Configuration\Connection\Loader;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Migrations\Configuration\Configuration;
use Doctrine\DBAL\Migrations\Configuration\Connection\ConnectionLoaderInterface;
class ConnectionConfigurationLoader implements ConnectionLoaderInterface
{
/** @var Configuration */
private $configuration;
public function __construct(Configuration $configuration=null)
{
if ($configuration !== null) {
$this->configuration = $configuration;
}
}
/**
* read the input and return a Configuration, returns `false` if the config
* is not supported
* @return Connection|null
*/
public function chosen()
{
if ($this->configuration) {
return $this->configuration->getConnection();
}
return null;
}
}
PK (CV;^ c lib/Doctrine/DBAL/Migrations/Configuration/Connection/Loader/ConnectionConfigurationChainLoader.phpnu W+A .
*/
namespace Doctrine\DBAL\Migrations\Configuration\Connection\Loader;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Migrations\Configuration\Connection\ConnectionLoaderInterface;
final class ConnectionConfigurationChainLoader implements ConnectionLoaderInterface
{
/** @var ConnectionLoaderInterface[] */
private $loaders;
public function __construct(array $loaders)
{
$this->loaders = $loaders;
}
/**
* read the input and return a Configuration, returns `false` if the config
* is not supported
* @return Connection|null
*/
public function chosen()
{
foreach($this->loaders as $loader) {
if (null !== $confObj = $loader->chosen()) {
return $confObj;
}
}
return null;
}
}
PK (CV>" c lib/Doctrine/DBAL/Migrations/Configuration/Connection/Loader/ArrayConnectionConfigurationLoader.phpnu W+A .
*/
namespace Doctrine\DBAL\Migrations\Configuration\Connection\Loader;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Migrations\Configuration\Connection\ConnectionLoaderInterface;
class ArrayConnectionConfigurationLoader implements ConnectionLoaderInterface
{
private $filename;
public function __construct($filename)
{
$this->filename = $filename;
}
/**
* read the input and return a Configuration, returns `false` if the config
* is not supported
* @return Connection|null
*/
public function chosen()
{
if (empty($this->filename)) {
return null;
}
if (!file_exists($this->filename)) {
return null;
}
$params = include $this->filename;
if (!is_array($params)) {
throw new \InvalidArgumentException('The connection file has to return an array with database configuration parameters.');
}
return DriverManager::getConnection($params);
}
}
PK (CVTjo# W lib/Doctrine/DBAL/Migrations/Configuration/Connection/Loader/ConnectionHelperLoader.phpnu W+A .
*/
namespace Doctrine\DBAL\Migrations\Configuration\Connection\Loader;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Migrations\Configuration\Connection\ConnectionLoaderInterface;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Symfony\Component\Console\Helper\HelperSet;
class ConnectionHelperLoader implements ConnectionLoaderInterface
{
/**
* @var string
*/
private $helperName;
/** @var HelperSet */
private $helperSet;
/**
* ConnectionHelperLoader constructor.
* @param HelperSet $helperSet
* @param string $helperName
*/
public function __construct(HelperSet $helperSet = null, $helperName)
{
$this->helperName = $helperName;
if ($helperSet === null) {
$helperSet = new HelperSet();
}
$this->helperSet = $helperSet;
}
/**
* read the input and return a Configuration, returns `false` if the config
* is not supported
* @return Connection|null
*/
public function chosen()
{
if ($this->helperSet->has($this->helperName)) {
$connectionHelper = $this->helperSet->get($this->helperName);
if ($connectionHelper instanceof ConnectionHelper) {
return $connectionHelper->getConnection();
}
}
return null;
}
}
PK (CVK S lib/Doctrine/DBAL/Migrations/Configuration/Connection/ConnectionLoaderInterface.phpnu W+A .
*/
namespace Doctrine\DBAL\Migrations\Configuration\Connection;
use Doctrine\DBAL\Connection;
interface ConnectionLoaderInterface
{
/**
* read the input and return a Configuration, returns `false` if the config
* is not supported
* @return Connection|null
*/
public function chosen();
}
PK (CVکVH H @ lib/Doctrine/DBAL/Migrations/Configuration/XML/configuration.xsdnu W+A
PK (CV1N_ _ <