migrations/Version20191230162753.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20191230162753 extends AbstractMigration
  10. {
  11.     // sales-interviews
  12.     public const REPORT_ID 28;
  13.     public function getDescription(): string
  14.     {
  15.         return '';
  16.     }
  17.     public function up(Schema $schema): void
  18.     {
  19.         // this up() migration is auto-generated, please modify it to your needs
  20.         $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
  21.         $this->addSql('ALTER TABLE user ADD access_customer_entity_role_interviews TINYINT(1) NOT NULL');
  22.         $this->addSql('ALTER TABLE user_group ADD access_customer_entity_role_interviews TINYINT(1) NOT NULL');
  23.         foreach ([
  24.             'user_report' => 'user',
  25.             'group_report' => 'user_group',
  26.         ] as $reportTable => $objectTable) {
  27.             $stmt $this->connection->prepare(sprintf('SELECT * FROM %s WHERE report_id = %d'$reportTableself::REPORT_ID));
  28.             $stmt->execute();
  29.             while ($row $stmt->fetch(\PDO::FETCH_OBJ)) {
  30.                 $this->addSql(sprintf('UPDATE %s SET access_customer_entity_role_interviews = 1 WHERE id = :id'$objectTable), [
  31.                     'id' => $row->object_id,
  32.                 ]);
  33.             }
  34.             $this->addSql(sprintf('DELETE FROM %s WHERE report_id = %d'$reportTableself::REPORT_ID));
  35.         }
  36.         $this->addSql(sprintf('DELETE FROM report WHERE id = %d'self::REPORT_ID));
  37.     }
  38.     public function down(Schema $schema): void
  39.     {
  40.         // this down() migration is auto-generated, please modify it to your needs
  41.         $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
  42.         $this->addSql(sprintf('INSERT INTO report (id, token, name, category, enabled, sort_order) VALUES (%d, \'sales-interviews\', \'Interviews\', \'Sales\', 1, 3)'self::REPORT_ID));
  43.         foreach ([
  44.             'user_report' => 'user',
  45.             'group_report' => 'user_group',
  46.         ] as $reportTable => $objectTable) {
  47.             $stmt $this->connection->prepare(sprintf('SELECT id FROM %s WHERE access_customer_entity_role_interviews = 1'$objectTable));
  48.             $stmt->execute();
  49.             while ($row $stmt->fetch(\PDO::FETCH_OBJ)) {
  50.                 $this->addSql(sprintf('INSERT INTO %s (object_id, report_id) VALUES (:object_id, :report_id)'$reportTable), [
  51.                     'object_id' => $row->id,
  52.                     'report_id' => self::REPORT_ID,
  53.                 ]);
  54.             }
  55.         }
  56.         $this->addSql('ALTER TABLE user DROP access_customer_entity_role_interviews');
  57.         $this->addSql('ALTER TABLE user_group DROP access_customer_entity_role_interviews');
  58.     }
  59. }