diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-04-04 23:15:00 +0200 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-04-13 14:06:29 +0200 |
commit | 781784553889601d02553931aed8ff1fde95640b (patch) | |
tree | 21dd1b23c192d23be1ab1f468ff77165b7591172 /core | |
parent | cd95fce105fe5f0e71b1bcac7685464f936b9749 (diff) | |
download | nextcloud-server-781784553889601d02553931aed8ff1fde95640b.tar.gz nextcloud-server-781784553889601d02553931aed8ff1fde95640b.zip |
Add a metadata service to store file metadata
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'core')
-rw-r--r-- | core/Application.php | 15 | ||||
-rw-r--r-- | core/Migrations/Version240000Date20220404230027.php | 62 |
2 files changed, 77 insertions, 0 deletions
diff --git a/core/Application.php b/core/Application.php index 545588ab208..34932cab183 100644 --- a/core/Application.php +++ b/core/Application.php @@ -48,12 +48,17 @@ use OC\DB\MissingColumnInformation; use OC\DB\MissingIndexInformation; use OC\DB\MissingPrimaryKeyInformation; use OC\DB\SchemaWrapper; +use OC\Metadata\FileEventListener; use OCP\AppFramework\App; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Events\Node\NodeDeletedEvent; +use OCP\Files\Events\Node\NodeWrittenEvent; +use OCP\Files\Events\NodeRemovedFromCache; use OCP\IDBConnection; use OCP\User\Events\BeforeUserDeletedEvent; use OCP\User\Events\UserDeletedEvent; use OCP\Util; +use OCP\IConfig; use Symfony\Component\EventDispatcher\GenericEvent; /** @@ -301,5 +306,15 @@ class Application extends App { $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, UserDeletedFilesCleanupListener::class); $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedFilesCleanupListener::class); $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedWebAuthnCleanupListener::class); + + // Metadata + /** @var IConfig $config */ + $config = $container->get(IConfig::class); + if ($config->getSystemValueBool('enable_file_metadata', true)) { + $eventDispatcher = \OC::$server->get(IEventDispatcher::class); + $eventDispatcher->addServiceListener(NodeDeletedEvent::class, FileEventListener::class); + $eventDispatcher->addServiceListener(NodeRemovedFromCache::class, FileEventListener::class); + $eventDispatcher->addServiceListener(NodeWrittenEvent::class, FileEventListener::class); + } } } diff --git a/core/Migrations/Version240000Date20220404230027.php b/core/Migrations/Version240000Date20220404230027.php new file mode 100644 index 00000000000..f45f8d5b500 --- /dev/null +++ b/core/Migrations/Version240000Date20220404230027.php @@ -0,0 +1,62 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright 2022 Carl Schwan <carl@carlschwan.eu> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OC\Core\Migrations; + +use Closure; +use OCP\DB\ISchemaWrapper; +use OCP\DB\Types; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; + +/** + * Add oc_file_metadata table + * @see OC\Metadata\FileMetadata + */ +class Version240000Date20220404230027 extends SimpleMigrationStep { + /** + * @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('file_metadata')) { + $table = $schema->createTable('file_metadata'); + $table->addColumn('id', Types::INTEGER, [ + 'notnull' => true, + ]); + $table->addColumn('group_name', Types::STRING, [ + 'notnull' => true, + 'length' => 50, + ]); + $table->addColumn('metadata', Types::JSON, [ + 'notnull' => true, + ]); + $table->setPrimaryKey(['id', 'group_name'], 'file_metadata_idx'); + } + return $schema; + } +} |