Merge pull request #1032 from nlegoff/fix-migration

[READY][3.9] Fix some patch migration issues
This commit is contained in:
Nicolas Le Goff
2014-03-23 19:08:07 +01:00
18 changed files with 256 additions and 31 deletions

View File

@@ -168,6 +168,7 @@ class ORMServiceProvider implements ServiceProviderInterface
'longblob' => 'Alchemy\Phrasea\Model\Types\LongBlob',
'varbinary' => 'Alchemy\Phrasea\Model\Types\VarBinary',
'binary' => 'Alchemy\Phrasea\Model\Types\Binary',
'binary_string' => 'Alchemy\Phrasea\Model\Types\BinaryString',
];
foreach ($types as $type => $class) {

View File

@@ -13,7 +13,7 @@ namespace Alchemy\Phrasea\Core;
class Version
{
protected static $number = '3.9.0-alpha.16';
protected static $number = '3.9.0-alpha.18';
protected static $name = 'Epanterias';
public static function getNumber()

View File

@@ -51,7 +51,7 @@ class User
private $id;
/**
* @ORM\Column(type="string", length=128)
* @ORM\Column(type="binary_string", length=128)
*/
private $login;
@@ -61,12 +61,14 @@ class User
private $email;
/**
* @ORM\Column(type="string", length=128, nullable=true)
* The password can be null when the user is a template.
*
* @ORM\Column(type="binary_string", length=128, nullable=true)
*/
private $password;
/**
* @ORM\Column(type="string", length=64, nullable=true)
* @ORM\Column(type="binary_string", length=64, nullable=true)
*/
private $nonce;

View File

@@ -0,0 +1,43 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Model\Types;
use Alchemy\Phrasea\Exception\RuntimeException;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class BinaryString extends Type
{
const BINARY_STRING = 'binary_string';
public function getName()
{
return static::BINARY_STRING;
}
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
if ($platform->getName() === 'mysql') {
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration)." ". $platform->getCollationFieldDeclaration('utf8_bin');
}
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
}
/**
* {@inheritdoc}
*/
public function getDefaultLength(AbstractPlatform $platform)
{
return $platform->getVarcharDefaultLength();
}
}

View File

@@ -0,0 +1,33 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Setup\DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
class AggregateTokenMigration extends AbstractMigration
{
public function isAlreadyApplied()
{
return $this->tableExists('AggregateTokens');
}
public function doUpSql(Schema $schema)
{
$this->addSql("CREATE TABLE AggregateTokens (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, value VARCHAR(64) DEFAULT NULL, INDEX IDX_4232BC51A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("ALTER TABLE AggregateTokens ADD CONSTRAINT FK_4232BC51A76ED395 FOREIGN KEY (user_id) REFERENCES Users (id)");
}
public function doDownSql(Schema $schema)
{
$this->addSql("DROP TABLE AggregateTokens");
}
}

View File

@@ -37,7 +37,6 @@ class DeleteUsrIdFieldMigration extends AbstractMigration
$this->addSql("ALTER TABLE LazaretSessions DROP usr_id");
$this->addSql("ALTER TABLE ValidationParticipants DROP usr_id");
$this->addSql("ALTER TABLE FeedPublishers DROP usr_id");
$this->addSql("ALTER TABLE AggregateTokens DROP usr_id");
$this->addSql("ALTER TABLE FtpExports DROP usr_id");
$this->addSql("DROP INDEX unique_provider_per_user ON UsrAuthProviders");
$this->addSql("ALTER TABLE UsrAuthProviders DROP usr_id");
@@ -50,7 +49,6 @@ class DeleteUsrIdFieldMigration extends AbstractMigration
public function doDownSql(Schema $schema)
{
$this->addSql("ALTER TABLE AggregateTokens ADD usr_id INT NOT NULL");
$this->addSql("ALTER TABLE Baskets ADD usr_id INT NOT NULL");
$this->addSql("ALTER TABLE FeedPublishers ADD usr_id INT NOT NULL");
$this->addSql("ALTER TABLE FeedTokens ADD usr_id INT NOT NULL");

View File

@@ -0,0 +1,33 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Setup\DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
class PresetMigration extends AbstractMigration
{
public function isAlreadyApplied()
{
return $this->tableExists('Presets');
}
public function doUpSql(Schema $schema)
{
$this->addSql("CREATE TABLE Presets (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, sbas_id INT NOT NULL, title VARCHAR(128) NOT NULL, data LONGTEXT NOT NULL, created DATETIME NOT NULL, INDEX IDX_1C48F8F3A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("ALTER TABLE Presets ADD CONSTRAINT FK_1C48F8F3A76ED395 FOREIGN KEY (user_id) REFERENCES Users (id)");
}
public function doDownSql(Schema $schema)
{
$this->addSql("DROP TABLE Presets");
}
}

View File

@@ -36,8 +36,6 @@ class UserFieldMigration extends AbstractMigration
$this->addSql("CREATE INDEX IDX_17850D7BA76ED395 ON ValidationParticipants (user_id)");
$this->addSql("ALTER TABLE FeedPublishers ADD CONSTRAINT FK_31AFAB2A76ED395 FOREIGN KEY (user_id) REFERENCES Users (id)");
$this->addSql("CREATE INDEX IDX_31AFAB2A76ED395 ON FeedPublishers (user_id)");
$this->addSql("ALTER TABLE AggregateTokens ADD CONSTRAINT FK_4232BC51A76ED395 FOREIGN KEY (user_id) REFERENCES Users (id)");
$this->addSql("CREATE INDEX IDX_4232BC51A76ED395 ON AggregateTokens (user_id)");
$this->addSql("ALTER TABLE FtpExports ADD CONSTRAINT FK_CFCEEE7AA76ED395 FOREIGN KEY (user_id) REFERENCES Users (id)");
$this->addSql("CREATE INDEX IDX_CFCEEE7AA76ED395 ON FtpExports (user_id)");
$this->addSql("ALTER TABLE UsrAuthProviders ADD CONSTRAINT FK_947F003FA76ED395 FOREIGN KEY (user_id) REFERENCES Users (id)");
@@ -50,8 +48,6 @@ class UserFieldMigration extends AbstractMigration
public function doDownSql(Schema $schema)
{
$this->addSql("ALTER TABLE AggregateTokens DROP FOREIGN KEY FK_4232BC51A76ED395");
$this->addSql("DROP INDEX IDX_4232BC51A76ED395 ON AggregateTokens");
$this->addSql("ALTER TABLE Baskets DROP FOREIGN KEY FK_13461873A76ED395");
$this->addSql("DROP INDEX IDX_13461873A76ED395 ON Baskets");
$this->addSql("ALTER TABLE FeedPublishers DROP FOREIGN KEY FK_31AFAB2A76ED395");

View File

@@ -73,7 +73,6 @@ class Upgrade39Users implements PreSchemaUpgradeInterface
*/
public function rollback(EntityManager $em, \appbox $appbox, Configuration $conf)
{
$this->renameTable($em, 'down');
// truncate created tables
$this->emptyTables($em);
// rollback schema
@@ -124,14 +123,14 @@ class Upgrade39Users implements PreSchemaUpgradeInterface
private function alterTablesDown(EntityManager $em)
{
foreach ([
'Baskets' => "ALTER TABLE Baskets CHANGE user_id usr_id",
'LazaretSessions' => "ALTER TABLE LazaretSessions CHANGE user_id usr_id",
'Sessions' => "ALTER TABLE Sessions CHANGE user_id usr_id",
'StoryWZ' => "ALTER TABLE StoryWZ CHANGE user_id usr_id",
'UsrAuthProviders' => "ALTER TABLE UsrAuthProviders CHANGE user_id usr_id",
'UsrListOwners' => "ALTER TABLE UsrListOwners CHANGE user_id usr_id",
'UsrListsContent' => "ALTER TABLE UsrListsContent CHANGE user_id usr_id",
'ValidationParticipants' => "ALTER TABLE ValidationParticipants CHANGE user_id usr_id",
'Baskets' => "ALTER TABLE Baskets CHANGE user_id usr_id INT DEFAULT NULL",
'LazaretSessions' => "ALTER TABLE LazaretSessions CHANGE user_id usr_id INT DEFAULT NULL",
'Sessions' => "ALTER TABLE Sessions CHANGE user_id usr_id INT DEFAULT NULL",
'StoryWZ' => "ALTER TABLE StoryWZ CHANGE user_id usr_id INT DEFAULT NULL",
'UsrAuthProviders' => "ALTER TABLE UsrAuthProviders CHANGE user_id usr_id INT DEFAULT NULL",
'UsrListOwners' => "ALTER TABLE UsrListOwners CHANGE user_id usr_id INT DEFAULT NULL",
'UsrListsContent' => "ALTER TABLE UsrListsContent CHANGE user_id usr_id INT DEFAULT NULL",
'ValidationParticipants' => "ALTER TABLE ValidationParticipants CHANGE user_id usr_id INT DEFAULT NULL",
] as $table => $sql) {
if ($this->tableExists($em, $table)) {
$em->getConnection()->executeUpdate($sql);

View File

@@ -59,7 +59,7 @@ class patch_390alpha14a extends patchAbstract
$app['conf']->remove(['main', 'api-timers']);
if ($this->tableHasField($app['EM'], 'api_logs', 'api_log_ressource')) {
$sql = 'UPDATE api_logs SET api_log_resource = api_log_ressource';
$sql = "ALTER TABLE api_logs CHANGE api_log_ressource api_log_resource varchar(64)";
$app['phraseanet.appbox']->get_connection()->executeUpdate($sql);
}

View File

@@ -60,10 +60,19 @@ class patch_390alpha15a extends patchAbstract
return true;
}
$sql = 'INSERT INTO Tokens
(value, user_id, type, data, created, updated, expiration)
(SELECT value, usr_id, type, datas, created_on, created_on, expire_on FROM tokens_backup)';
$appbox->get_connection()->exec($sql);
$app['EM']->getConnection()->executeUpdate('
INSERT INTO Tokens
(
`value`, user_id, `type`, `data`,
created, updated, expiration
)
(
SELECT
tb.`value`, tb.usr_id, tb.`type`, tb.datas,
tb.created_on, tb.created_on, tb.expire_on
FROM tokens_backup tb
INNER JOIN Users u ON (u.id = tb.usr_id)
)');
return true;
}

View File

@@ -50,7 +50,7 @@ class patch_390alpha16a extends patchAbstract
*/
public function getDoctrineMigrations()
{
return [];
return ['preset'];
}
/**
@@ -58,7 +58,7 @@ class patch_390alpha16a extends patchAbstract
*/
public function apply(base $appbox, Application $app)
{
$sql = ' SELECT edit_preset_id, creation_date, title, xml
$sql = ' SELECT edit_preset_id, creation_date, title, xml, usr_id, sbas_id
FROM edit_presets';
$em = $app['EM'];
@@ -74,6 +74,9 @@ class patch_390alpha16a extends patchAbstract
$preset->setTitle($row['title']);
$fields = [];
if (false !== ($sx = @simplexml_load_string($row['xml']))) {
if (false === isset($sx->fields)) {
continue;
}
foreach ($sx->fields->children() as $name => $value) {
$fields[] = ['name' => $name, 'value' => $value];
}

View File

@@ -0,0 +1,95 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\Preset;
use Gedmo\Timestampable\TimestampableListener;
class patch_390alpha18a extends patchAbstract
{
/** @var string */
private $release = '3.9.0-alpha.18';
/** @var array */
private $concern = [base::APPLICATION_BOX];
/**
* {@inheritdoc}
*/
public function get_release()
{
return $this->release;
}
/**
* {@inheritdoc}
*/
public function require_all_upgrades()
{
return false;
}
/**
* {@inheritdoc}
*/
public function concern()
{
return $this->concern;
}
/**
* {@inheritdoc}
*/
public function getDoctrineMigrations()
{
return ['user', 'lazaret', 'feed', 'session'];
}
/**
* {@inheritdoc}
*/
public function apply(base $appbox, Application $app)
{
$app['EM']->getConnection()->executeUpdate('
DELETE lf FROM LazaretFiles lf
INNER JOIN LazaretSessions ls ON (ls.id = lf.lazaret_session_id)
LEFT JOIN Users u ON (ls.user_id = u.id)
WHERE u.id IS NULL'
);
$app['EM']->getConnection()->executeUpdate('
DELETE ls FROM LazaretSessions AS ls
LEFT JOIN Users u ON (ls.user_id = u.id)
WHERE u.id IS NULL'
);
$app['EM']->getConnection()->executeUpdate('
DELETE fi FROM FeedItems AS fi
INNER JOIN FeedEntries fe ON (fe.id = fi.entry_id)
LEFT JOIN Users u ON (fe.publisher_id = u.id)
WHERE u.id IS NULL'
);
$app['EM']->getConnection()->executeUpdate('
DELETE fe FROM FeedEntries AS fe
LEFT JOIN Users u ON (fe.publisher_id = u.id)
WHERE u.id IS NULL'
);
$app['EM']->getConnection()->executeUpdate(
'DELETE se FROM Sessions AS se
LEFT JOIN Users u ON (se.user_id = u.id)
WHERE u.id IS NULL'
);
return true;
}
}

View File

@@ -12,9 +12,11 @@
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\Order;
use Alchemy\Phrasea\Model\Entities\OrderElement;
use Doctrine\ORM\Query;
use Doctrine\ORM\NoResultException;
use Gedmo\Timestampable\TimestampableListener;
class patch_390alpha1a extends patchAbstract
{
/** @var string */
@@ -92,7 +94,9 @@ class patch_390alpha1a extends patchAbstract
$todo = $stmt->fetch(\PDO::FETCH_ASSOC);
$stmt->closeCursor();
$user = $this->loadUser($app['EM'], $row['usr_id']);
if (null === $user = $this->loadUser($app['EM'], $row['usr_id'])) {
continue;
}
try {
$basket = $app['EM']->createQuery('SELECT PARTIAL b.{id} FROM Phraseanet:Basket b WHERE b.id = :id')

View File

@@ -55,7 +55,7 @@ class patch_390alpha7a extends patchAbstract
*/
public function getDoctrineMigrations()
{
return ['feed'];
return ['aggregate-token', 'feed'];
}
/**
@@ -127,7 +127,7 @@ class patch_390alpha7a extends patchAbstract
$feed->setIsPublic($row['public']);
$feed->setCreatedOn(new \DateTime($row['created_on']));
$feed->setUpdatedOn(new \DateTime($row['updated_on']));
$feed->setCollection($row['base_id'] ? collection::get_from_base_id($app, $row['base_id']) : null);
$feed->setBaseId($row['base_id']);
$fpStmt->execute([':feed_id' => $row['id']]);
$fpRes = $fpStmt->fetchAll(\PDO::FETCH_ASSOC);

View File

@@ -195,8 +195,10 @@ class patch_390alpha9b extends patchAbstract
unset($config['main']['languages']);
}
$config = array_merge(['servername' => $config['main']['servername']], $config);
unset($config['main']['servername']);
if (isset($config['main']['servername'])) {
$config = array_merge(['servername' => $config['main']['servername']], $config);
unset($config['main']['servername']);
}
if (isset($config['task-manager'])) {
$config['main']['task-manager'] = $config['task-manager'];

View File

@@ -11,6 +11,7 @@
use Doctrine\ORM\NoResultException;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\ResultSetMapping;
abstract class patchAbstract implements patchInterface

View File

@@ -60,3 +60,9 @@ migrations:
migration19:
version: token
class: Alchemy\Phrasea\Setup\DoctrineMigrations\TokenMigration
migration21:
version: aggregate-token
class: Alchemy\Phrasea\Setup\DoctrineMigrations\AggregateTokenMigration
migration22:
version: preset
class: Alchemy\Phrasea\Setup\DoctrineMigrations\PresetMigration