Last active
August 24, 2019 11:20
-
-
Save arfaram/114f146d26328cb3c104d533db6abd8b to your computer and use it in GitHub Desktop.
cw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
system: | |
admin_group: #or default for all backend | |
#notification bars timeout | |
notifications: | |
warning: | |
timeout: 5000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Bundle\Slot; | |
use eZ\Publish\Core\SignalSlot\Slot as BaseSlot; | |
use eZ\Publish\Core\SignalSlot\Signal; | |
use eZ\Publish\API\Repository\ContentService; | |
use eZ\Publish\API\Repository\LocationService; | |
class FixArticlePublishSlot extends BaseSlot | |
{ | |
/** @var ContentService */ | |
private $contentService; | |
/** | |
* @var LocationService | |
*/ | |
private $locationService; | |
/** | |
* @var array | |
*/ | |
private $domain_mapping; | |
public function __construct( | |
ContentService $contentService, | |
LocationService $locationService, | |
$domain_mapping) | |
{ | |
$this->contentService = $contentService; | |
$this->locationService = $locationService; | |
$this->domain_mapping = $domain_mapping; | |
} | |
/** | |
* @param \eZ\Publish\Core\SignalSlot\Signal $signal | |
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException | |
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException | |
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException | |
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException | |
*/ | |
public function receive(Signal $signal) | |
{ | |
//# Load published content | |
$content = $this->contentService->loadContent($signal->contentId, null, $signal->versionNo); | |
//# if contenttype is article create new locations in Newsrooms from each siteaccess (see parameters for mapping) | |
if ($content->getContentType()->id == 2) { | |
$contentInfo = $this->contentService->loadContentInfo($signal->contentId); | |
$this->handleLocations($contentInfo, $content->getField('domain')->value->selection); | |
//# checks if newsdate field is set to set the publishedDate to a past date | |
$newsdate = $content->getField('newsdate')->value; | |
$creationDate = $contentInfo->publishedDate; | |
$metadataUpdate = $this->contentService->newContentMetadataUpdateStruct(); | |
if ($newsdate->date) { | |
// if publishedDate differs from newsdate, update the publishDate | |
if ($newsdate->date != $creationDate) { | |
$metadataUpdate->publishedDate = $newsdate->date; | |
$this->contentService->updateContentMetadata($contentInfo, $metadataUpdate); | |
} | |
} | |
// set metadata name with date in format like "2019-04-15 new article" | |
$metadataUpdate->name = $newsdate->date ? $newsdate->date->format('Ymd') : $creationDate->format('Ymd') . ' ' . $content->getField('title')->value; | |
$this->contentService->updateContentMetadata($contentInfo, $metadataUpdate); | |
} | |
} | |
/** | |
* @param $contentInfo | |
* @param $domains | |
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException | |
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException | |
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException | |
*/ | |
public function handleLocations($contentInfo, $domains) | |
{ | |
$sublocations = $this->locationService->loadLocations($contentInfo); | |
//# domains from selection box in news (if news should be shown in de, ch or/and lu) | |
$mapped_domains = []; | |
foreach ($domains as $domain) { | |
$createLoc = true; | |
$newLocId = $this->domain_mapping[$domain]; | |
if (\count($sublocations) > 1) { | |
//# check if location already exists, then do not create one | |
foreach ($sublocations as $sublocation) { | |
if ($sublocation->parentLocationId == $newLocId) { | |
$createLoc = false; | |
} | |
} | |
} | |
if ($createLoc) { | |
$loccreatestruct = $this->locationService->newLocationCreateStruct($newLocId); | |
$this->locationService->createLocation($contentInfo, $loccreatestruct); | |
} | |
$mapped_domains[] = $newLocId; | |
} | |
//# delete the location, which is not linked anymore | |
foreach (\array_slice($sublocations, 1) as $sublocation) { | |
if (!\in_array($sublocation->parentLocationId, $mapped_domains)) { | |
$this->locationService->deleteLocation($sublocation); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- php_cs_fixer : https://github.com/FriendsOfPHP/PHP-CS-Fixer#globally-manual vor feature release | |
- Conetnttype name = same as identifier (News = news not article). Identifier is only for internal use |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment