8000 Drop the `guests` column after migration by aschempp · Pull Request #8365 · contao/contao · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Drop the guests column after migration #8365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 5.3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public function shouldRun(): bool

$columns = $schemaManager->listTableColumns($table);

if (!isset($columns['guests'], $columns['groups'])) {
if (!isset($columns['guests'], $columns['groups'], $columns['protected'])) {
continue;
}

$test = $this->connection->fetchOne("
SELECT TRUE
FROM $table
WHERE `guests`='1' AND (`groups` IS NULL OR `groups` NOT LIKE '%\"-1\"%')
WHERE `guests`='1'
LIMIT 1
");

Expand All @@ -70,27 +70,29 @@ public function run(): MigrationResult

$columns = $schemaManager->listTableColumns($table);

if (!isset($columns['guests'], $columns['groups'])) {
if (!isset($columns['guests'], $columns['groups'], $columns['protected'])) {
continue;
}

$values = $this->connection->fetchAllKeyValue("
SELECT id, `groups`
$values = $this->connection->fetchAllAssociative("
SELECT id, protected, `groups`
FROM $table
WHERE `guests`='1' AND (`groups` IS NULL OR `groups` NOT LIKE '%\"-1\"%')
WHERE `guests`='1'
");

foreach ($values as $id => $value) {
$groups = StringUtil::deserialize($value, true);
foreach ($values as $row) {
$groups = $row['protected'] ? StringUtil::deserialize($row['groups'], true) : [];
$groups[] = '-1';

$data = [
'protected' => 1,
'`groups`' => serialize($groups),
];

$this->connection->update($table, $data, ['id' => (int) $id]);
$this->connection->update($table, $data, ['id' => (int) $row['id']]);
}

$this->connection->executeStatement("ALTER TABLE $table DROP COLUMN `guests`");
}

return $this->createResult(true);
Expand Down
0