Skip to content

Commit

Permalink
Fixed issue #18615: Data integrity SQL syntax error on Postgres when …
Browse files Browse the repository at this point in the history
…trying to fix quotas
  • Loading branch information
c-schmitz committed Jun 8, 2023
1 parent f8edfc9 commit 2077528
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions application/controllers/admin/CheckIntegrity.php
Expand Up @@ -470,8 +470,15 @@ private function deleteQuotaMembers(array $aData)
private function deleteQuotaLanguageSettings(array $aData)
{
$oCriteria = new CDbCriteria();
$oCriteria->join = 'LEFT JOIN {{quota}} q ON {{quota_languagesettings}}.quotals_quota_id=q.id';
$oCriteria->condition = '(q.id IS NULL)';

if (App()->db->driverName == 'pgsql') {
// This is much slower than the MySQL version, but it works
// PostgreSQL does not support DELETE with JOIN
$oCriteria->condition = '{{quota_languagesettings}}.quotals_quota_id not in (select id from {{quota}})';
} else {
$oCriteria->join = 'LEFT JOIN {{quota}} q ON {{quota_languagesettings}}.quotals_quota_id=q.id';
$oCriteria->condition = '(q.id IS NULL)';
}
$count = QuotaLanguageSetting::model()->deleteAll($oCriteria);
$aData['messages'][] = sprintf(gT('Deleting orphaned quota languages: %u quota languages deleted'), $count);
return $aData;
Expand All @@ -485,8 +492,15 @@ private function deleteQuotaLanguageSettings(array $aData)
private function deleteQuotas(array $aData)
{
$oCriteria = new CDbCriteria();
$oCriteria->join = 'LEFT JOIN {{surveys}} q ON {{quota}}.sid=q.sid';
$oCriteria->condition = '(q.sid IS NULL)';

if (App()->db->driverName == 'pgsql') {
// This is much slower than the MySQL version, but it works
// PostgreSQL does not support DELETE with JOIN
$oCriteria->condition = '{{quota}}.sid not in (select sid from {{surveys}})';
} else {
$oCriteria->join = 'LEFT JOIN {{surveys}} q ON {{quota}}.sid=q.sid';
$oCriteria->condition = '(q.sid IS NULL)';
}
$count = Quota::model()->deleteAll($oCriteria);
$aData['messages'][] = sprintf(gT('Deleting orphaned quotas: %u quotas deleted'), $count);
return $aData;
Expand Down

0 comments on commit 2077528

Please sign in to comment.