Skip to content

Commit 6a99afc

Browse files
tom93vmcj
authored andcommitted
Use query parameters in migrations
1 parent 7a5e397 commit 6a99afc

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

webapp/migrations/Version20210407120356.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public function up(Schema $schema) : void
4242
for ($idx = 0; $idx < $zip->numFiles; $idx++) {
4343
$filename = basename($zip->getNameIndex($idx));
4444
$content = $zip->getFromIndex($idx);
45-
$encodedContent = ($content === '' ? '' : ('0x' . strtoupper(bin2hex($content))));
4645

4746
// In doubt make files executable, but try to read it from the zip file.
4847
$executableBit = '1';
@@ -52,17 +51,15 @@ public function up(Schema $schema) : void
5251
$executableBit = '0';
5352
}
5453
$this->connection->executeStatement(
55-
'INSERT INTO executable_file '
56-
. '(`immutable_execid`, `filename`, `ranknumber`, `file_content`, `hash`, `is_executable`) '
57-
. 'VALUES (' . $immutable_execid . ', "' . $filename . '", '
58-
. $idx . ', ' . $encodedContent . ', "' . md5($content) . '", '
59-
. $executableBit . ')'
54+
'INSERT INTO executable_file (`immutable_execid`, `filename`, `ranknumber`, `file_content`, `hash`, `is_executable`)'
55+
. ' VALUES (?, ?, ?, ?, ?, ?)',
56+
[$immutable_execid, $filename, $idx, $content, md5($content), $executableBit]
6057
);
6158
}
6259

6360
$this->connection->executeStatement(
64-
'UPDATE executable SET immutable_execid = '
65-
. $immutable_execid . ' WHERE execid = "' . $oldRow['execid'] . '"'
61+
'UPDATE executable SET immutable_execid = :immutable_execid WHERE execid = :execid',
62+
['immutable_execid' => $immutable_execid, 'execid' => $oldRow['execid']]
6663
);
6764
}
6865

webapp/migrations/Version20240511091916.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,33 @@ public function getDescription(): string
5757

5858
public function up(Schema $schema): void
5959
{
60-
foreach (self::COMPILER_VERSION_COMMAND as $lang => $versionCommand) {
61-
$this->addSql("UPDATE language SET compiler_version_command = '" . $versionCommand ."' WHERE langid='" . $lang . "' AND compiler_version_command IS NULL;");
60+
foreach (self::COMPILER_VERSION_COMMAND as $langid => $versionCommand) {
61+
$this->addSql(
62+
"UPDATE language SET compiler_version_command = :compiler_version_command WHERE langid = :langid AND compiler_version_command IS NULL",
63+
['compiler_version_command' => $versionCommand, 'langid' => $langid]
64+
);
6265
}
63-
foreach (self::RUNNER_VERSION_COMMAND as $lang => $versionCommand) {
64-
$this->addSql("UPDATE language SET runner_version_command = '" . $versionCommand ."' WHERE langid='" . $lang . "' AND runner_version_command IS NULL;");
66+
foreach (self::RUNNER_VERSION_COMMAND as $langid => $versionCommand) {
67+
$this->addSql(
68+
"UPDATE language SET runner_version_command = :compiler_version_command WHERE langid = :langid AND runner_version_command IS NULL",
69+
['compiler_version_command' => $versionCommand, 'langid' => $langid]
70+
);
6571
}
6672
}
6773

6874
public function down(Schema $schema): void
6975
{
70-
foreach (self::COMPILER_VERSION_COMMAND as $lang => $versionCommand) {
71-
$this->addSql("UPDATE language SET compiler_version_command = NULL WHERE langid='" . $lang . "' AND compiler_version_command = '" . $versionCommand ."';");
76+
foreach (self::COMPILER_VERSION_COMMAND as $langid => $versionCommand) {
77+
$this->addSql(
78+
"UPDATE language SET compiler_version_command = NULL WHERE langid = :langid AND compiler_version_command = :compiler_version_command",
79+
['compiler_version_command' => $versionCommand, 'langid' => $langid]
80+
);
7281
}
73-
foreach (self::RUNNER_VERSION_COMMAND as $lang => $versionCommand) {
74-
$this->addSql("UPDATE language SET runner_version_command = NULL WHERE langid='" . $lang . "' AND runner_version_command = '" . $versionCommand ."';");
82+
foreach (self::RUNNER_VERSION_COMMAND as $langid => $versionCommand) {
83+
$this->addSql(
84+
"UPDATE language SET runner_version_command = NULL WHERE langid = :langid AND runner_version_command = :compiler_version_command",
85+
['compiler_version_command' => $versionCommand, 'langid' => $langid]
86+
);
7587
}
7688
}
7789

0 commit comments

Comments
 (0)