diff options
author | Joas Schilling <coding@schilljs.com> | 2019-09-20 11:04:36 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2019-09-27 14:29:56 +0200 |
commit | 45506adc5c2a34a8c812a2a3c9273a8447b450af (patch) | |
tree | adc63ec1a19b2351eac77962010999c5029c9fc4 /core/Migrations | |
parent | 88b6dc5eaf28b1bfe72a62773e8a9ce339979ea3 (diff) | |
download | nextcloud-server-45506adc5c2a34a8c812a2a3c9273a8447b450af.tar.gz nextcloud-server-45506adc5c2a34a8c812a2a3c9273a8447b450af.zip |
Add a displayname to the database group backend
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'core/Migrations')
-rw-r--r-- | core/Migrations/Version18000Date20190920085628.php | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/core/Migrations/Version18000Date20190920085628.php b/core/Migrations/Version18000Date20190920085628.php new file mode 100644 index 00000000000..8464057e4db --- /dev/null +++ b/core/Migrations/Version18000Date20190920085628.php @@ -0,0 +1,74 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OC\Core\Migrations; + +use Closure; +use Doctrine\DBAL\Types\Type; +use OCP\DB\ISchemaWrapper; +use OCP\IDBConnection; +use OCP\Migration\SimpleMigrationStep; +use OCP\Migration\IOutput; + +class Version18000Date20190920085628 extends SimpleMigrationStep { + + /** @var IDBConnection */ + protected $connection; + + public function __construct(IDBConnection $connection) { + $this->connection = $connection; + } + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null|ISchemaWrapper + */ + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + if ($schema->hasTable('groups')) { + $table = $schema->getTable('groups'); + + $table->addColumn('displayname', Type::STRING, [ + 'notnull' => true, + 'length' => 255, + ]); + } + + return $schema; + } + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + */ + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { + $query = $this->connection->getQueryBuilder(); + $query->update('groups') + ->set('displayname', 'gid'); + $query->execute(); + } +} |