diff --git a/webapp/migrations/Version20210407120356.php b/webapp/migrations/Version20210407120356.php index 4e7ecffcfa..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,21 +51,19 @@ public function up(Schema $schema) : void $executableBit = '0'; } $this->connection->executeStatement( - 'INSERT INTO executable_file ' - . '(`immutable_execid`, `filename`, `ranknumber`, `file_content`, `is_executable`) ' - . 'VALUES (' . $immutable_execid . ', "' . $filename . '", ' - . $idx . ', ' . $encodedContent . ', ' - . $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']] ); } - $this->addSql('ALTER TABLE `executable` DROP COLUMN `zipfile`'); + $this->connection->executeStatement('ALTER TABLE `executable` DROP COLUMN `zipfile`'); } } diff --git a/webapp/migrations/Version20230508163415.php b/webapp/migrations/Version20230508163415.php index 9cef0b66ba..0e59742533 100644 --- a/webapp/migrations/Version20230508163415.php +++ b/webapp/migrations/Version20230508163415.php @@ -4,48 +4,28 @@ namespace DoctrineMigrations; -use App\Entity\ExecutableFile; use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; -/** - * Auto-generated Migration: Please modify to your needs! - */ final class Version20230508163415 extends AbstractMigration { + // The code that was in this file was moved to Version20230508180000.php so + // that it will re-run after Version20230508170000.php. This file has been + // kept as a no-op to prevent warnings about previously executed migrations + // that are not registered. + public function getDescription(): string { - return 'Update hashes of immutable executables'; + return '[Deleted]'; } public function up(Schema $schema): void { - $immutableExecutables = $this->connection->fetchAllAssociative('SELECT immutable_execid FROM immutable_executable'); - foreach ($immutableExecutables as $immutableExecutable) { - $files = $this->connection->fetchAllAssociative('SELECT hash, filename, is_executable FROM executable_file WHERE immutable_execid = :id', ['id' => $immutableExecutable['immutable_execid']]); - uasort($files, fn(array $a, array $b) => strcmp($a['filename'], $b['filename'])); - $newHash = md5( - join( - array_map( - fn(array $file) => $file['hash'] . $file['filename'] . (bool)$file['is_executable'], - $files - ) - ) - ); - $this->connection->executeQuery('UPDATE immutable_executable SET hash = :hash WHERE immutable_execid = :id', [ - 'hash' => $newHash, - 'id' => $immutableExecutable['immutable_execid'], - ]); - } + $this->addSql('-- no-op'); // suppress warning "Migration was executed but did not result in any SQL statements." } public function down(Schema $schema): void { - // We don't handle this case - } - - public function isTransactional(): bool - { - return false; + $this->addSql('-- no-op'); } } diff --git a/webapp/migrations/Version20230508170000.php b/webapp/migrations/Version20230508170000.php new file mode 100644 index 0000000000..beb8955941 --- /dev/null +++ b/webapp/migrations/Version20230508170000.php @@ -0,0 +1,41 @@ +connection->fetchAllAssociative('SELECT execfileid, file_content FROM executable_file WHERE hash IS NULL'); + foreach ($executableFiles as $file) { + $this->addSql('UPDATE executable_file SET hash = :hash WHERE execfileid = :id', [ + 'hash' => md5($file['file_content']), + 'id' => $file['execfileid'] + ]); + } + } + + public function down(Schema $schema): void + { + // We don't handle this case + } + + public function isTransactional(): bool + { + return false; + } +} diff --git a/webapp/migrations/Version20230508180000.php b/webapp/migrations/Version20230508180000.php new file mode 100644 index 0000000000..0d11330f79 --- /dev/null +++ b/webapp/migrations/Version20230508180000.php @@ -0,0 +1,50 @@ +connection->fetchAllAssociative('SELECT immutable_execid FROM immutable_executable'); + foreach ($immutableExecutables as $immutableExecutable) { + $files = $this->connection->fetchAllAssociative('SELECT hash, filename, is_executable FROM executable_file WHERE immutable_execid = :id', ['id' => $immutableExecutable['immutable_execid']]); + uasort($files, fn(array $a, array $b) => strcmp($a['filename'], $b['filename'])); + $newHash = md5( + join( + array_map( + fn(array $file) => $file['hash'] . $file['filename'] . (bool)$file['is_executable'], + $files + ) + ) + ); + $this->addSql('UPDATE immutable_executable SET hash = :hash WHERE immutable_execid = :id', [ + 'hash' => $newHash, + 'id' => $immutableExecutable['immutable_execid'], + ]); + } + } + + public function down(Schema $schema): void + { + // We don't handle this case + } + + public function isTransactional(): bool + { + return false; + } +} diff --git a/webapp/migrations/Version20231120225210.php b/webapp/migrations/Version20231120225210.php index 4f2bedd3cc..7a4d901b0b 100644 --- a/webapp/migrations/Version20231120225210.php +++ b/webapp/migrations/Version20231120225210.php @@ -34,7 +34,7 @@ public function up(Schema $schema): void if ($updated) { $newExtensionsJson = json_encode($extensions); - $this->connection->executeQuery('UPDATE language SET extensions = :extensions WHERE langid = :langid', [ + $this->addSql('UPDATE language SET extensions = :extensions WHERE langid = :langid', [ 'extensions' => $newExtensionsJson, 'langid' => $language['langid'], ]); 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] + ); } }