Skip to content
Code-Schnipsel Gruppen Projekte
Bestätigt Commit 4768f167 erstellt von Jan Wennrich's avatar Jan Wennrich
Dateien durchsuchen

fix: corrects falsy DROP PRIMARY KEY statement in setup


There where syntax errors in the SQL statement.
Furthermore the primary keys are only dropped if they exist.
This prevents unnecessary errors/messages in the logs.

Co-authored-by: default avatarAdrian Müller <adrian@pcsg.de>
Übergeordneter 072c89de
No related branches found
No related tags found
1 Merge Request!8fix: corrects falsy DROP PRIMARY KEY statement in setup
......@@ -225,6 +225,8 @@ public static function onPackageSetup(QUI\Package\Package $Package)
// unique bricks cache patch
$projects = QUI::getProjectManager()->getProjectList();
$databaseName = QUI::getDataBase()->getAttribute('dbname');
foreach ($projects as $Project) {
$projectCacheTable = QUI::getDBProjectTableName(
Manager::TABLE_CACHE,
......@@ -232,9 +234,19 @@ public static function onPackageSetup(QUI\Package\Package $Package)
);
try {
QUI::getDataBase()->fetchSQL(
"`ALTER TABLE ``{$projectCacheTable}`` DROP PRIMARY KEY;`"
);
$primaryExists = QUI::getDataBase()->fetchSQL("
SELECT COUNT(constraint_type) AS primary_key_count FROM information_schema.table_constraints
WHERE constraint_type = 'PRIMARY KEY'
AND table_name = '{$projectCacheTable}'
AND TABLE_SCHEMA = '{$databaseName}'
");
$isPrimaryKeyExisting = \boolval($primaryExists[0]['primary_key_count']);
// Primary key should only be dropped if it exists
if ($isPrimaryKeyExisting) {
QUI::getDataBase()->fetchSQL("ALTER TABLE `{$projectCacheTable}` DROP PRIMARY KEY;");
}
} catch (QUI\Exception $Exception) {
QUI\System\Log::addInfo($Exception->getMessage());
}
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren