1 | <?php |
||
2 | namespace RazonYang\Yii2\Log\Db\Migration; |
||
3 | |||
4 | use yii\db\Migration; |
||
5 | use RazonYang\Yii2\Log\Db\Target; |
||
6 | use Yii; |
||
7 | |||
8 | /** |
||
9 | * Class M190814022727RequestId |
||
10 | */ |
||
11 | class M190814022727RequestId extends Migration |
||
12 | { |
||
13 | /** |
||
14 | * @var DbTarget[] Targets to create log table for |
||
15 | */ |
||
16 | private $dbTargets = []; |
||
17 | |||
18 | /** |
||
19 | * @throws InvalidConfigException |
||
20 | * @return DbTarget[] |
||
21 | */ |
||
22 | protected function getDbTargets() |
||
23 | { |
||
24 | if ($this->dbTargets === []) { |
||
25 | $log = Yii::$app->getLog(); |
||
26 | |||
27 | $usedTargets = []; |
||
28 | foreach ($log->targets as $target) { |
||
29 | if ($target instanceof Target) { |
||
30 | $currentTarget = [ |
||
31 | $target->db, |
||
32 | $target->logTable, |
||
33 | ]; |
||
34 | if (!in_array($currentTarget, $usedTargets, true)) { |
||
35 | // do not create same table twice |
||
36 | $usedTargets[] = $currentTarget; |
||
37 | $this->dbTargets[] = $target; |
||
38 | } |
||
39 | } |
||
40 | } |
||
41 | |||
42 | if ($this->dbTargets === []) { |
||
43 | throw new InvalidConfigException('You should configure "log" component to use one or more database targets before executing this migration.'); |
||
0 ignored issues
–
show
|
|||
44 | } |
||
45 | } |
||
46 | |||
47 | return $this->dbTargets; |
||
0 ignored issues
–
show
|
|||
48 | } |
||
49 | |||
50 | public function up() |
||
51 | { |
||
52 | foreach ($this->getDbTargets() as $target) { |
||
53 | $this->db = $target->db; |
||
54 | $this->addColumn($target->logTable, 'request_id', $this->char(13)->notNull()->defaultValue('')->after('id')); |
||
55 | $this->createIndex('idx_request_id', $target->logTable, 'request_id'); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | public function down() |
||
60 | { |
||
61 | foreach ($this->getDbTargets() as $target) { |
||
62 | $this->db = $target->db; |
||
63 | |||
64 | $this->dropColumn($target->logTable, 'request_id'); |
||
65 | } |
||
66 | } |
||
67 | } |
||
68 |
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