1 | <?php |
||
2 | /** |
||
3 | * Analytics |
||
4 | * |
||
5 | * SPDX-FileCopyrightText: 2019-2022 Marcel Scherello |
||
6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
||
7 | */ |
||
8 | |||
9 | declare(strict_types=1); |
||
10 | |||
11 | namespace OCA\Analytics\Migration; |
||
12 | |||
13 | use Closure; |
||
14 | use OCP\DB\ISchemaWrapper; |
||
0 ignored issues
–
show
|
|||
15 | use OCP\IDBConnection; |
||
0 ignored issues
–
show
The type
OCP\IDBConnection was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
16 | use OCP\Migration\IOutput; |
||
0 ignored issues
–
show
The type
OCP\Migration\IOutput was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
17 | use OCP\Migration\SimpleMigrationStep; |
||
0 ignored issues
–
show
The type
OCP\Migration\SimpleMigrationStep was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
18 | |||
19 | /** |
||
20 | * Auto-generated migration step: Please modify to your needs! |
||
21 | * sudo -u www-data php occ migrations:execute analytics 4015Date20240714200000 |
||
22 | */ |
||
23 | class Version4015Date20240714200000 extends SimpleMigrationStep |
||
24 | { |
||
25 | public function __construct( |
||
26 | private IDBConnection $connection, |
||
27 | ) { |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @param IOutput $output |
||
32 | * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
||
33 | * @param array $options |
||
34 | * @return null|ISchemaWrapper |
||
35 | */ |
||
36 | public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) |
||
37 | { |
||
38 | /** @var ISchemaWrapper $schema */ |
||
39 | $schema = $schemaClosure(); |
||
40 | |||
41 | $table = $schema->getTable('analytics_dataset'); |
||
42 | if (!$table->hasColumn('ai_index')) { |
||
43 | $table->addColumn('ai_index', 'integer', [ |
||
44 | 'notnull' => false |
||
45 | ]); |
||
46 | } |
||
47 | if ($table->hasColumn('chartoptions')) { |
||
48 | $table->dropColumn('chartoptions'); |
||
49 | } |
||
50 | if ($table->hasColumn('dataoptions')) { |
||
51 | $table->dropColumn('dataoptions'); |
||
52 | } |
||
53 | if ($table->hasColumn('filteroptions')) { |
||
54 | $table->dropColumn('filteroptions'); |
||
55 | } |
||
56 | if ($table->hasColumn('refresh')) { |
||
57 | $table->dropColumn('refresh'); |
||
58 | } |
||
59 | if ($table->hasColumn('link')) { |
||
60 | $table->dropColumn('link'); |
||
61 | } |
||
62 | if ($table->hasColumn('visualization')) { |
||
63 | $table->dropColumn('visualization'); |
||
64 | } |
||
65 | if ($table->hasColumn('chart')) { |
||
66 | $table->dropColumn('chart'); |
||
67 | } |
||
68 | |||
69 | $table = $schema->getTable('analytics_share'); |
||
70 | if (!$table->hasColumn('item_type')) { |
||
71 | $table->addColumn('item_type', 'string', [ |
||
72 | 'notnull' => true, |
||
73 | 'length' => 64, |
||
74 | ]); |
||
75 | } |
||
76 | if (!$table->hasColumn('item_source')) { |
||
77 | $table->addColumn('item_source', 'integer', [ |
||
78 | 'notnull' => false, |
||
79 | ]); |
||
80 | } |
||
81 | return $schema; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param IOutput $output |
||
86 | * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
||
87 | * @param array $options |
||
88 | */ |
||
89 | public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) |
||
90 | { |
||
91 | |||
92 | $update = $this->connection->getQueryBuilder(); |
||
93 | $update->update('analytics_share') |
||
94 | ->set('item_type', $update->createParameter('item_type')) |
||
95 | ->set('item_source', $update->createParameter('item_source')) |
||
96 | ->where($update->expr()->eq('id', $update->createParameter('id'))); |
||
97 | |||
98 | $query = $this->connection->getQueryBuilder(); |
||
99 | $query->select(['id', 'report']) |
||
100 | ->from('analytics_share'); |
||
101 | $result = $query->executeQuery() ; |
||
102 | |||
103 | while ($row = $result->fetch()) { |
||
104 | $update |
||
105 | ->setParameter('item_type', 'report') |
||
106 | ->setParameter('item_source', $row['report']) |
||
107 | ->setParameter('id', $row['id']) |
||
108 | ; |
||
109 | $update->executeStatement(); |
||
110 | } |
||
111 | } |
||
112 | } |
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