|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of DivineNii opensource projects. |
|
7
|
|
|
* |
|
8
|
|
|
* PHP version 7.4 and above required |
|
9
|
|
|
* |
|
10
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
|
11
|
|
|
* @copyright 2019 DivineNii (https://divinenii.com/) |
|
12
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause License |
|
13
|
|
|
* |
|
14
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
15
|
|
|
* file that was distributed with this source code. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace Rade\Commands\CycleORM; |
|
19
|
|
|
|
|
20
|
|
|
use Cycle\Database\DatabaseProviderInterface; |
|
|
|
|
|
|
21
|
|
|
use Cycle\Migrations\Migrator; |
|
|
|
|
|
|
22
|
|
|
use Cycle\Migrations\State; |
|
|
|
|
|
|
23
|
|
|
use Cycle\Schema\Compiler; |
|
|
|
|
|
|
24
|
|
|
use Cycle\Schema\Generator\Migrations\GenerateMigrations; |
|
|
|
|
|
|
25
|
|
|
use Cycle\Schema\Generator\SyncTables; |
|
|
|
|
|
|
26
|
|
|
use Cycle\Schema\GeneratorInterface; |
|
|
|
|
|
|
27
|
|
|
use Cycle\Schema\Registry; |
|
|
|
|
|
|
28
|
|
|
use Rade\DI\Extensions\CycleORM\Generator\ShowChanges; |
|
29
|
|
|
use Symfony\Component\Console\Command\Command; |
|
30
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
31
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
32
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Cycle ORM synchronizer command. |
|
36
|
|
|
* |
|
37
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
|
38
|
|
|
*/ |
|
39
|
|
|
class DatabaseOrmCommand extends Command |
|
40
|
|
|
{ |
|
41
|
|
|
protected static $defaultName = 'cycle:database:orm'; |
|
42
|
|
|
|
|
43
|
|
|
protected static $defaultDescription = 'Generate ORM schema migrations and run if possible'; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param array<int,GeneratorInterface> $generators |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct(private Migrator $migrator, private DatabaseProviderInterface $provider, private array $generators) |
|
49
|
|
|
{ |
|
50
|
|
|
parent::__construct(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritdoc} |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
57
|
|
|
{ |
|
58
|
|
|
$this->migrator->configure(); |
|
59
|
|
|
$io = new SymfonyStyle($input, $output); |
|
60
|
|
|
|
|
61
|
|
|
foreach ($this->migrator->getMigrations() as $migration) { |
|
62
|
|
|
if (State::STATUS_EXECUTED !== $migration->getState()->getStatus()) { |
|
63
|
|
|
$io->error('Outstanding migrations found, run `cycle:database:migrate` first.'); |
|
64
|
|
|
|
|
65
|
|
|
return self::FAILURE; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$this->generators[] = $show = new ShowChanges($output); |
|
70
|
|
|
|
|
71
|
|
|
if (!\class_exists(GenerateMigrations::class)) { |
|
72
|
|
|
$io->warning('Synchronizing ORM schema into database is a ricky operation, instead "composer require cycle/schema-migrations-generator".'); |
|
73
|
|
|
|
|
74
|
|
|
if (!$io->confirm('Do you want to proceed now?', false)) { |
|
75
|
|
|
return self::SUCCESS; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$this->generators[] = new SyncTables(); |
|
79
|
|
|
$autoMigrate = false; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
(new Compiler())->compile($registry = new Registry($this->provider), $this->generators); |
|
83
|
|
|
|
|
84
|
|
|
if ($show->hasChanges()) { |
|
85
|
|
|
if (!isset($autoMigrate)) { |
|
86
|
|
|
(new GenerateMigrations($this->migrator->getRepository(), $this->migrator->getConfig()))->run($registry); |
|
87
|
|
|
|
|
88
|
|
|
if ($io->confirm('Do you want to run migrations now?', false)) { |
|
89
|
|
|
return $this->getApplication()->find('cycle:database:migrate')->run($input, $output); |
|
90
|
|
|
} |
|
91
|
|
|
} else { |
|
92
|
|
|
$io->writeln("\n<info>ORM Schema has been synchronized</info>"); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return self::SUCCESS; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
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