Skip to content

Commit 4889088

Browse files
nickygerritsenvmcj
authored andcommitted
Do not use Doctrine in the migrations.
This would break when adding fields. (cherry picked from commit 9cc324e)
1 parent e0d02c6 commit 4889088

File tree

2 files changed

+21
-33
lines changed

2 files changed

+21
-33
lines changed

webapp/migrations/Version20191031203138.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,14 @@ public function getDescription(): string
2929

3030
public function up(Schema $schema): void
3131
{
32-
$em = $this->container->get('doctrine')->getManager();
33-
/** @var Language $python2 */
34-
$python2 = $em->getRepository(Language::class)->find('py2');
35-
/** @var Language $python3 */
36-
$python3 = $em->getRepository(Language::class)->find('py3');
37-
if ($python2 === null ||
38-
$python3 === null ||
39-
$python2->getAllowSubmit() ||
40-
$python3->getAllowSubmit() ||
41-
$python2->getExtensions() !== ['py2', 'py'] ||
42-
$python3->getExtensions() !== ['py3']) {
32+
$python2 = $this->connection->fetchAssociative('SELECT * FROM language WHERE langid = :py2', ['py2' => 'py2']);
33+
$python3 = $this->connection->fetchAssociative('SELECT * FROM language WHERE langid = :py3', ['py3' => 'py3']);
34+
if ($python2 === false ||
35+
$python3 === false ||
36+
$python2['allow_submit'] ||
37+
$python3['allow_submit'] ||
38+
json_decode($python2['extensions'], true) !== ['py2', 'py'] ||
39+
json_decode($python3['extensions'], true) !== ['py3']) {
4340
return;
4441
}
4542

@@ -49,19 +46,15 @@ public function up(Schema $schema): void
4946

5047
public function down(Schema $schema): void
5148
{
52-
// this down() migration is auto-generated, please modify it to your needs
53-
$em = $this->container->get('doctrine')->getManager();
54-
/** @var Language $python2 */
55-
$python2 = $em->getRepository(Language::class)->find('py2');
56-
/** @var Language $python3 */
57-
$python3 = $em->getRepository(Language::class)->find('py3');
49+
$python2 = $this->connection->fetchAssociative('SELECT * FROM language WHERE langid = :py2', ['py2' => 'py2']);
50+
$python3 = $this->connection->fetchAssociative('SELECT * FROM language WHERE langid = :py3', ['py3' => 'py3']);
5851

59-
if ($python2 === null ||
60-
$python3 === null ||
61-
$python2->getAllowSubmit() ||
62-
$python3->getAllowSubmit() ||
63-
$python2->getExtensions() !== ['py2', 'py'] ||
64-
$python3->getExtensions() !== ['py3']) {
52+
if ($python2 === false ||
53+
$python3 === false ||
54+
$python2['allow_submit'] ||
55+
$python3['allow_submit'] ||
56+
json_decode($python2['extensions'], true) !== ['py2'] ||
57+
json_decode($python3['extensions'], true) !== ['py3', 'py']) {
6558
return;
6659
}
6760

webapp/migrations/Version20200131064449.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ public function up(Schema $schema) : void
3030
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
3131

3232
// Note: can't use ConfigurationService::get on 'registration_category_name' because the specification has been removed from db-config.yaml
33-
$em = $this->container->get('doctrine')->getManager();
34-
$registrationCategoryNameConfig = $em->getRepository(Configuration::class)->findOneBy(['name' => 'registration_category_name']);
33+
$registrationCategoryNameConfig = $this->connection->fetchAssociative('SELECT * FROM configuration WHERE name = :registration_category_name', ['registration_category_name' => 'registration_category_name']);
3534
if ($registrationCategoryNameConfig) {
36-
$registrationCategoryName = $registrationCategoryNameConfig->getValue();
35+
$registrationCategoryName = $registrationCategoryNameConfig['value'];
3736
} else {
3837
$registrationCategoryName = '';
3938
}
@@ -53,23 +52,19 @@ public function down(Schema $schema) : void
5352
{
5453
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
5554

56-
$em = $this->container->get('doctrine')->getManager();
57-
$selfRegistrationCategories = $em->getRepository(TeamCategory::class)->findBy(
58-
['allow_self_registration' => 1],
59-
['sortorder' => 'ASC']
60-
);
55+
$selfRegistrationCategories = $this->connection->fetchAllAssociative('SELECT * FROM team_category WHERE allow_self_registration = 1 ORDER BY sortorder');
6156

6257
$this->warnIf(
6358
count($selfRegistrationCategories) > 1,
6459
sprintf('Team categories for self-registered teams were %s. Only first will be kept.',
6560
implode(', ', array_map(function($category) {
66-
return $category->getName();
61+
return $category['name'];
6762
}, $selfRegistrationCategories)))
6863
);
6964

7065
$this->addSql(
7166
"INSERT INTO configuration (name, value) VALUES ('registration_category_name', :value)",
72-
['value' => empty($selfRegistrationCategories) ? '""' : json_encode($selfRegistrationCategories[0]->getName())]
67+
['value' => empty($selfRegistrationCategories) ? '""' : json_encode($selfRegistrationCategories[0]['name'])]
7368
);
7469

7570
$this->addSql('ALTER TABLE team_category DROP allow_self_registration');

0 commit comments

Comments
 (0)