Skip to content

Commit

Permalink
[Bug]: migration fails for classid column for Pimcore 11 (#75)
Browse files Browse the repository at this point in the history
* fix: class id  column name for 11

* Update src/Migrations/PimcoreX/Version20220914092411.php

Co-authored-by: robertSt7 <[email protected]>

---------

Co-authored-by: robertSt7 <[email protected]>
  • Loading branch information
lukmzig and robertSt7 authored May 11, 2023
1 parent 0951c03 commit 8d8e8de
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Migrations/PimcoreX/Version20220914092411.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 8d8e8de

Please sign in to comment.