Skip to content

Commit

Permalink
pkp#9069 Updated cleanup to consider a database without the foreign k…
Browse files Browse the repository at this point in the history
…eys from pkp#8333
  • Loading branch information
jonasraoni committed Jun 8, 2023
1 parent 63a7d49 commit b1ba672
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ protected function checkLocaleConflicts(): void
foreach ($affectedLocales as $localeSource => $localeTarget) {
$conflictingSettings = DB::table($tableName)
->select('setting_name', DB::raw('COUNT(*)'))
->when($entityIdColumnName, fn ($query) => $query->addSelect($entityIdColumnName))
->when($entityIdColumnName, fn (Builder $query) => $query->addSelect($entityIdColumnName))
->where('locale', $localeSource)
->orWhere('locale', $localeTarget)
->when(
$entityIdColumnName,
fn ($query) => $query->groupBy($entityIdColumnName, 'setting_name'),
fn ($query) => $query->groupBy('setting_name')
fn (Builder $query) => $query->groupBy($entityIdColumnName, 'setting_name'),
fn (Builder $query) => $query->groupBy('setting_name')
)
->havingRaw('COUNT(*) >= 2')
->get();
Expand Down Expand Up @@ -493,9 +493,12 @@ protected function buildOrphanedEntityProcessor(): void

$this->addTableProcessor('user_groups', function (): int {
$affectedRows = 0;
$ignoreAdministratorUserGroup = fn (Builder $q) => $q->where(
fn (Builder $where) => $where->where('s.context_id', '!=', 0)->orWhere('s.role_id', '!=', 1)
);
// Depends directly on ~1 entities: context_id->context_table.context_id
// Custom field (not found in at least one of the softwares)
$affectedRows += $this->cleanOptionalReference('user_groups', 'context_id', $this->getContextTable(), $this->getContextKeyField(), $this->ignoreZero('context_id'));
$affectedRows += $this->deleteRequiredReference('user_groups', 'context_id', $this->getContextTable(), $this->getContextKeyField(), $ignoreAdministratorUserGroup);
return $affectedRows;
});

Expand Down Expand Up @@ -554,9 +557,9 @@ protected function buildOrphanedEntityProcessor(): void
$affectedRows = 0;
// Depends directly on ~3 entities: context_id->context_table.context_id filter_group_id->filter_groups.filter_group_id parent_filter_id->filters.filter_id
$affectedRows += $this->deleteRequiredReference('filters', 'filter_group_id', 'filter_groups', 'filter_group_id');
$affectedRows += $this->deleteOptionalReference('filters', 'parent_filter_id', 'filters', 'filter_id', $this->ignoreZero('parent_filter_id'));
$affectedRows += $this->deleteRequiredReference('filters', 'parent_filter_id', 'filters', 'filter_id', $this->ignoreZero('parent_filter_id'));
// Custom field (not found in at least one of the softwares)
$affectedRows += $this->deleteOptionalReference('filters', 'context_id', $this->getContextTable(), $this->getContextKeyField(), $this->ignoreZero('context_id'));
$affectedRows += $this->deleteRequiredReference('filters', 'context_id', $this->getContextTable(), $this->getContextKeyField(), $this->ignoreZero('context_id'));
return $affectedRows;
});

Expand All @@ -581,7 +584,7 @@ protected function buildOrphanedEntityProcessor(): void
$affectedRows = 0;
// Depends directly on ~1 entities: context_id->context_table.context_id
// Custom field (not found in at least one of the softwares)
$affectedRows += $this->deleteOptionalReference('navigation_menu_items', 'context_id', $this->getContextTable(), $this->getContextKeyField(), $this->ignoreZero('context_id'));
$affectedRows += $this->deleteRequiredReference('navigation_menu_items', 'context_id', $this->getContextTable(), $this->getContextKeyField(), $this->ignoreZero('context_id'));
return $affectedRows;
});

Expand Down Expand Up @@ -619,7 +622,7 @@ protected function buildOrphanedEntityProcessor(): void
$this->addTableProcessor('email_log', function (): int {
$affectedRows = 0;
// Depends directly on ~1 entities: sender_id->users.user_id
$affectedRows += $this->deleteOptionalReference('email_log', 'sender_id', 'users', 'user_id', $this->ignoreZero('sender_id'));
$affectedRows += $this->deleteRequiredReference('email_log', 'sender_id', 'users', 'user_id', $this->ignoreZero('sender_id'));
return $affectedRows;
});

Expand All @@ -634,7 +637,7 @@ protected function buildOrphanedEntityProcessor(): void
$this->addTableProcessor('event_log', function (): int {
$affectedRows = 0;
// Depends directly on ~1 entities: user_id->users.user_id
$affectedRows += $this->deleteRequiredReference('event_log', 'user_id', 'users', 'user_id');
$affectedRows += $this->deleteOptionalReference('event_log', 'user_id', 'users', 'user_id');
return $affectedRows;
});

Expand All @@ -651,7 +654,7 @@ protected function buildOrphanedEntityProcessor(): void
$affectedRows = 0;
// Depends directly on ~1 entities: context_id->context_table.context_id
// Custom field (not found in at least one of the softwares)
$affectedRows += $this->deleteOptionalReference('navigation_menus', 'context_id', $this->getContextTable(), $this->getContextKeyField(), $this->ignoreZero('context_id'));
$affectedRows += $this->deleteRequiredReference('navigation_menus', 'context_id', $this->getContextTable(), $this->getContextKeyField(), $this->ignoreZero('context_id'));
return $affectedRows;
});

Expand Down Expand Up @@ -835,7 +838,7 @@ protected function buildOrphanedEntityProcessor(): void
$affectedRows = 0;
// Depends directly on ~1 entities: context_id->context_table.context_id
// Custom field (not found in at least one of the softwares)
$affectedRows += $this->deleteOptionalReference('plugin_settings', 'context_id', $this->getContextTable(), $this->getContextKeyField(), $this->ignoreZero('context_id'));
$affectedRows += $this->deleteRequiredReference('plugin_settings', 'context_id', $this->getContextTable(), $this->getContextKeyField(), $this->ignoreZero('context_id'));
return $affectedRows;
});

Expand Down Expand Up @@ -888,7 +891,6 @@ protected function buildOrphanedEntityProcessor(): void
$this->addTableProcessor('review_form_settings', function (): int {
$affectedRows = 0;
// Depends directly on ~1 entities: review_form_id->review_forms.review_form_id

$affectedRows += $this->deleteRequiredReference('review_form_settings', 'review_form_id', 'review_forms', 'review_form_id');
return $affectedRows;
});
Expand Down

0 comments on commit b1ba672

Please sign in to comment.