1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* Copyright (C) 2020-2025 Iain Cambridge |
7
|
|
|
* |
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by |
10
|
|
|
* the Free Software Foundation, either version 2.1 of the License, or |
11
|
|
|
* (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Lesser General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU General Public License |
19
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Parthenon\MultiTenancy\Database; |
23
|
|
|
|
24
|
|
|
use Doctrine\Migrations\Configuration\Configuration; |
|
|
|
|
25
|
|
|
use Doctrine\Migrations\Configuration\EntityManager\EntityManagerLoader; |
|
|
|
|
26
|
|
|
use Doctrine\Migrations\Configuration\Migration\ConfigurationLoader; |
|
|
|
|
27
|
|
|
use Doctrine\Migrations\DependencyFactory; |
|
|
|
|
28
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
29
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
30
|
|
|
use Parthenon\MultiTenancy\Entity\TenantInterface; |
31
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
32
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
33
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
34
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
35
|
|
|
|
36
|
|
|
class MigrationsHandler implements MigrationsHandlerInterface |
37
|
|
|
{ |
38
|
|
|
public function __construct( |
39
|
|
|
private ManagerRegistry $managerRegistry, |
40
|
|
|
private string $migrationsDirectory, |
41
|
|
|
private string $entityManagerName, |
42
|
|
|
) { |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function handleMigrations(TenantInterface $tenant): void |
46
|
|
|
{ |
47
|
|
|
$newInput = new ArrayInput([]); |
48
|
|
|
|
49
|
|
|
$newInput->setInteractive(false); |
50
|
|
|
$otherCommand = new \Doctrine\Migrations\Tools\Console\Command\SyncMetadataCommand($this->getDependencyFactory()); |
|
|
|
|
51
|
|
|
$otherCommand->run($newInput, new NullOutput()); |
52
|
|
|
|
53
|
|
|
$newInput = new ArrayInput([ |
54
|
|
|
'--add' => true, |
55
|
|
|
'--all' => true, |
56
|
|
|
]); |
57
|
|
|
|
58
|
|
|
$newInput->setInteractive(false); |
59
|
|
|
$otherCommand = new \Doctrine\Migrations\Tools\Console\Command\VersionCommand($this->getDependencyFactory()); |
|
|
|
|
60
|
|
|
$otherCommand->run($newInput, new NullOutput()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function getDependencyFactory(): DependencyFactory |
64
|
|
|
{ |
65
|
|
|
$em = $this->managerRegistry->getManager($this->entityManagerName); |
66
|
|
|
$a = new Configuration(); |
67
|
|
|
$a->addMigrationsDirectory('DoctrineMigrations', $this->migrationsDirectory); |
68
|
|
|
$a->setAllOrNothing(false); |
69
|
|
|
$a->setCheckDatabasePlatform(true); |
70
|
|
|
$a->setTransactional(true); |
71
|
|
|
$a->setMetadataStorageConfiguration(new \Doctrine\Migrations\Metadata\Storage\TableMetadataStorageConfiguration()); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$configLoader = $this->getConfigLoader($a); |
74
|
|
|
$emLoader = $this->getEmLoader($em); |
75
|
|
|
|
76
|
|
|
return DependencyFactory::fromEntityManager($configLoader, $emLoader); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
protected function executeMigrations(InputInterface $input, OutputInterface $output) |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
protected function getConfigLoader(Configuration $a) |
84
|
|
|
{ |
85
|
|
|
$configLoader = new class($a) implements ConfigurationLoader { |
86
|
|
|
public function __construct(private $a) |
87
|
|
|
{ |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getConfiguration(): Configuration |
91
|
|
|
{ |
92
|
|
|
return $this->a; |
93
|
|
|
} |
94
|
|
|
}; |
95
|
|
|
|
96
|
|
|
return $configLoader; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
protected function getEmLoader(\Doctrine\Persistence\ObjectManager $em) |
100
|
|
|
{ |
101
|
|
|
$emLoader = new class($em) implements EntityManagerLoader { |
102
|
|
|
public function __construct(private $em) |
103
|
|
|
{ |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getEntityManager(?string $name = null): EntityManagerInterface |
107
|
|
|
{ |
108
|
|
|
return $this->em; |
109
|
|
|
} |
110
|
|
|
}; |
111
|
|
|
|
112
|
|
|
return $emLoader; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths