2024-03-19 12:07:45 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace D3\DecodeMigrations\migration\data;
|
|
|
|
|
|
|
|
use Doctrine\DBAL\Exception;
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
2024-03-22 15:31:30 +01:00
|
|
|
use Doctrine\DBAL\Types\BlobType;
|
2024-03-19 12:07:45 +01:00
|
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Auto-generated Migration: Please modify to your needs!
|
|
|
|
*/
|
|
|
|
final class Version20240319113842 extends AbstractMigration
|
|
|
|
{
|
|
|
|
public function getDescription() : string
|
|
|
|
{
|
|
|
|
return 'decode / encode user payment columns';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function up(Schema $schema) : void
|
|
|
|
{
|
|
|
|
$this->skipIf($this->connection->getDatabasePlatform() instanceof MySQL80Platform, 'Userpayment values can\'t decoded on MySQL 8');
|
|
|
|
|
|
|
|
$this->connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
|
|
|
|
|
|
|
|
$table = $schema->getTable('oxuserpayments');
|
|
|
|
$column = $table->getColumn('oxvalue');
|
|
|
|
|
|
|
|
$this->skipIf(!$column->getType() instanceof BlobType, 'Userpayment values are already decoded');
|
|
|
|
|
|
|
|
$this->addSql('ALTER TABLE oxuserpayments ADD COLUMN `OXVALUE_UNENC` text;');
|
2024-03-19 16:06:34 +01:00
|
|
|
$this->addSql("UPDATE oxuserpayments SET `OXVALUE_UNENC` = DECODE(OXVALUE, 'fq45QS09_fqyx09239QQ') WHERE 1;");
|
2024-03-19 12:07:45 +01:00
|
|
|
$this->addSql('ALTER TABLE oxuserpayments MODIFY COLUMN `OXVALUE` text;');
|
|
|
|
$this->addSql("UPDATE oxuserpayments SET `OXVALUE` = `OXVALUE_UNENC` WHERE 1;");
|
|
|
|
$this->addSql('ALTER TABLE oxuserpayments DROP COLUMN `OXVALUE_UNENC`;');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function down(Schema $schema): void
|
|
|
|
{
|
|
|
|
$this->skipIf($this->connection->getDatabasePlatform() instanceof MySQL80Platform, 'Userpayment values can\'t encoded on MySQL 8');
|
|
|
|
|
|
|
|
$this->connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
|
|
|
|
|
|
|
|
$table = $schema->getTable('oxuserpayments');
|
|
|
|
$column = $table->getColumn('oxvalue');
|
|
|
|
|
|
|
|
$this->skipIf($column->getType() instanceof BlobType, 'Userpayment values are already encoded');
|
|
|
|
|
|
|
|
$this->addSql('ALTER TABLE oxuserpayments ADD COLUMN `OXVALUE_ENC` text;');
|
2024-03-19 16:06:34 +01:00
|
|
|
$this->addSql("UPDATE oxuserpayments SET `OXVALUE_ENC` = ENCODE(OXVALUE, 'fq45QS09_fqyx09239QQ') WHERE 1;");
|
2024-03-19 12:07:45 +01:00
|
|
|
$this->addSql('ALTER TABLE oxuserpayments MODIFY COLUMN `OXVALUE` blob;');
|
|
|
|
$this->addSql("UPDATE oxuserpayments SET `OXVALUE` = `OXVALUE_ENC` WHERE 1;");
|
|
|
|
$this->addSql('ALTER TABLE oxuserpayments DROP COLUMN `OXVALUE_ENC`;');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isTransactional(): bool
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|