From 8687d5cc021d3412174c695eb31d186634de0376 Mon Sep 17 00:00:00 2001 From: Tom Levy Date: Tue, 30 Jul 2024 22:26:52 +0000 Subject: [PATCH] Use query parameters in migrations --- webapp/migrations/Version20210407120356.php | 13 ++++------ webapp/migrations/Version20240511091916.php | 28 +++++++++++++++------ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/webapp/migrations/Version20210407120356.php b/webapp/migrations/Version20210407120356.php index f8c97308bf..14c263fae3 100644 --- a/webapp/migrations/Version20210407120356.php +++ b/webapp/migrations/Version20210407120356.php @@ -42,7 +42,6 @@ public function up(Schema $schema) : void for ($idx = 0; $idx < $zip->numFiles; $idx++) { $filename = basename($zip->getNameIndex($idx)); $content = $zip->getFromIndex($idx); - $encodedContent = ($content === '' ? '' : ('0x' . strtoupper(bin2hex($content)))); // In doubt make files executable, but try to read it from the zip file. $executableBit = '1'; @@ -52,17 +51,15 @@ public function up(Schema $schema) : void $executableBit = '0'; } $this->connection->executeStatement( - 'INSERT INTO executable_file ' - . '(`immutable_execid`, `filename`, `ranknumber`, `file_content`, `hash`, `is_executable`) ' - . 'VALUES (' . $immutable_execid . ', "' . $filename . '", ' - . $idx . ', ' . $encodedContent . ', "' . md5($content) . '", ' - . $executableBit . ')' + 'INSERT INTO executable_file (`immutable_execid`, `filename`, `ranknumber`, `file_content`, `hash`, `is_executable`)' + . ' VALUES (?, ?, ?, ?, ?, ?)', + [$immutable_execid, $filename, $idx, $content, md5($content), $executableBit] ); } $this->connection->executeStatement( - 'UPDATE executable SET immutable_execid = ' - . $immutable_execid . ' WHERE execid = "' . $oldRow['execid'] . '"' + 'UPDATE executable SET immutable_execid = :immutable_execid WHERE execid = :execid', + ['immutable_execid' => $immutable_execid, 'execid' => $oldRow['execid']] ); } diff --git a/webapp/migrations/Version20240511091916.php b/webapp/migrations/Version20240511091916.php index 47fd04c297..2418526d17 100644 --- a/webapp/migrations/Version20240511091916.php +++ b/webapp/migrations/Version20240511091916.php @@ -57,21 +57,33 @@ public function getDescription(): string public function up(Schema $schema): void { - foreach (self::COMPILER_VERSION_COMMAND as $lang => $versionCommand) { - $this->addSql("UPDATE language SET compiler_version_command = '" . $versionCommand ."' WHERE langid='" . $lang . "' AND compiler_version_command IS NULL;"); + foreach (self::COMPILER_VERSION_COMMAND as $langid => $versionCommand) { + $this->addSql( + "UPDATE language SET compiler_version_command = :compiler_version_command WHERE langid = :langid AND compiler_version_command IS NULL", + ['compiler_version_command' => $versionCommand, 'langid' => $langid] + ); } - foreach (self::RUNNER_VERSION_COMMAND as $lang => $versionCommand) { - $this->addSql("UPDATE language SET runner_version_command = '" . $versionCommand ."' WHERE langid='" . $lang . "' AND runner_version_command IS NULL;"); + foreach (self::RUNNER_VERSION_COMMAND as $langid => $versionCommand) { + $this->addSql( + "UPDATE language SET runner_version_command = :compiler_version_command WHERE langid = :langid AND runner_version_command IS NULL", + ['compiler_version_command' => $versionCommand, 'langid' => $langid] + ); } } public function down(Schema $schema): void { - foreach (self::COMPILER_VERSION_COMMAND as $lang => $versionCommand) { - $this->addSql("UPDATE language SET compiler_version_command = NULL WHERE langid='" . $lang . "' AND compiler_version_command = '" . $versionCommand ."';"); + foreach (self::COMPILER_VERSION_COMMAND as $langid => $versionCommand) { + $this->addSql( + "UPDATE language SET compiler_version_command = NULL WHERE langid = :langid AND compiler_version_command = :compiler_version_command", + ['compiler_version_command' => $versionCommand, 'langid' => $langid] + ); } - foreach (self::RUNNER_VERSION_COMMAND as $lang => $versionCommand) { - $this->addSql("UPDATE language SET runner_version_command = NULL WHERE langid='" . $lang . "' AND runner_version_command = '" . $versionCommand ."';"); + foreach (self::RUNNER_VERSION_COMMAND as $langid => $versionCommand) { + $this->addSql( + "UPDATE language SET runner_version_command = NULL WHERE langid = :langid AND runner_version_command = :compiler_version_command", + ['compiler_version_command' => $versionCommand, 'langid' => $langid] + ); } }