1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @copyright Copyright (c) 2020 Joas Schilling <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @author Joas Schilling <[email protected]> |
9
|
|
|
* |
10
|
|
|
* @license GNU AGPL version 3 or any later version |
11
|
|
|
* |
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
15
|
|
|
* License, or (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, |
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
* GNU Affero General Public License for more details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
24
|
|
|
* |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace OC\Core\Migrations; |
28
|
|
|
|
29
|
|
|
use Closure; |
30
|
|
|
use OCP\DB\ISchemaWrapper; |
31
|
|
|
use OCP\Migration\IOutput; |
32
|
|
|
use OCP\Migration\SimpleMigrationStep; |
33
|
|
|
|
34
|
|
|
class Version20000Date20201109081915 extends SimpleMigrationStep { |
35
|
|
|
/** |
36
|
|
|
* @param IOutput $output |
37
|
|
|
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
38
|
|
|
* @param array $options |
39
|
|
|
* @return null|ISchemaWrapper |
40
|
|
|
*/ |
41
|
|
|
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
42
|
|
|
/** @var ISchemaWrapper $schema */ |
43
|
|
|
$schema = $schemaClosure(); |
44
|
|
|
|
45
|
|
|
$result = $this->ensureColumnIsNullable($schema, 'share', 'password_by_talk'); |
46
|
|
|
$result = $this->ensureColumnIsNullable($schema, 'share', 'hide_download') || $result; |
47
|
|
|
// $result = $this->ensureColumnIsNullable($schema, 'credentials', 'user') || $result; |
48
|
|
|
$result = $this->ensureColumnIsNullable($schema, 'authtoken', 'password_invalid') || $result; |
49
|
|
|
$result = $this->ensureColumnIsNullable($schema, 'collres_accesscache', 'access') || $result; |
50
|
|
|
|
51
|
|
|
return $result ? $schema : null; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool { |
55
|
|
|
$table = $schema->getTable($tableName); |
56
|
|
|
$column = $table->getColumn($columnName); |
57
|
|
|
|
58
|
|
|
if ($column->getNotnull()) { |
59
|
|
|
$column->setNotnull(false); |
60
|
|
|
return true; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return false; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|