1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yiisoft\Yii\Cycle\Helper; |
4
|
|
|
|
5
|
|
|
use Cycle\Migrations\GenerateMigrations; |
6
|
|
|
use Cycle\Schema\Compiler; |
7
|
|
|
use Cycle\Schema\Generator; |
8
|
|
|
use Cycle\Schema\Registry; |
9
|
|
|
use Spiral\Database\DatabaseManager; |
10
|
|
|
use Spiral\Migrations\Config\MigrationConfig; |
11
|
|
|
use Spiral\Migrations\Migrator; |
12
|
|
|
use Psr\SimpleCache\CacheInterface; |
|
|
|
|
13
|
|
|
use Yiisoft\Yii\Cycle\SchemaConveyorInterface; |
14
|
|
|
|
15
|
|
|
class CycleOrmHelper |
16
|
|
|
{ |
17
|
|
|
/** @var DatabaseManager $dbal */ |
18
|
|
|
private $dbal; |
19
|
|
|
|
20
|
|
|
/** @var CacheInterface */ |
21
|
|
|
private $cache; |
22
|
|
|
|
23
|
|
|
/** @var string */ |
24
|
|
|
private $cacheKey = 'Cycle-ORM-Schema'; |
25
|
|
|
|
26
|
|
|
/** @var SchemaConveyorInterface */ |
27
|
|
|
private $schemaConveyor; |
28
|
|
|
|
29
|
|
|
public function __construct( |
30
|
|
|
DatabaseManager $dbal, |
31
|
|
|
CacheInterface $cache, |
32
|
|
|
SchemaConveyorInterface $schemaConveyor |
33
|
|
|
) { |
34
|
|
|
$this->dbal = $dbal; |
35
|
|
|
$this->cache = $cache; |
36
|
|
|
$this->schemaConveyor = $schemaConveyor; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function dropCurrentSchemaCache(): void |
40
|
|
|
{ |
41
|
|
|
$this->cache->delete($this->cacheKey); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function generateMigrations(Migrator $migrator, MigrationConfig $config, array $generators = []): void |
45
|
|
|
{ |
46
|
|
|
// add migrations generator |
47
|
|
|
$migrate = new GenerateMigrations($migrator->getRepository(), $config); |
48
|
|
|
$this->schemaConveyor->addGenerator($this->schemaConveyor::STAGE_USERLAND, $migrate); |
49
|
|
|
// add custom generators |
50
|
|
|
foreach ($generators as $generator) { |
51
|
|
|
$this->schemaConveyor->addGenerator($this->schemaConveyor::STAGE_USERLAND, $generator); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$conveyor = $this->schemaConveyor->getGenerators(); |
55
|
|
|
|
56
|
|
|
(new Compiler())->compile(new Registry($this->dbal), $conveyor); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getCurrentSchemaArray($fromCache = true): array |
60
|
|
|
{ |
61
|
|
|
if ($fromCache) { |
62
|
|
|
$schema = $this->cache->get($this->cacheKey); |
63
|
|
|
if (is_array($schema)) { |
64
|
|
|
return $schema; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
// sync table changes to database |
68
|
|
|
$this->schemaConveyor->addGenerator($this->schemaConveyor::STAGE_RENDER, Generator\SyncTables::class); |
69
|
|
|
// compile schema array |
70
|
|
|
$conveyor = $this->schemaConveyor->getGenerators(); |
71
|
|
|
$schema = (new Compiler())->compile(new Registry($this->dbal), $conveyor); |
72
|
|
|
|
73
|
|
|
$this->cache->set($this->cacheKey, $schema); |
74
|
|
|
return $schema; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
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