diff --git a/lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php index 1eba97d48c..3d3c6c1fbb 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php @@ -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) { diff --git a/lib/Alchemy/Phrasea/Core/Version.php b/lib/Alchemy/Phrasea/Core/Version.php index ad36ce78fe..4cff4e295f 100644 --- a/lib/Alchemy/Phrasea/Core/Version.php +++ b/lib/Alchemy/Phrasea/Core/Version.php @@ -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() diff --git a/lib/Alchemy/Phrasea/Model/Entities/User.php b/lib/Alchemy/Phrasea/Model/Entities/User.php index b8c2cc6219..4c91f2ecc8 100644 --- a/lib/Alchemy/Phrasea/Model/Entities/User.php +++ b/lib/Alchemy/Phrasea/Model/Entities/User.php @@ -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; diff --git a/lib/Alchemy/Phrasea/Model/Types/BinaryString.php b/lib/Alchemy/Phrasea/Model/Types/BinaryString.php new file mode 100644 index 0000000000..c9b6788ada --- /dev/null +++ b/lib/Alchemy/Phrasea/Model/Types/BinaryString.php @@ -0,0 +1,43 @@ +getName() === 'mysql') { + return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration)." ". $platform->getCollationFieldDeclaration('utf8_bin'); + } + + return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration); + } + + /** + * {@inheritdoc} + */ + public function getDefaultLength(AbstractPlatform $platform) + { + return $platform->getVarcharDefaultLength(); + } +} diff --git a/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/AggregateTokenMigration.php b/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/AggregateTokenMigration.php new file mode 100644 index 0000000000..76bb5b5b45 --- /dev/null +++ b/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/AggregateTokenMigration.php @@ -0,0 +1,33 @@ +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"); + } +} diff --git a/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/DeleteUsrIdFieldMigration.php b/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/DeleteUsrIdFieldMigration.php index 740e5897df..cf5b46b285 100644 --- a/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/DeleteUsrIdFieldMigration.php +++ b/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/DeleteUsrIdFieldMigration.php @@ -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"); diff --git a/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/PresetMigration.php b/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/PresetMigration.php new file mode 100644 index 0000000000..d9a73625fc --- /dev/null +++ b/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/PresetMigration.php @@ -0,0 +1,33 @@ +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"); + } +} diff --git a/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/UserFieldMigration.php b/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/UserFieldMigration.php index 9e57e02104..fd2715ed20 100644 --- a/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/UserFieldMigration.php +++ b/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/UserFieldMigration.php @@ -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"); diff --git a/lib/Alchemy/Phrasea/Setup/Version/PreSchemaUpgrade/Upgrade39Users.php b/lib/Alchemy/Phrasea/Setup/Version/PreSchemaUpgrade/Upgrade39Users.php index 699e5ab3db..50263adfac 100644 --- a/lib/Alchemy/Phrasea/Setup/Version/PreSchemaUpgrade/Upgrade39Users.php +++ b/lib/Alchemy/Phrasea/Setup/Version/PreSchemaUpgrade/Upgrade39Users.php @@ -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); diff --git a/lib/classes/patch/390alpha14a.php b/lib/classes/patch/390alpha14a.php index 84f0e9e824..d26453d9e2 100644 --- a/lib/classes/patch/390alpha14a.php +++ b/lib/classes/patch/390alpha14a.php @@ -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); } diff --git a/lib/classes/patch/390alpha15a.php b/lib/classes/patch/390alpha15a.php index 3e58e25e18..057a13d380 100644 --- a/lib/classes/patch/390alpha15a.php +++ b/lib/classes/patch/390alpha15a.php @@ -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; } diff --git a/lib/classes/patch/390alpha16a.php b/lib/classes/patch/390alpha16a.php index fe6e6408b3..5e78de9513 100644 --- a/lib/classes/patch/390alpha16a.php +++ b/lib/classes/patch/390alpha16a.php @@ -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]; } diff --git a/lib/classes/patch/390alpha18a.php b/lib/classes/patch/390alpha18a.php new file mode 100644 index 0000000000..97ae8583bb --- /dev/null +++ b/lib/classes/patch/390alpha18a.php @@ -0,0 +1,95 @@ +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; + } +} diff --git a/lib/classes/patch/390alpha1a.php b/lib/classes/patch/390alpha1a.php index b43f976107..419520934c 100644 --- a/lib/classes/patch/390alpha1a.php +++ b/lib/classes/patch/390alpha1a.php @@ -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') diff --git a/lib/classes/patch/390alpha7a.php b/lib/classes/patch/390alpha7a.php index ecdb7e931e..15ca9e2f19 100644 --- a/lib/classes/patch/390alpha7a.php +++ b/lib/classes/patch/390alpha7a.php @@ -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); diff --git a/lib/classes/patch/390alpha9b.php b/lib/classes/patch/390alpha9b.php index 509cf78827..58856fda34 100644 --- a/lib/classes/patch/390alpha9b.php +++ b/lib/classes/patch/390alpha9b.php @@ -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']; diff --git a/lib/classes/patchAbstract.php b/lib/classes/patchAbstract.php index 6fc7a3fdaf..956a119476 100644 --- a/lib/classes/patchAbstract.php +++ b/lib/classes/patchAbstract.php @@ -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 diff --git a/lib/conf.d/migrations.yml b/lib/conf.d/migrations.yml index c63fcd51a0..2cc0b1cde8 100644 --- a/lib/conf.d/migrations.yml +++ b/lib/conf.d/migrations.yml @@ -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