Skip to content

Commit

Permalink
Cleanup tags and Share component
Browse files Browse the repository at this point in the history
- Port to LoggerInterface
- Use IDBConnection and IQueryBuilder instead of raw SQL and OC_DB
- Use IEventListener instead of hooks
- Remove the now unused OC_DB and OC_DB_StatementWrapper legacy utils

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
  • Loading branch information
CarlSchwan committed Sep 19, 2022
1 parent ca747b9 commit b2b3286
Show file tree
Hide file tree
Showing 16 changed files with 589 additions and 856 deletions.
10 changes: 8 additions & 2 deletions core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use OC\DB\MissingPrimaryKeyInformation;
use OC\DB\SchemaWrapper;
use OC\Metadata\FileEventListener;
use OC\TagManager;
use OCP\AppFramework\App;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Events\Node\NodeDeletedEvent;
Expand Down Expand Up @@ -78,7 +79,7 @@ public function __construct() {

$server = $container->getServer();
/** @var IEventDispatcher $eventDispatcher */
$eventDispatcher = $server->query(IEventDispatcher::class);
$eventDispatcher = $server->get(IEventDispatcher::class);

$notificationManager = $server->getNotificationManager();
$notificationManager->registerNotifierService(CoreNotifier::class);
Expand Down Expand Up @@ -325,10 +326,15 @@ function (GenericEvent $event) use ($container) {
/** @var IConfig $config */
$config = $container->get(IConfig::class);
if ($config->getSystemValueBool('enable_file_metadata', true)) {
$eventDispatcher = \OC::$server->get(IEventDispatcher::class);
/** @@psalm-suppress InvalidArgument */
$eventDispatcher->addServiceListener(NodeDeletedEvent::class, FileEventListener::class);
/** @@psalm-suppress InvalidArgument */
$eventDispatcher->addServiceListener(NodeRemovedFromCache::class, FileEventListener::class);
/** @@psalm-suppress InvalidArgument */
$eventDispatcher->addServiceListener(NodeWrittenEvent::class, FileEventListener::class);
}

// Tags
$eventDispatcher->addServiceListener(UserDeletedEvent::class, TagManager::class);
}
}
2 changes: 0 additions & 2 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1590,8 +1590,6 @@
'OC\\User\\User' => $baseDir . '/lib/private/User/User.php',
'OC_API' => $baseDir . '/lib/private/legacy/OC_API.php',
'OC_App' => $baseDir . '/lib/private/legacy/OC_App.php',
'OC_DB' => $baseDir . '/lib/private/legacy/OC_DB.php',
'OC_DB_StatementWrapper' => $baseDir . '/lib/private/legacy/OC_DB_StatementWrapper.php',
'OC_Defaults' => $baseDir . '/lib/private/legacy/OC_Defaults.php',
'OC_EventSource' => $baseDir . '/lib/private/legacy/OC_EventSource.php',
'OC_FileChunking' => $baseDir . '/lib/private/legacy/OC_FileChunking.php',
Expand Down
2 changes: 0 additions & 2 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1623,8 +1623,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\User\\User' => __DIR__ . '/../../..' . '/lib/private/User/User.php',
'OC_API' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_API.php',
'OC_App' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_App.php',
'OC_DB' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_DB.php',
'OC_DB_StatementWrapper' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_DB_StatementWrapper.php',
'OC_Defaults' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_Defaults.php',
'OC_EventSource' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_EventSource.php',
'OC_FileChunking' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_FileChunking.php',
Expand Down
3 changes: 3 additions & 0 deletions lib/private/Accounts/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
use OCP\User\Events\UserChangedEvent;
use Psr\Log\LoggerInterface;

/**
* @template-implements IEventListener<UserChangedEvent>
*/
class Hooks implements IEventListener {

/** @var IAccountManager */
Expand Down
6 changes: 4 additions & 2 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
use OC\Files\Mount\MoveableMount;
use OC\Files\Storage\Storage;
use OC\User\LazyUser;
use OC\Share\Share;
use OC\User\User;
use OCA\Files_Sharing\SharedMount;
use OCP\Constants;
use OCP\Files\Cache\ICacheEntry;
Expand Down Expand Up @@ -1800,10 +1802,10 @@ private function targetIsNotShared(IStorage $targetStorage, string $targetIntern
}

// check if any of the parents were shared by the current owner (include collections)
$shares = \OCP\Share::getItemShared(
$shares = Share::getItemShared(
'folder',
$fileId,
\OCP\Share::FORMAT_NONE,
\OC\Share\Constants::FORMAT_NONE,
null,
true
);
Expand Down
5 changes: 5 additions & 0 deletions lib/private/Metadata/FileEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
use OCP\Files\FileInfo;
use Psr\Log\LoggerInterface;

/**
* @template-implements IEventListener<NodeRemovedFromCache>
* @template-implements IEventListener<NodeDeletedEvent>
* @template-implements IEventListener<NodeWrittenEvent>
*/
class FileEventListener implements IEventListener {
private IMetadataManager $manager;
private LoggerInterface $logger;
Expand Down
Loading

0 comments on commit b2b3286

Please sign in to comment.