1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Circles - Bring cloud-users closer together. |
7
|
|
|
* |
8
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
9
|
|
|
* later. See the COPYING file. |
10
|
|
|
* |
11
|
|
|
* @author Maxence Lange <[email protected]> |
12
|
|
|
* @copyright 2021 |
13
|
|
|
* @license GNU AGPL version 3 or any later version |
14
|
|
|
* |
15
|
|
|
* This program is free software: you can redistribute it and/or modify |
16
|
|
|
* it under the terms of the GNU Affero General Public License as |
17
|
|
|
* published by the Free Software Foundation, either version 3 of the |
18
|
|
|
* License, or (at your option) any later version. |
19
|
|
|
* |
20
|
|
|
* This program is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU Affero General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* You should have received a copy of the GNU Affero General Public License |
26
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
27
|
|
|
* |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
namespace OCA\Circles\Migration; |
31
|
|
|
|
32
|
|
|
use Closure; |
33
|
|
|
use Doctrine\DBAL\Schema\SchemaException; |
34
|
|
|
use OC\DB\Connection; |
35
|
|
|
use OCP\DB\ISchemaWrapper; |
36
|
|
|
use OCP\Migration\IOutput; |
37
|
|
|
use OCP\Migration\SimpleMigrationStep; |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Class Version0021Date20210105123456 |
42
|
|
|
* |
43
|
|
|
* @package OCA\Circles\Migration |
44
|
|
|
*/ |
45
|
|
|
class Version0022Date20220526111723 extends SimpleMigrationStep { |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** @var Connection */ |
49
|
|
|
private $connection; |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param Connection $connection |
54
|
|
|
*/ |
55
|
|
|
public function __construct(Connection $connection) { |
56
|
|
|
$this->connection = $connection; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param IOutput $output |
62
|
|
|
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
63
|
|
|
* @param array $options |
64
|
|
|
* |
65
|
|
|
* @return null|ISchemaWrapper |
66
|
|
|
* @throws SchemaException |
67
|
|
|
*/ |
68
|
|
|
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
69
|
|
|
/** @var ISchemaWrapper $schema */ |
70
|
|
|
$schema = $schemaClosure(); |
71
|
|
|
|
72
|
|
|
// check if migration to 22 already done |
73
|
|
|
if ($schema->hasTable('circles_event')) { |
74
|
|
|
return $schema; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$prefix = $this->connection->getPrefix(); |
78
|
|
|
$tables = $schema->getTables(); |
79
|
|
|
foreach ($tables as $table) { |
80
|
|
|
$tableName = $table->getName(); |
81
|
|
|
if (substr($tableName, 0, 8 + strlen($prefix)) === $prefix . 'circles_') { |
82
|
|
|
$tableName = substr($tableName, strlen($prefix)); |
83
|
|
|
$schema->dropTable($tableName); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $schema; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|