Skip to content

Commit b61294f

Browse files
nickygerritsenvmcj
authored andcommitted
Recalculate all immutable hashes since the algorithm changed in the past.
Fixes #1826 (cherry picked from commit c920919)
1 parent 646b7bf commit b61294f

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use App\Entity\ExecutableFile;
8+
use Doctrine\DBAL\Schema\Schema;
9+
use Doctrine\Migrations\AbstractMigration;
10+
11+
/**
12+
* Auto-generated Migration: Please modify to your needs!
13+
*/
14+
final class Version20230508163415 extends AbstractMigration
15+
{
16+
public function getDescription(): string
17+
{
18+
return 'Update hashes of immutable executables';
19+
}
20+
21+
public function up(Schema $schema): void
22+
{
23+
$immutableExecutables = $this->connection->fetchAllAssociative('SELECT immutable_execid FROM immutable_executable');
24+
foreach ($immutableExecutables as $immutableExecutable) {
25+
$files = $this->connection->fetchAllAssociative('SELECT hash, filename, is_executable FROM executable_file WHERE immutable_execid = :id', ['id' => $immutableExecutable['immutable_execid']]);
26+
uasort($files, fn(array $a, array $b) => strcmp($a['filename'], $b['filename']));
27+
$newHash = md5(
28+
join(
29+
array_map(
30+
fn(array $file) => $file['hash'] . $file['filename'] . (bool)$file['is_executable'],
31+
$files
32+
)
33+
)
34+
);
35+
$this->connection->executeQuery('UPDATE immutable_executable SET hash = :hash WHERE immutable_execid = :id', [
36+
'hash' => $newHash,
37+
'id' => $immutableExecutable['immutable_execid'],
38+
]);
39+
}
40+
}
41+
42+
public function down(Schema $schema): void
43+
{
44+
// We don't handle this case
45+
}
46+
47+
public function isTransactional(): bool
48+
{
49+
return false;
50+
}
51+
}

0 commit comments

Comments
 (0)