|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace OCA\Analytics\Migration; |
|
6
|
|
|
|
|
7
|
|
|
use Closure; |
|
8
|
|
|
use OCP\DB\ISchemaWrapper; |
|
9
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder; |
|
10
|
|
|
use OCP\IDBConnection; |
|
11
|
|
|
use OCP\Migration\IOutput; |
|
12
|
|
|
use OCP\Migration\SimpleMigrationStep; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Auto-generated migration step: Please modify to your needs! |
|
16
|
|
|
* sudo -u www-data php /var/www/nextcloud/occ migrations:execute analytics 3006Date20210601180000 |
|
17
|
|
|
*/ |
|
18
|
|
|
class Version3006Date20210601180000 extends SimpleMigrationStep |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** @var IDBConnection */ |
|
22
|
|
|
private $connection; |
|
23
|
|
|
|
|
24
|
|
|
public function __construct(IDBConnection $connection) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->connection = $connection; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param IOutput $output |
|
31
|
|
|
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
32
|
|
|
* @param array $options |
|
33
|
|
|
*/ |
|
34
|
|
|
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) |
|
35
|
|
|
{ |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param IOutput $output |
|
40
|
|
|
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
41
|
|
|
* @param array $options |
|
42
|
|
|
* @return null|ISchemaWrapper |
|
43
|
|
|
*/ |
|
44
|
|
|
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) |
|
45
|
|
|
{ |
|
46
|
|
|
/** @var ISchemaWrapper $schema */ |
|
47
|
|
|
$schema = $schemaClosure(); |
|
48
|
|
|
|
|
49
|
|
|
if (!$schema->hasTable('analytics_report')) { |
|
50
|
|
|
$table = $schema->createTable('analytics_report'); |
|
51
|
|
|
$table->addColumn('id', 'integer', [ |
|
52
|
|
|
'autoincrement' => true, |
|
53
|
|
|
'notnull' => true, |
|
54
|
|
|
]); |
|
55
|
|
|
$table->addColumn('user_id', 'string', [ |
|
56
|
|
|
'notnull' => true, |
|
57
|
|
|
'length' => 64, |
|
58
|
|
|
]); |
|
59
|
|
|
$table->addColumn('name', 'string', [ |
|
60
|
|
|
'notnull' => true, |
|
61
|
|
|
'length' => 64, |
|
62
|
|
|
]); |
|
63
|
|
|
$table->addColumn('subheader', 'string', [ |
|
64
|
|
|
'notnull' => false, |
|
65
|
|
|
'length' => 256, |
|
66
|
|
|
]); |
|
67
|
|
|
$table->addColumn('dataset', 'integer', [ |
|
68
|
|
|
'notnull' => false, |
|
69
|
|
|
]); |
|
70
|
|
|
$table->addColumn('visualization', 'string', [ |
|
71
|
|
|
'notnull' => false, |
|
72
|
|
|
'length' => 10, |
|
73
|
|
|
]); |
|
74
|
|
|
$table->addColumn('chart', 'string', [ |
|
75
|
|
|
'notnull' => false, |
|
76
|
|
|
'length' => 256, |
|
77
|
|
|
]); |
|
78
|
|
|
$table->addColumn('parent', 'integer', [ |
|
79
|
|
|
'notnull' => false, |
|
80
|
|
|
]); |
|
81
|
|
|
$table->addColumn('chartoptions', 'string', [ |
|
82
|
|
|
'notnull' => false, |
|
83
|
|
|
'length' => 1000, |
|
84
|
|
|
]); |
|
85
|
|
|
$table->addColumn('dataoptions', 'string', [ |
|
86
|
|
|
'notnull' => false, |
|
87
|
|
|
'length' => 1000, |
|
88
|
|
|
]); |
|
89
|
|
|
$table->addColumn('filteroptions', 'string', [ |
|
90
|
|
|
'notnull' => false, |
|
91
|
|
|
'length' => 1000, |
|
92
|
|
|
]); |
|
93
|
|
|
$table->setPrimaryKey(['id']); |
|
94
|
|
|
$table->addIndex(['dataset'], 'analytics_report_dataset_idx'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return $schema; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param IOutput $output |
|
102
|
|
|
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
103
|
|
|
* @param array $options |
|
104
|
|
|
*/ |
|
105
|
|
|
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) |
|
106
|
|
|
{ |
|
107
|
|
|
$reportIdMap = []; |
|
108
|
|
|
|
|
109
|
|
|
$insert = $this->connection->getQueryBuilder(); |
|
110
|
|
|
$insert->insert('analytics_report') |
|
111
|
|
|
->values([ |
|
112
|
|
|
'name' => $insert->createParameter('name'), |
|
113
|
|
|
'user_id' => $insert->createParameter('user_id'), |
|
114
|
|
|
'subheader' => $insert->createParameter('subheader'), |
|
115
|
|
|
'dataset' => $insert->createParameter('dataset'), |
|
116
|
|
|
'visualization' => $insert->createParameter('visualization'), |
|
117
|
|
|
'chart' => $insert->createParameter('chart'), |
|
118
|
|
|
'parent' => $insert->createParameter('parent'), |
|
119
|
|
|
'chartoptions' => $insert->createParameter('chartoptions'), |
|
120
|
|
|
'dataoptions' => $insert->createParameter('dataoptions'), |
|
121
|
|
|
'filteroptions' => $insert->createParameter('filteroptions'), |
|
122
|
|
|
]); |
|
123
|
|
|
|
|
124
|
|
|
$query = $this->connection->getQueryBuilder(); |
|
125
|
|
|
$query->select('*') |
|
126
|
|
|
->from('analytics_dataset'); |
|
127
|
|
|
|
|
128
|
|
|
$result = $query->execute(); |
|
|
|
|
|
|
129
|
|
|
while ($row = $result->fetch()) { |
|
130
|
|
|
$insert |
|
131
|
|
|
->setParameter('name', $row['name']) |
|
132
|
|
|
->setParameter('user_id', $row['user_id']) |
|
133
|
|
|
->setParameter('subheader', $row['subheader']) |
|
134
|
|
|
->setParameter('dataset', (int)$row['id'], IQueryBuilder::PARAM_INT) |
|
135
|
|
|
->setParameter('visualization', $row['visualization']) |
|
136
|
|
|
->setParameter('chart', $row['chart']) |
|
137
|
|
|
->setParameter('parent', (int)$row['parent'], IQueryBuilder::PARAM_INT) |
|
138
|
|
|
->setParameter('chartoptions', $row['chartoptions']) |
|
139
|
|
|
->setParameter('dataoptions', $row['dataoptions']) |
|
140
|
|
|
->setParameter('filteroptions', $row['filteroptions']); |
|
141
|
|
|
$insert->execute(); |
|
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
$reportIdMap[(int)$row['id']] = $insert->getLastInsertId(); |
|
144
|
|
|
} |
|
145
|
|
|
$result->closeCursor(); |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.