From 8d8e8de04ba502e7106ab936aac009922d68ec48 Mon Sep 17 00:00:00 2001 From: lukmzig <30526586+lukmzig@users.noreply.github.com> Date: Thu, 11 May 2023 12:02:15 +0200 Subject: [PATCH] [Bug]: migration fails for classid column for Pimcore 11 (#75) * fix: class id column name for 11 * Update src/Migrations/PimcoreX/Version20220914092411.php Co-authored-by: robertSt7 <104770750+robertSt7@users.noreply.github.com> --------- Co-authored-by: robertSt7 <104770750+robertSt7@users.noreply.github.com> --- .../PimcoreX/Version20220914092411.php | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Migrations/PimcoreX/Version20220914092411.php b/src/Migrations/PimcoreX/Version20220914092411.php index 08ecaf9..87a6b3d 100644 --- a/src/Migrations/PimcoreX/Version20220914092411.php +++ b/src/Migrations/PimcoreX/Version20220914092411.php @@ -33,14 +33,31 @@ protected function getBundleName(): string public function up(Schema $schema): void { $db = Db::get(); - $this->addSql('alter table ' . $db->quoteIdentifier(DAO::TABLE_NAME) . ' modify o_classid varchar(50) null'); + + if ($column = $this->getClassIdColumn($schema)) { + $this->addSql('alter table ' . $db->quoteIdentifier(DAO::TABLE_NAME) . ' modify ' . $column .' varchar(50) null'); + } $this->addSql('alter table ' . $db->quoteIdentifier(DAO::TABLE_NAME) . ' modify ' . $db->quoteIdentifier('description') . ' varchar(255) null'); } public function down(Schema $schema): void { $db = Db::get(); - $this->addSql('alter table ' . $db->quoteIdentifier(DAO::TABLE_NAME) . ' modify o_classid varchar(50) not null'); + if ($column = $this->getClassIdColumn($schema)) { + $this->addSql('alter table ' . $db->quoteIdentifier(DAO::TABLE_NAME) . ' modify ' . $column .' varchar(50) not null'); + } $this->addSql('alter table ' . $db->quoteIdentifier(DAO::TABLE_NAME) . ' modify ' . $db->quoteIdentifier('description') . ' varchar(255) not null;'); } + + private function getClassIdColumn(Schema $schema): ?string + { + $table = $schema->getTable(DAO::TABLE_NAME); + if ($table->hasColumn('o_classid')) { + return 'o_classid'; + } elseif ($table->hasColumn('classId')) { + return 'classId'; + } + + return null; + } }