<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20191230162753 extends AbstractMigration
{
// sales-interviews
public const REPORT_ID = 28;
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE user ADD access_customer_entity_role_interviews TINYINT(1) NOT NULL');
$this->addSql('ALTER TABLE user_group ADD access_customer_entity_role_interviews TINYINT(1) NOT NULL');
foreach ([
'user_report' => 'user',
'group_report' => 'user_group',
] as $reportTable => $objectTable) {
$stmt = $this->connection->prepare(sprintf('SELECT * FROM %s WHERE report_id = %d', $reportTable, self::REPORT_ID));
$stmt->execute();
while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) {
$this->addSql(sprintf('UPDATE %s SET access_customer_entity_role_interviews = 1 WHERE id = :id', $objectTable), [
'id' => $row->object_id,
]);
}
$this->addSql(sprintf('DELETE FROM %s WHERE report_id = %d', $reportTable, self::REPORT_ID));
}
$this->addSql(sprintf('DELETE FROM report WHERE id = %d', self::REPORT_ID));
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
$this->addSql(sprintf('INSERT INTO report (id, token, name, category, enabled, sort_order) VALUES (%d, \'sales-interviews\', \'Interviews\', \'Sales\', 1, 3)', self::REPORT_ID));
foreach ([
'user_report' => 'user',
'group_report' => 'user_group',
] as $reportTable => $objectTable) {
$stmt = $this->connection->prepare(sprintf('SELECT id FROM %s WHERE access_customer_entity_role_interviews = 1', $objectTable));
$stmt->execute();
while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) {
$this->addSql(sprintf('INSERT INTO %s (object_id, report_id) VALUES (:object_id, :report_id)', $reportTable), [
'object_id' => $row->id,
'report_id' => self::REPORT_ID,
]);
}
}
$this->addSql('ALTER TABLE user DROP access_customer_entity_role_interviews');
$this->addSql('ALTER TABLE user_group DROP access_customer_entity_role_interviews');
}
}