1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* CMS Pico - Create websites using Pico CMS for Nextcloud. |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2019, Daniel Rudolf (<[email protected]>) |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
declare(strict_types=1); |
24
|
|
|
|
25
|
|
|
namespace OCA\CMSPico\Migration; |
26
|
|
|
|
27
|
|
|
use Doctrine\DBAL\Schema\SchemaException; |
28
|
|
|
use OCA\CMSPico\Db\CoreRequestBuilder; |
29
|
|
|
use OCA\CMSPico\Service\MiscService; |
30
|
|
|
use OCP\DB\ISchemaWrapper; |
31
|
|
|
use OCP\Migration\IOutput; |
32
|
|
|
use OCP\Migration\SimpleMigrationStep; |
33
|
|
|
|
34
|
|
|
class Version010000 extends SimpleMigrationStep |
35
|
|
|
{ |
36
|
|
|
/** @var MiscService */ |
37
|
|
|
private $miscService; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Version010000 constructor. |
41
|
|
|
*/ |
42
|
|
|
public function __construct() |
43
|
|
|
{ |
44
|
|
|
$this->miscService = \OC::$server->query(MiscService::class); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param IOutput $output |
49
|
|
|
* @param \Closure $schemaClosure |
50
|
|
|
* @param array $options |
51
|
|
|
* |
52
|
|
|
* @return ISchemaWrapper |
53
|
|
|
*/ |
54
|
|
|
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options): ISchemaWrapper |
55
|
|
|
{ |
56
|
|
|
/** @var ISchemaWrapper $schema */ |
57
|
|
|
$schema = $schemaClosure(); |
58
|
|
|
|
59
|
|
|
try { |
60
|
|
|
$table = $schema->getTable(CoreRequestBuilder::TABLE_WEBSITES); |
61
|
|
|
} catch (SchemaException $e) { |
62
|
|
|
$table = $schema->createTable(CoreRequestBuilder::TABLE_WEBSITES); |
63
|
|
|
|
64
|
|
|
$table->addColumn('id', 'integer', [ |
65
|
|
|
'autoincrement' => true, |
66
|
|
|
'notnull' => true, |
67
|
|
|
'length' => 4, |
68
|
|
|
'unsigned' => true, |
69
|
|
|
]); |
70
|
|
|
$table->addColumn('user_id', 'string', [ |
71
|
|
|
'notnull' => true, |
72
|
|
|
'length' => 64, |
73
|
|
|
]); |
74
|
|
|
$table->addColumn('name', 'string', [ |
75
|
|
|
'notnull' => true, |
76
|
|
|
'length' => 255, |
77
|
|
|
]); |
78
|
|
|
$table->addColumn('site', 'string', [ |
79
|
|
|
'notnull' => true, |
80
|
|
|
'length' => 255, |
81
|
|
|
]); |
82
|
|
|
$table->addColumn('theme', 'string', [ |
83
|
|
|
'notnull' => true, |
84
|
|
|
'length' => 64, |
85
|
|
|
'default' => 'default', |
86
|
|
|
]); |
87
|
|
|
$table->addColumn('type', 'smallint', [ |
88
|
|
|
'notnull' => true, |
89
|
|
|
'length' => 1, |
90
|
|
|
]); |
91
|
|
|
$table->addColumn('options', 'string', [ |
92
|
|
|
'notnull' => false, |
93
|
|
|
'length' => 255, |
94
|
|
|
]); |
95
|
|
|
$table->addColumn('path', 'string', [ |
96
|
|
|
'notnull' => false, |
97
|
|
|
'length' => 255, |
98
|
|
|
]); |
99
|
|
|
$table->addColumn('creation', 'datetime', [ |
100
|
|
|
'notnull' => false, |
101
|
|
|
]); |
102
|
|
|
|
103
|
|
|
$table->setPrimaryKey(['id']); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$themeColumn = $table->getColumn('theme'); |
107
|
|
|
if ($themeColumn->getLength() < 64) { |
108
|
|
|
$themeColumn->setLength(64); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
if (!$table->hasIndex('user_id')) { |
112
|
|
|
$table->addIndex([ 'user_id' ], 'user_id'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
if (!$table->hasIndex('site')) { |
116
|
|
|
$table->addIndex([ 'site' ], 'site'); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return $schema; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param IOutput $output |
124
|
|
|
* @param \Closure $schemaClosure |
125
|
|
|
* @param array $options |
126
|
|
|
*/ |
127
|
|
|
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) |
128
|
|
|
{ |
129
|
|
|
$this->miscService->checkComposer(); |
130
|
|
|
$this->miscService->checkPublicFolder(); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|