Browse Source

feat!: Migrate TagService events to typed events

Signed-off-by: Joas Schilling <coding@schilljs.com>
tags/v28.0.0beta1
Joas Schilling 10 months ago
parent
commit
9bf812ac6c
No account linked to committer's email address

+ 2
- 1
apps/files/lib/AppInfo/Application.php View File

@@ -57,6 +57,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Collaboration\Reference\RenderReferenceEvent;
use OCP\Collaboration\Resources\IProviderManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IPreview;
@@ -110,7 +111,7 @@ class Application extends App implements IBootstrap {
$c->get(IActivityManager::class),
$c->get(ITagManager::class)->load(self::APP_ID),
$server->getUserFolder(),
$server->getEventDispatcher()
$c->get(IEventDispatcher::class),
);
});


+ 11
- 10
apps/files/lib/Service/TagService.php View File

@@ -26,12 +26,13 @@ namespace OCA\Files\Service;

use OCA\Files\Activity\FavoriteProvider;
use OCP\Activity\IManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Events\NodeAddedToFavorite;
use OCP\Files\Events\NodeRemovedFromFavorite;
use OCP\Files\Folder;
use OCP\ITags;
use OCP\IUser;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

/**
* Service class to manage tags on files.
@@ -46,7 +47,7 @@ class TagService {
private $tagger;
/** @var Folder|null */
private $homeFolder;
/** @var EventDispatcherInterface */
/** @var IEventDispatcher */
private $dispatcher;

public function __construct(
@@ -54,7 +55,7 @@ class TagService {
IManager $activityManager,
?ITags $tagger,
?Folder $homeFolder,
EventDispatcherInterface $dispatcher
IEventDispatcher $dispatcher,
) {
$this->userSession = $userSession;
$this->activityManager = $activityManager;
@@ -120,12 +121,12 @@ class TagService {
return;
}

$eventName = $addToFavorite ? 'addFavorite' : 'removeFavorite';
$this->dispatcher->dispatch(self::class . '::' . $eventName, new GenericEvent(null, [
'userId' => $user->getUID(),
'fileId' => $fileId,
'path' => $path,
]));
if ($addToFavorite) {
$event = new NodeAddedToFavorite($user, $fileId, $path);
} else {
$event = new NodeRemovedFromFavorite($user, $fileId, $path);
}
$this->dispatcher->dispatchTyped($event);

$event = $this->activityManager->generateEvent();
try {

+ 3
- 3
apps/files/tests/Service/TagServiceTest.php View File

@@ -29,10 +29,10 @@ namespace OCA\Files\Tests\Service;

use OCA\Files\Service\TagService;
use OCP\Activity\IManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ITags;
use OCP\IUser;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* Class TagServiceTest
@@ -59,7 +59,7 @@ class TagServiceTest extends \Test\TestCase {
*/
private $root;

/** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
private $dispatcher;

/**
@@ -90,7 +90,7 @@ class TagServiceTest extends \Test\TestCase {
->willReturn($user);

$this->root = \OC::$server->getUserFolder();
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
$this->dispatcher = $this->createMock(IEventDispatcher::class);

$this->tagger = \OC::$server->getTagManager()->load('files');
$this->tagService = $this->getTagService(['addActivity']);

+ 2
- 0
lib/composer/composer/autoload_classmap.php View File

@@ -309,7 +309,9 @@ return array(
'OCP\\Files\\Events\\FolderScannedEvent' => $baseDir . '/lib/public/Files/Events/FolderScannedEvent.php',
'OCP\\Files\\Events\\InvalidateMountCacheEvent' => $baseDir . '/lib/public/Files/Events/InvalidateMountCacheEvent.php',
'OCP\\Files\\Events\\NodeAddedToCache' => $baseDir . '/lib/public/Files/Events/NodeAddedToCache.php',
'OCP\\Files\\Events\\NodeAddedToFavorite' => $baseDir . '/lib/public/Files/Events/NodeAddedToFavorite.php',
'OCP\\Files\\Events\\NodeRemovedFromCache' => $baseDir . '/lib/public/Files/Events/NodeRemovedFromCache.php',
'OCP\\Files\\Events\\NodeRemovedFromFavorite' => $baseDir . '/lib/public/Files/Events/NodeRemovedFromFavorite.php',
'OCP\\Files\\Events\\Node\\AbstractNodeEvent' => $baseDir . '/lib/public/Files/Events/Node/AbstractNodeEvent.php',
'OCP\\Files\\Events\\Node\\AbstractNodesEvent' => $baseDir . '/lib/public/Files/Events/Node/AbstractNodesEvent.php',
'OCP\\Files\\Events\\Node\\BeforeNodeCopiedEvent' => $baseDir . '/lib/public/Files/Events/Node/BeforeNodeCopiedEvent.php',

+ 2
- 0
lib/composer/composer/autoload_static.php View File

@@ -342,7 +342,9 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Files\\Events\\FolderScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/FolderScannedEvent.php',
'OCP\\Files\\Events\\InvalidateMountCacheEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/InvalidateMountCacheEvent.php',
'OCP\\Files\\Events\\NodeAddedToCache' => __DIR__ . '/../../..' . '/lib/public/Files/Events/NodeAddedToCache.php',
'OCP\\Files\\Events\\NodeAddedToFavorite' => __DIR__ . '/../../..' . '/lib/public/Files/Events/NodeAddedToFavorite.php',
'OCP\\Files\\Events\\NodeRemovedFromCache' => __DIR__ . '/../../..' . '/lib/public/Files/Events/NodeRemovedFromCache.php',
'OCP\\Files\\Events\\NodeRemovedFromFavorite' => __DIR__ . '/../../..' . '/lib/public/Files/Events/NodeRemovedFromFavorite.php',
'OCP\\Files\\Events\\Node\\AbstractNodeEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/AbstractNodeEvent.php',
'OCP\\Files\\Events\\Node\\AbstractNodesEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/AbstractNodesEvent.php',
'OCP\\Files\\Events\\Node\\BeforeNodeCopiedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/BeforeNodeCopiedEvent.php',

+ 66
- 0
lib/public/Files/Events/NodeAddedToFavorite.php View File

@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
*
* @author 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 OCP\Files\Events;

use OCP\EventDispatcher\Event;
use OCP\IUser;

/**
* @since 28.0.0
*/
class NodeAddedToFavorite extends Event {
/**
* @since 28.0.0
*/
public function __construct(
protected IUser $user,
protected int $fileId,
protected string $path,
) {
parent::__construct();
}

/**
* @since 28.0.0
*/
public function getUser(): IUser {
return $this->user;
}

/**
* @since 28.0.0
*/
public function getFileId(): int {
return $this->fileId;
}

/**
* @since 28.0.0
*/
public function getPath(): string {
return $this->path;
}
}

+ 66
- 0
lib/public/Files/Events/NodeRemovedFromFavorite.php View File

@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
*
* @author 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 OCP\Files\Events;

use OCP\EventDispatcher\Event;
use OCP\IUser;

/**
* @since 28.0.0
*/
class NodeRemovedFromFavorite extends Event {
/**
* @since 28.0.0
*/
public function __construct(
protected IUser $user,
protected int $fileId,
protected string $path,
) {
parent::__construct();
}

/**
* @since 28.0.0
*/
public function getUser(): IUser {
return $this->user;
}

/**
* @since 28.0.0
*/
public function getFileId(): int {
return $this->fileId;
}

/**
* @since 28.0.0
*/
public function getPath(): string {
return $this->path;
}
}

Loading…
Cancel
Save