Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-30749: Passed explicitly event name to dispatcher #2700

Merged
merged 1 commit into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eZ/Publish/API/Repository/Tests/LanguageServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,13 @@ public function testUpdateLanguageName()
public function testUpdateLanguageNameThrowsInvalidArgumentException()
{
$this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class);
$this->expectExceptionMessage('Argument \'newName\' is invalid: \'1\' is wrong value');
$this->expectExceptionMessage('Argument \'newName\' is invalid: \'\' is wrong value');

$repository = $this->getRepository();
$languageService = $repository->getContentLanguageService();

$language = $languageService->loadLanguage('eng-GB');
$languageService->updateLanguageName($language, 1);
$languageService->updateLanguageName($language, '');
}

/**
Expand Down
16 changes: 12 additions & 4 deletions eZ/Publish/Core/Event/BookmarkService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
namespace eZ\Publish\Core\Event;

use eZ\Publish\API\Repository\BookmarkService as BookmarkServiceInterface;
use eZ\Publish\API\Repository\Events\Bookmark\BeforeCreateBookmarkEvent as BeforeCreateBookmarkEventInterface;
use eZ\Publish\API\Repository\Events\Bookmark\BeforeDeleteBookmarkEvent as BeforeDeleteBookmarkEventInterface;
use eZ\Publish\API\Repository\Events\Bookmark\CreateBookmarkEvent as CreateBookmarkEventInterface;
use eZ\Publish\API\Repository\Events\Bookmark\DeleteBookmarkEvent as DeleteBookmarkEventInterface;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\Core\Event\Bookmark\BeforeCreateBookmarkEvent;
use eZ\Publish\Core\Event\Bookmark\BeforeDeleteBookmarkEvent;
Expand Down Expand Up @@ -36,26 +40,30 @@ public function createBookmark(Location $location): void
$eventData = [$location];

$beforeEvent = new BeforeCreateBookmarkEvent(...$eventData);
if ($this->eventDispatcher->dispatch($beforeEvent)->isPropagationStopped()) {

$this->eventDispatcher->dispatch($beforeEvent, BeforeCreateBookmarkEventInterface::class);
if ($beforeEvent->isPropagationStopped()) {
return;
}

$this->innerService->createBookmark($location);

$this->eventDispatcher->dispatch(new CreateBookmarkEvent(...$eventData));
$this->eventDispatcher->dispatch(new CreateBookmarkEvent(...$eventData), CreateBookmarkEventInterface::class);
}

public function deleteBookmark(Location $location): void
{
$eventData = [$location];

$beforeEvent = new BeforeDeleteBookmarkEvent(...$eventData);
if ($this->eventDispatcher->dispatch($beforeEvent)->isPropagationStopped()) {

$this->eventDispatcher->dispatch($beforeEvent, BeforeDeleteBookmarkEventInterface::class);
if ($beforeEvent->isPropagationStopped()) {
return;
}

$this->innerService->deleteBookmark($location);

$this->eventDispatcher->dispatch(new DeleteBookmarkEvent(...$eventData));
$this->eventDispatcher->dispatch(new DeleteBookmarkEvent(...$eventData), DeleteBookmarkEventInterface::class);
}
}
143 changes: 117 additions & 26 deletions eZ/Publish/Core/Event/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@
namespace eZ\Publish\Core\Event;

use eZ\Publish\API\Repository\ContentService as ContentServiceInterface;
use eZ\Publish\API\Repository\Events\Content\AddRelationEvent as AddRelationEventInterface;
use eZ\Publish\API\Repository\Events\Content\BeforeAddRelationEvent as BeforeAddRelationEventInterface;
use eZ\Publish\API\Repository\Events\Content\BeforeCopyContentEvent as BeforeCopyContentEventInterface;
use eZ\Publish\API\Repository\Events\Content\BeforeCreateContentDraftEvent as BeforeCreateContentDraftEventInterface;
use eZ\Publish\API\Repository\Events\Content\BeforeCreateContentEvent as BeforeCreateContentEventInterface;
use eZ\Publish\API\Repository\Events\Content\BeforeDeleteContentEvent as BeforeDeleteContentEventInterface;
use eZ\Publish\API\Repository\Events\Content\BeforeDeleteRelationEvent as BeforeDeleteRelationEventInterface;
use eZ\Publish\API\Repository\Events\Content\BeforeDeleteTranslationEvent as BeforeDeleteTranslationEventInterface;
use eZ\Publish\API\Repository\Events\Content\BeforeDeleteVersionEvent as BeforeDeleteVersionEventInterface;
use eZ\Publish\API\Repository\Events\Content\BeforeHideContentEvent as BeforeHideContentEventInterface;
use eZ\Publish\API\Repository\Events\Content\BeforePublishVersionEvent as BeforePublishVersionEventInterface;
use eZ\Publish\API\Repository\Events\Content\BeforeRevealContentEvent as BeforeRevealContentEventInterface;
use eZ\Publish\API\Repository\Events\Content\BeforeUpdateContentEvent as BeforeUpdateContentEventInterface;
use eZ\Publish\API\Repository\Events\Content\BeforeUpdateContentMetadataEvent as BeforeUpdateContentMetadataEventInterface;
use eZ\Publish\API\Repository\Events\Content\CopyContentEvent as CopyContentEventInterface;
use eZ\Publish\API\Repository\Events\Content\CreateContentDraftEvent as CreateContentDraftEventInterface;
use eZ\Publish\API\Repository\Events\Content\CreateContentEvent as CreateContentEventInterface;
use eZ\Publish\API\Repository\Events\Content\DeleteContentEvent as DeleteContentEventInterface;
use eZ\Publish\API\Repository\Events\Content\DeleteRelationEvent as DeleteRelationEventInterface;
use eZ\Publish\API\Repository\Events\Content\DeleteTranslationEvent as DeleteTranslationEventInterface;
use eZ\Publish\API\Repository\Events\Content\DeleteVersionEvent as DeleteVersionEventInterface;
use eZ\Publish\API\Repository\Events\Content\HideContentEvent as HideContentEventInterface;
use eZ\Publish\API\Repository\Events\Content\PublishVersionEvent as PublishVersionEventInterface;
use eZ\Publish\API\Repository\Events\Content\RevealContentEvent as RevealContentEventInterface;
use eZ\Publish\API\Repository\Events\Content\UpdateContentEvent as UpdateContentEventInterface;
use eZ\Publish\API\Repository\Events\Content\UpdateContentMetadataEvent as UpdateContentMetadataEventInterface;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This long import list makes me feel that maybe use eZ\Publish\API\Repository\Events\Content; and e.g.

$this->eventDispatcher->dispatch(
    new UpdateContentMetadataEvent($content, ...$eventData),
    Content\UpdateContentMetadataEvent::class
);

would be better.

use eZ\Publish\API\Repository\Values\Content\Content;
use eZ\Publish\API\Repository\Values\Content\ContentCreateStruct;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
Expand Down Expand Up @@ -72,15 +98,20 @@ public function createContent(
];

$beforeEvent = new BeforeCreateContentEvent(...$eventData);
if ($this->eventDispatcher->dispatch($beforeEvent)->isPropagationStopped()) {

$this->eventDispatcher->dispatch($beforeEvent, BeforeCreateContentEventInterface::class);
if ($beforeEvent->isPropagationStopped()) {
return $beforeEvent->getContent();
}

$content = $beforeEvent->hasContent()
? $beforeEvent->getContent()
: $this->innerService->createContent($contentCreateStruct, $locationCreateStructs);

$this->eventDispatcher->dispatch(new CreateContentEvent($content, ...$eventData));
$this->eventDispatcher->dispatch(
new CreateContentEvent($content, ...$eventData),
CreateContentEventInterface::class
);

return $content;
}
Expand All @@ -95,15 +126,20 @@ public function updateContentMetadata(
];

$beforeEvent = new BeforeUpdateContentMetadataEvent(...$eventData);
if ($this->eventDispatcher->dispatch($beforeEvent)->isPropagationStopped()) {

$this->eventDispatcher->dispatch($beforeEvent, BeforeUpdateContentMetadataEventInterface::class);
if ($beforeEvent->isPropagationStopped()) {
return $beforeEvent->getContent();
}

$content = $beforeEvent->hasContent()
? $beforeEvent->getContent()
: $this->innerService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct);

$this->eventDispatcher->dispatch(new UpdateContentMetadataEvent($content, ...$eventData));
$this->eventDispatcher->dispatch(
new UpdateContentMetadataEvent($content, ...$eventData),
UpdateContentMetadataEventInterface::class
);

return $content;
}
Expand All @@ -113,15 +149,20 @@ public function deleteContent(ContentInfo $contentInfo): array
$eventData = [$contentInfo];

$beforeEvent = new BeforeDeleteContentEvent(...$eventData);
if ($this->eventDispatcher->dispatch($beforeEvent)->isPropagationStopped()) {

$this->eventDispatcher->dispatch($beforeEvent, BeforeDeleteContentEventInterface::class);
if ($beforeEvent->isPropagationStopped()) {
return $beforeEvent->getLocations();
}

$locations = $beforeEvent->hasLocations()
? $beforeEvent->getLocations()
: $this->innerService->deleteContent($contentInfo);

$this->eventDispatcher->dispatch(new DeleteContentEvent($locations, ...$eventData));
$this->eventDispatcher->dispatch(
new DeleteContentEvent($locations, ...$eventData),
DeleteContentEventInterface::class
);

return $locations;
}
Expand All @@ -138,15 +179,20 @@ public function createContentDraft(
];

$beforeEvent = new BeforeCreateContentDraftEvent(...$eventData);
if ($this->eventDispatcher->dispatch($beforeEvent)->isPropagationStopped()) {

$this->eventDispatcher->dispatch($beforeEvent, BeforeCreateContentDraftEventInterface::class);
if ($beforeEvent->isPropagationStopped()) {
return $beforeEvent->getContentDraft();
}

$contentDraft = $beforeEvent->hasContentDraft()
? $beforeEvent->getContentDraft()
: $this->innerService->createContentDraft($contentInfo, $versionInfo, $creator);

$this->eventDispatcher->dispatch(new CreateContentDraftEvent($contentDraft, ...$eventData));
$this->eventDispatcher->dispatch(
new CreateContentDraftEvent($contentDraft, ...$eventData),
CreateContentDraftEventInterface::class
);

return $contentDraft;
}
Expand All @@ -161,15 +207,20 @@ public function updateContent(
];

$beforeEvent = new BeforeUpdateContentEvent(...$eventData);
if ($this->eventDispatcher->dispatch($beforeEvent)->isPropagationStopped()) {

$this->eventDispatcher->dispatch($beforeEvent, BeforeUpdateContentEventInterface::class);
if ($beforeEvent->isPropagationStopped()) {
return $beforeEvent->getContent();
}

$content = $beforeEvent->hasContent()
? $beforeEvent->getContent()
: $this->innerService->updateContent($versionInfo, $contentUpdateStruct);

$this->eventDispatcher->dispatch(new UpdateContentEvent($content, ...$eventData));
$this->eventDispatcher->dispatch(
new UpdateContentEvent($content, ...$eventData),
UpdateContentEventInterface::class
);

return $content;
}
Expand All @@ -182,15 +233,20 @@ public function publishVersion(VersionInfo $versionInfo, array $translations = L
];

$beforeEvent = new BeforePublishVersionEvent(...$eventData);
if ($this->eventDispatcher->dispatch($beforeEvent)->isPropagationStopped()) {

$this->eventDispatcher->dispatch($beforeEvent, BeforePublishVersionEventInterface::class);
if ($beforeEvent->isPropagationStopped()) {
return $beforeEvent->getContent();
}

$content = $beforeEvent->hasContent()
? $beforeEvent->getContent()
: $this->innerService->publishVersion($versionInfo, $translations);

$this->eventDispatcher->dispatch(new PublishVersionEvent($content, ...$eventData));
$this->eventDispatcher->dispatch(
new PublishVersionEvent($content, ...$eventData),
PublishVersionEventInterface::class
);

return $content;
}
Expand All @@ -200,13 +256,18 @@ public function deleteVersion(VersionInfo $versionInfo): void
$eventData = [$versionInfo];

$beforeEvent = new BeforeDeleteVersionEvent(...$eventData);
if ($this->eventDispatcher->dispatch($beforeEvent)->isPropagationStopped()) {

$this->eventDispatcher->dispatch($beforeEvent, BeforeDeleteVersionEventInterface::class);
if ($beforeEvent->isPropagationStopped()) {
return;
}

$this->innerService->deleteVersion($versionInfo);

$this->eventDispatcher->dispatch(new DeleteVersionEvent(...$eventData));
$this->eventDispatcher->dispatch(
new DeleteVersionEvent(...$eventData),
DeleteVersionEventInterface::class
);
}

public function copyContent(
Expand All @@ -221,15 +282,20 @@ public function copyContent(
];

$beforeEvent = new BeforeCopyContentEvent(...$eventData);
if ($this->eventDispatcher->dispatch($beforeEvent)->isPropagationStopped()) {

$this->eventDispatcher->dispatch($beforeEvent, BeforeCopyContentEventInterface::class);
if ($beforeEvent->isPropagationStopped()) {
return $beforeEvent->getContent();
}

$content = $beforeEvent->hasContent()
? $beforeEvent->getContent()
: $this->innerService->copyContent($contentInfo, $destinationLocationCreateStruct, $versionInfo);

$this->eventDispatcher->dispatch(new CopyContentEvent($content, ...$eventData));
$this->eventDispatcher->dispatch(
new CopyContentEvent($content, ...$eventData),
CopyContentEventInterface::class
);

return $content;
}
Expand All @@ -244,15 +310,20 @@ public function addRelation(
];

$beforeEvent = new BeforeAddRelationEvent(...$eventData);
if ($this->eventDispatcher->dispatch($beforeEvent)->isPropagationStopped()) {

$this->eventDispatcher->dispatch($beforeEvent, BeforeAddRelationEventInterface::class);
if ($beforeEvent->isPropagationStopped()) {
return $beforeEvent->getRelation();
}

$relation = $beforeEvent->hasRelation()
? $beforeEvent->getRelation()
: $this->innerService->addRelation($sourceVersion, $destinationContent);

$this->eventDispatcher->dispatch(new AddRelationEvent($relation, ...$eventData));
$this->eventDispatcher->dispatch(
new AddRelationEvent($relation, ...$eventData),
AddRelationEventInterface::class
);

return $relation;
}
Expand All @@ -267,13 +338,18 @@ public function deleteRelation(
];

$beforeEvent = new BeforeDeleteRelationEvent(...$eventData);
if ($this->eventDispatcher->dispatch($beforeEvent)->isPropagationStopped()) {

$this->eventDispatcher->dispatch($beforeEvent, BeforeDeleteRelationEventInterface::class);
if ($beforeEvent->isPropagationStopped()) {
return;
}

$this->innerService->deleteRelation($sourceVersion, $destinationContent);

$this->eventDispatcher->dispatch(new DeleteRelationEvent(...$eventData));
$this->eventDispatcher->dispatch(
new DeleteRelationEvent(...$eventData),
DeleteRelationEventInterface::class
);
}

public function deleteTranslation(
Expand All @@ -286,40 +362,55 @@ public function deleteTranslation(
];

$beforeEvent = new BeforeDeleteTranslationEvent(...$eventData);
if ($this->eventDispatcher->dispatch($beforeEvent)->isPropagationStopped()) {

$this->eventDispatcher->dispatch($beforeEvent, BeforeDeleteTranslationEventInterface::class);
if ($beforeEvent->isPropagationStopped()) {
return;
}

$this->innerService->deleteTranslation($contentInfo, $languageCode);

$this->eventDispatcher->dispatch(new DeleteTranslationEvent(...$eventData));
$this->eventDispatcher->dispatch(
new DeleteTranslationEvent(...$eventData),
DeleteTranslationEventInterface::class
);
}

public function hideContent(ContentInfo $contentInfo): void
{
$eventData = [$contentInfo];

$beforeEvent = new BeforeHideContentEvent(...$eventData);
if ($this->eventDispatcher->dispatch($beforeEvent)->isPropagationStopped()) {

$this->eventDispatcher->dispatch($beforeEvent, BeforeHideContentEventInterface::class);
if ($beforeEvent->isPropagationStopped()) {
return;
}

$this->innerService->hideContent($contentInfo);

$this->eventDispatcher->dispatch(new HideContentEvent(...$eventData));
$this->eventDispatcher->dispatch(
new HideContentEvent(...$eventData),
HideContentEventInterface::class
);
}

public function revealContent(ContentInfo $contentInfo): void
{
$eventData = [$contentInfo];

$beforeEvent = new BeforeRevealContentEvent(...$eventData);
if ($this->eventDispatcher->dispatch($beforeEvent)->isPropagationStopped()) {

$this->eventDispatcher->dispatch($beforeEvent, BeforeRevealContentEventInterface::class);
if ($beforeEvent->isPropagationStopped()) {
return;
}

$this->innerService->revealContent($contentInfo);

$this->eventDispatcher->dispatch(new RevealContentEvent(...$eventData));
$this->eventDispatcher->dispatch(
new RevealContentEvent(...$eventData),
RevealContentEventInterface::class
);
}
}
Loading