Skip to content

Commit 6612976

Browse files
authored
Merge pull request #534 from nextcloud/make-column-nullable
Allow nullable values as subject params
2 parents fa6749a + d93b5d9 commit 6612976

4 files changed

Lines changed: 64 additions & 3 deletions

File tree

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
More information is available in the Activity documentation.
1515
</description>
1616

17-
<version>2.14.2</version>
17+
<version>2.14.3</version>
1818
<licence>agpl</licence>
1919
<author>Frank Karlitschek</author>
2020
<author>Joas Schilling</author>

lib/Migration/Version2011Date20201006132544.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
6161
// Can't switch from Long to clob on Oracle, so we need an intermediate column
6262
if ($column->getType() !== Type::getType('text')) {
6363
$table->addColumn('amq_subjectparams2', 'text', [
64-
'notnull' => true,
64+
'notnull' => false,
6565
]);
6666
}
6767

lib/Migration/Version2011Date20201006132546.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
5353
$table = $schema->getTable('activity_mq');
5454
if (!$table->hasColumn('amq_subjectparams')) {
5555
$table->addColumn('amq_subjectparams', 'text', [
56-
'notnull' => true,
56+
'notnull' => false,
5757
]);
5858
return $schema;
5959
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
7+
*
8+
* @author Joas Schilling <coding@schilljs.com>
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 OCA\Activity\Migration;
28+
29+
use Closure;
30+
use OCP\DB\ISchemaWrapper;
31+
use OCP\Migration\IOutput;
32+
use OCP\Migration\SimpleMigrationStep;
33+
34+
class Version2011Date20201207091915 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, 'activity_mq', 'amq_subjectparams');
46+
47+
return $result ? $schema : null;
48+
}
49+
50+
protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool {
51+
$table = $schema->getTable($tableName);
52+
$column = $table->getColumn($columnName);
53+
54+
if ($column->getNotnull()) {
55+
$column->setNotnull(false);
56+
return true;
57+
}
58+
59+
return false;
60+
}
61+
}

0 commit comments

Comments
 (0)