| Total Complexity | 15 |
| Total Lines | 266 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | class Version3007Date20211003180000 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) |
||
| 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('dataset', 'integer', [ |
||
| 60 | 'notnull' => true, |
||
| 61 | ]); |
||
| 62 | $table->addColumn('name', 'string', [ |
||
| 63 | 'notnull' => true, |
||
| 64 | 'length' => 64, |
||
| 65 | ]); |
||
| 66 | $table->addColumn('subheader', 'string', [ |
||
| 67 | 'notnull' => false, |
||
| 68 | 'length' => 256, |
||
| 69 | ]); |
||
| 70 | $table->addColumn('type', 'integer', [ |
||
| 71 | 'notnull' => false, |
||
| 72 | ]); |
||
| 73 | $table->addColumn('link', 'string', [ |
||
| 74 | 'notnull' => false, |
||
| 75 | 'length' => 500, |
||
| 76 | ]); |
||
| 77 | $table->addColumn('visualization', 'string', [ |
||
| 78 | 'notnull' => false, |
||
| 79 | 'length' => 10, |
||
| 80 | ]); |
||
| 81 | $table->addColumn('chart', 'string', [ |
||
| 82 | 'notnull' => false, |
||
| 83 | 'length' => 256, |
||
| 84 | ]); |
||
| 85 | $table->addColumn('parent', 'integer', [ |
||
| 86 | 'notnull' => false, |
||
| 87 | ]); |
||
| 88 | $table->addColumn('dimension1', 'string', [ |
||
| 89 | 'notnull' => false, |
||
| 90 | 'length' => 64, |
||
| 91 | ]); |
||
| 92 | $table->addColumn('dimension2', 'string', [ |
||
| 93 | 'notnull' => false, |
||
| 94 | 'length' => 64, |
||
| 95 | ]); |
||
| 96 | $table->addColumn('dimension3', 'string', [ |
||
| 97 | 'notnull' => false, |
||
| 98 | 'length' => 64, |
||
| 99 | ]); |
||
| 100 | $table->addColumn('value', 'string', [ |
||
| 101 | 'notnull' => false, |
||
| 102 | 'length' => 64, |
||
| 103 | ]); |
||
| 104 | $table->addColumn('chartoptions', 'string', [ |
||
| 105 | 'notnull' => false, |
||
| 106 | 'length' => 1000, |
||
| 107 | ]); |
||
| 108 | $table->addColumn('dataoptions', 'string', [ |
||
| 109 | 'notnull' => false, |
||
| 110 | 'length' => 1000, |
||
| 111 | ]); |
||
| 112 | $table->addColumn('filteroptions', 'string', [ |
||
| 113 | 'notnull' => false, |
||
| 114 | 'length' => 1000, |
||
| 115 | ]); |
||
| 116 | $table->addColumn('refresh', 'integer', [ |
||
| 117 | 'notnull' => false, |
||
| 118 | ]); |
||
| 119 | $table->setPrimaryKey(['id']); |
||
| 120 | $table->addIndex(['user_id'], 'analytics_report_user_id_idx'); |
||
| 121 | } |
||
| 122 | |||
| 123 | $table = $schema->getTable('analytics_share'); |
||
| 124 | if (!$table->hasColumn('report')) { |
||
| 125 | $table->addColumn('report', 'integer', [ |
||
| 126 | 'notnull' => false, |
||
| 127 | ]); |
||
| 128 | } |
||
| 129 | |||
| 130 | $table = $schema->getTable('analytics_threshold'); |
||
| 131 | if (!$table->hasColumn('report')) { |
||
| 132 | $table->addColumn('report', 'integer', [ |
||
| 133 | 'notnull' => false, |
||
| 134 | ]); |
||
| 135 | } |
||
| 136 | |||
| 137 | return $schema; |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @param IOutput $output |
||
| 142 | * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
||
| 143 | * @param array $options |
||
| 144 | */ |
||
| 145 | public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) |
||
| 146 | { |
||
| 147 | $reportIdMap = $this->copyReport(); |
||
| 148 | $this->fixShares($reportIdMap); |
||
| 149 | $this->fixThreshold($reportIdMap); |
||
| 150 | $this->fixParents($reportIdMap); |
||
| 151 | } |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @return int[] |
||
| 155 | */ |
||
| 156 | protected function copyReport(): array { |
||
| 157 | $reportIdMap = []; |
||
| 158 | |||
| 159 | $insert = $this->connection->getQueryBuilder(); |
||
| 160 | $insert->insert('analytics_report') |
||
| 161 | ->values([ |
||
| 162 | 'user_id' => $insert->createParameter('user_id'), |
||
| 163 | 'dataset' => $insert->createParameter('dataset'), |
||
| 164 | 'name' => $insert->createParameter('name'), |
||
| 165 | 'subheader' => $insert->createParameter('subheader'), |
||
| 166 | 'type' => $insert->createParameter('type'), |
||
| 167 | 'link' => $insert->createParameter('link'), |
||
| 168 | 'visualization' => $insert->createParameter('visualization'), |
||
| 169 | 'chart' => $insert->createParameter('chart'), |
||
| 170 | 'parent' => $insert->createParameter('parent'), |
||
| 171 | 'dimension1' => $insert->createParameter('dimension1'), |
||
| 172 | 'dimension2' => $insert->createParameter('dimension2'), |
||
| 173 | 'dimension3' => $insert->createParameter('dimension3'), |
||
| 174 | 'value' => $insert->createParameter('value'), |
||
| 175 | 'chartoptions' => $insert->createParameter('chartoptions'), |
||
| 176 | 'dataoptions' => $insert->createParameter('dataoptions'), |
||
| 177 | 'filteroptions' => $insert->createParameter('filteroptions'), |
||
| 178 | 'refresh' => $insert->createParameter('refresh'), |
||
| 179 | ]); |
||
| 180 | |||
| 181 | $query = $this->connection->getQueryBuilder(); |
||
| 182 | $query->select('*') |
||
| 183 | ->from('analytics_dataset'); |
||
| 184 | |||
| 185 | $result = $query->execute(); |
||
|
1 ignored issue
–
show
|
|||
| 186 | while ($row = $result->fetch()) { |
||
| 187 | $insert |
||
| 188 | ->setParameter('user_id', $row['user_id']) |
||
| 189 | ->setParameter('dataset', (int) $row['id'], IQueryBuilder::PARAM_INT) |
||
| 190 | ->setParameter('name', $row['name']) |
||
| 191 | ->setParameter('subheader', $row['subheader']) |
||
| 192 | ->setParameter('type', (int) $row['type'], IQueryBuilder::PARAM_INT) |
||
| 193 | ->setParameter('link', $row['link']) |
||
| 194 | ->setParameter('visualization', $row['visualization']) |
||
| 195 | ->setParameter('chart', $row['chart']) |
||
| 196 | ->setParameter('parent', (int) $row['parent'], IQueryBuilder::PARAM_INT) |
||
| 197 | ->setParameter('dimension1', $row['dimension1']) |
||
| 198 | ->setParameter('dimension2', $row['dimension2']) |
||
| 199 | ->setParameter('dimension3', $row['dimension3']) |
||
| 200 | ->setParameter('value', $row['value']) |
||
| 201 | ->setParameter('chartoptions', $row['chartoptions']) |
||
| 202 | ->setParameter('dataoptions', $row['dataoptions']) |
||
| 203 | ->setParameter('filteroptions', $row['filteroptions']) |
||
| 204 | ->setParameter('refresh', (int) $row['refresh'], IQueryBuilder::PARAM_INT); |
||
| 205 | $insert->execute(); |
||
|
1 ignored issue
–
show
|
|||
| 206 | |||
| 207 | $reportIdMap[(int)$row['id']] = $insert->getLastInsertId(); |
||
| 208 | } |
||
| 209 | $result->closeCursor(); |
||
| 210 | |||
| 211 | return $reportIdMap; |
||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @param int[] $reportIdMap |
||
| 216 | */ |
||
| 217 | protected function fixShares(array $reportIdMap): void { |
||
| 218 | |||
| 219 | $update = $this->connection->getQueryBuilder(); |
||
| 220 | $update->update('analytics_share') |
||
| 221 | ->set('report', $update->createParameter('report')) |
||
| 222 | ->where($update->expr()->eq('dataset', $update->createParameter('dataset'))); |
||
| 223 | |||
| 224 | $query = $this->connection->getQueryBuilder(); |
||
| 225 | $query->select(['id']) |
||
| 226 | ->from('analytics_dataset'); |
||
| 227 | $result = $query->execute(); |
||
|
1 ignored issue
–
show
|
|||
| 228 | |||
| 229 | while ($row = $result->fetch()) { |
||
| 230 | $update |
||
| 231 | ->setParameter('report', $reportIdMap[(int) $row['id']]) |
||
| 232 | ->setParameter('dataset', (int) $row['id']) |
||
| 233 | ; |
||
| 234 | $update->execute(); |
||
|
1 ignored issue
–
show
|
|||
| 235 | } |
||
| 236 | } |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @param int[] $reportIdMap |
||
| 240 | */ |
||
| 241 | protected function fixThreshold(array $reportIdMap): void { |
||
| 259 | } |
||
| 260 | } |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @param int[] $reportIdMap |
||
| 264 | */ |
||
| 265 | protected function fixParents(array $reportIdMap): void { |
||
| 284 | } |
||
| 285 | } |
||
| 287 | } |
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.