From 7c8dd0df3bbc140c3f490c92bb71e9b99804855a Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 10 Aug 2021 09:21:24 +0200 Subject: [PATCH] Cleanup refactoring after big refactoring --- Classes/Domain/Import/Entity/Base.php | 118 +----------------- Classes/Domain/Import/Entity/MediaObject.php | 56 +-------- Classes/Domain/Import/Entity/Minimum.php | 116 +++++++++++++++++ Classes/Domain/Import/Entity/Place.php | 40 +----- .../Domain/Import/Entity/Properties/Offer.php | 40 +----- .../Entity/Properties/PriceSpecification.php | 43 +------ .../Import/Entity/Shared/ContainedInPlace.php | 66 ++++++++++ .../Domain/Import/Entity/Shared/ManagedBy.php | 49 ++++++++ .../Import/Entity/TouristInformation.php | 8 +- .../Import/Entity/TouristMarketingCompany.php | 4 +- Classes/Domain/Import/Entity/Town.php | 6 +- .../Typo3Converter/LanguageHandling.php | 12 +- .../Repository/Backend/TownRepository.php | 7 +- 13 files changed, 261 insertions(+), 304 deletions(-) create mode 100644 Classes/Domain/Import/Entity/Minimum.php create mode 100644 Classes/Domain/Import/Entity/Shared/ContainedInPlace.php create mode 100644 Classes/Domain/Import/Entity/Shared/ManagedBy.php diff --git a/Classes/Domain/Import/Entity/Base.php b/Classes/Domain/Import/Entity/Base.php index 5c8ef7e..6bd88a4 100644 --- a/Classes/Domain/Import/Entity/Base.php +++ b/Classes/Domain/Import/Entity/Base.php @@ -24,41 +24,11 @@ declare(strict_types=1); namespace WerkraumMedia\ThueCat\Domain\Import\Entity; use WerkraumMedia\ThueCat\Domain\Import\Entity\Properties\ForeignReference; +use WerkraumMedia\ThueCat\Domain\Import\Entity\Shared\ManagedBy; - -class Base +class Base extends Minimum { - /** - * URL to the original source at ThüCAT. - * Not unique within our system. We have one entity per language, - * while ThüCAT has a single entity containing all languages. - * - * @var string - */ - protected $id = ''; - - /** - * Short name of the thing. - * Can be translated. - * - * @var string - */ - protected $name = ''; - - /** - * Long text describing the thing. - * Can be translated. - * - * @var string - */ - protected $description = ''; - - /** - * URL to official version of this thing outside of ThüCAT. - * - * @var string - */ - protected $url = ''; + use ManagedBy; /** * @var ForeignReference @@ -72,38 +42,6 @@ class Base */ protected $images = []; - /** - * The Thing responsible for the data within this Thing. - * - * @var ForeignReference - */ - protected $managedBy; - - public function getId(): string - { - return $this->id; - } - - public function hasName(): bool - { - return trim($this->name) !== ''; - } - - public function getName(): string - { - return $this->name; - } - - public function getDescription(): string - { - return $this->description; - } - - public function getUrl(): string - { - return $this->url; - } - public function getPhoto(): ?ForeignReference { return $this->photo; @@ -117,43 +55,6 @@ class Base return $this->images; } - public function getManagedBy(): ?ForeignReference - { - return $this->managedBy; - } - - /** - * @internal for mapping via Symfony component. - */ - public function setId(string $url): void - { - $this->id = $url; - } - - /** - * @internal for mapping via Symfony component. - */ - public function setName(string $name): void - { - $this->name = $name; - } - - /** - * @internal for mapping via Symfony component. - */ - public function setDescription(string $description): void - { - $this->description = $description; - } - - /** - * @internal for mapping via Symfony component. - */ - public function setUrl(string $url): void - { - $this->url = $url; - } - /** * @internal for mapping via Symfony component. */ @@ -185,17 +86,4 @@ class Base public function removeImage(ForeignReference $image): void { } - - /** - * @internal for mapping via Symfony component. - */ - public function setContentResponsible(ForeignReference $contentResponsible): void - { - $this->managedBy = $contentResponsible; - } - - // TODO: Address - // TODO: Offers - - // TODO: containedInPlace -> resolve to town, etc. } diff --git a/Classes/Domain/Import/Entity/MediaObject.php b/Classes/Domain/Import/Entity/MediaObject.php index 5be14e8..aa957a0 100644 --- a/Classes/Domain/Import/Entity/MediaObject.php +++ b/Classes/Domain/Import/Entity/MediaObject.php @@ -23,23 +23,8 @@ declare(strict_types=1); namespace WerkraumMedia\ThueCat\Domain\Import\Entity; -class MediaObject implements MapsToType +class MediaObject extends Minimum implements MapsToType { - /** - * @var string - */ - protected $name = ''; - - /** - * @var string - */ - protected $description = ''; - - /** - * @var string - */ - protected $url = ''; - /** * @var int */ @@ -60,21 +45,6 @@ class MediaObject implements MapsToType */ protected $type = ''; - public function getName(): string - { - return $this->name; - } - - public function getDescription(): string - { - return $this->description; - } - - public function getUrl(): string - { - return $this->url; - } - public function getCopyrightYear(): int { return $this->copyrightYear; @@ -95,30 +65,6 @@ class MediaObject implements MapsToType return $this->type; } - /** - * @internal for mapping via Symfony component. - */ - public function setName(string $name): void - { - $this->name = $name; - } - - /** - * @internal for mapping via Symfony component. - */ - public function setDescription(string $description): void - { - $this->description = $description; - } - - /** - * @internal for mapping via Symfony component. - */ - public function setUrl(string $url): void - { - $this->url = $url; - } - /** * @internal for mapping via Symfony component. */ diff --git a/Classes/Domain/Import/Entity/Minimum.php b/Classes/Domain/Import/Entity/Minimum.php new file mode 100644 index 0000000..0976a53 --- /dev/null +++ b/Classes/Domain/Import/Entity/Minimum.php @@ -0,0 +1,116 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +namespace WerkraumMedia\ThueCat\Domain\Import\Entity; + +class Minimum +{ + /** + * URL to the original source at ThüCAT. + * Not unique within our system. We have one entity per language, + * while ThüCAT has a single entity containing all languages. + * + * @var string + */ + protected $id = ''; + + /** + * Short name of the thing. + * Can be translated. + * + * @var string + */ + protected $name = ''; + + /** + * Long text describing the thing. + * Can be translated. + * + * @var string + */ + protected $description = ''; + + /** + * URL to official version of this thing outside of ThüCAT. + * + * @var string + */ + protected $url = ''; + + public function getId(): string + { + return $this->id; + } + + public function hasName(): bool + { + return trim($this->name) !== ''; + } + + public function getName(): string + { + return $this->name; + } + + public function getDescription(): string + { + return $this->description; + } + + public function getUrl(): string + { + return $this->url; + } + + /** + * @internal for mapping via Symfony component. + */ + public function setId(string $url): void + { + $this->id = $url; + } + + /** + * @internal for mapping via Symfony component. + */ + public function setName(string $name): void + { + $this->name = $name; + } + + /** + * @internal for mapping via Symfony component. + */ + public function setDescription(string $description): void + { + $this->description = $description; + } + + /** + * @internal for mapping via Symfony component. + */ + public function setUrl(string $url): void + { + $this->url = $url; + } +} diff --git a/Classes/Domain/Import/Entity/Place.php b/Classes/Domain/Import/Entity/Place.php index 53bf3c5..e14fbff 100644 --- a/Classes/Domain/Import/Entity/Place.php +++ b/Classes/Domain/Import/Entity/Place.php @@ -24,14 +24,15 @@ declare(strict_types=1); namespace WerkraumMedia\ThueCat\Domain\Import\Entity; use WerkraumMedia\ThueCat\Domain\Import\Entity\Properties\Address; -use WerkraumMedia\ThueCat\Domain\Import\Entity\Properties\ForeignReference; use WerkraumMedia\ThueCat\Domain\Import\Entity\Properties\Geo; use WerkraumMedia\ThueCat\Domain\Import\Entity\Properties\OpeningHour; +use WerkraumMedia\ThueCat\Domain\Import\Entity\Shared\ContainedInPlace; use WerkraumMedia\ThueCat\Domain\Import\Entity\Shared\Organization; class Place extends Base { use Organization; + use ContainedInPlace; /** * @var Address @@ -48,11 +49,6 @@ class Place extends Base */ protected $openingHours = []; - /** - * @var ForeignReference[] - */ - protected $containedInPlace = []; - public function getAddress(): ?Address { return $this->address; @@ -63,14 +59,6 @@ class Place extends Base return $this->geo; } - /** - * @return ForeignReference[] - */ - public function getContainedInPlaces(): array - { - return $this->containedInPlace; - } - /** * @internal for mapping via Symfony component. */ @@ -110,28 +98,4 @@ class Place extends Base public function removeOpeningHoursSpecification(OpeningHour $openingHour): void { } - - /** - * @return ForeignReference[] - * @internal for mapping via Symfony component. - */ - public function getContainedInPlace(): array - { - return $this->containedInPlace; - } - - /** - * @internal for mapping via Symfony component. - */ - public function addContainedInPlace(ForeignReference $place): void - { - $this->containedInPlace[] = $place; - } - - /** - * @internal for mapping via Symfony component. - */ - public function removeContainedInPlace(ForeignReference $place): void - { - } } diff --git a/Classes/Domain/Import/Entity/Properties/Offer.php b/Classes/Domain/Import/Entity/Properties/Offer.php index a5a287e..5917c08 100644 --- a/Classes/Domain/Import/Entity/Properties/Offer.php +++ b/Classes/Domain/Import/Entity/Properties/Offer.php @@ -23,33 +23,15 @@ declare(strict_types=1); namespace WerkraumMedia\ThueCat\Domain\Import\Entity\Properties; -class Offer +use WerkraumMedia\ThueCat\Domain\Import\Entity\Minimum; + +class Offer extends Minimum { - /** - * @var string - */ - protected $name = ''; - - /** - * @var string - */ - protected $description = ''; - /** * @var PriceSpecification[] */ protected $prices = []; - public function getName(): string - { - return $this->name; - } - - public function getDescription(): string - { - return $this->description; - } - /** * @return PriceSpecification[] */ @@ -58,22 +40,6 @@ class Offer return $this->prices; } - /** - * @internal for mapping via Symfony component. - */ - public function setName(string $name): void - { - $this->name = $name; - } - - /** - * @internal for mapping via Symfony component. - */ - public function setDescription(string $description): void - { - $this->description = $description; - } - /** * @return PriceSpecification[] * @internal for mapping via Symfony component. diff --git a/Classes/Domain/Import/Entity/Properties/PriceSpecification.php b/Classes/Domain/Import/Entity/Properties/PriceSpecification.php index 46c18e9..78e274c 100644 --- a/Classes/Domain/Import/Entity/Properties/PriceSpecification.php +++ b/Classes/Domain/Import/Entity/Properties/PriceSpecification.php @@ -23,21 +23,10 @@ declare(strict_types=1); namespace WerkraumMedia\ThueCat\Domain\Import\Entity\Properties; -class PriceSpecification +use WerkraumMedia\ThueCat\Domain\Import\Entity\Minimum; + +class PriceSpecification extends Minimum { - // TODO: Move name to trait - // TODO: Move description to trait - - /** - * @var string - */ - protected $name = ''; - - /** - * @var string - */ - protected $description = ''; - /** * @var float */ @@ -59,16 +48,6 @@ class PriceSpecification */ protected $calculationRule = ''; - public function getName(): string - { - return $this->name; - } - - public function getDescription(): string - { - return $this->description; - } - public function getPrice(): float { return $this->price; @@ -84,22 +63,6 @@ class PriceSpecification return $this->calculationRule; } - /** - * @internal for mapping via Symfony component. - */ - public function setName(string $name): void - { - $this->name = $name; - } - - /** - * @internal for mapping via Symfony component. - */ - public function setDescription(string $description): void - { - $this->description = $description; - } - /** * @internal for mapping via Symfony component. */ diff --git a/Classes/Domain/Import/Entity/Shared/ContainedInPlace.php b/Classes/Domain/Import/Entity/Shared/ContainedInPlace.php new file mode 100644 index 0000000..95929d1 --- /dev/null +++ b/Classes/Domain/Import/Entity/Shared/ContainedInPlace.php @@ -0,0 +1,66 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +namespace WerkraumMedia\ThueCat\Domain\Import\Entity\Shared; + +use WerkraumMedia\ThueCat\Domain\Import\Entity\Properties\ForeignReference; + +trait ContainedInPlace +{ + /** + * @var ForeignReference[] + */ + protected $containedInPlace = []; + + /** + * @return ForeignReference[] + */ + public function getContainedInPlaces(): array + { + return $this->containedInPlace; + } + + /** + * @return ForeignReference[] + * @internal for mapping via Symfony component. + */ + public function getContainedInPlace(): array + { + return $this->containedInPlace; + } + + /** + * @internal for mapping via Symfony component. + */ + public function addContainedInPlace(ForeignReference $place): void + { + $this->containedInPlace[] = $place; + } + + /** + * @internal for mapping via Symfony component. + */ + public function removeContainedInPlace(ForeignReference $place): void + { + } +} diff --git a/Classes/Domain/Import/Entity/Shared/ManagedBy.php b/Classes/Domain/Import/Entity/Shared/ManagedBy.php new file mode 100644 index 0000000..e12de9a --- /dev/null +++ b/Classes/Domain/Import/Entity/Shared/ManagedBy.php @@ -0,0 +1,49 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +namespace WerkraumMedia\ThueCat\Domain\Import\Entity\Shared; + +use WerkraumMedia\ThueCat\Domain\Import\Entity\Properties\ForeignReference; + +trait ManagedBy +{ + /** + * The Thing responsible for the data within this Thing. + * + * @var ForeignReference + */ + protected $managedBy; + + public function getManagedBy(): ?ForeignReference + { + return $this->managedBy; + } + + /** + * @internal for mapping via Symfony component. + */ + public function setContentResponsible(ForeignReference $contentResponsible): void + { + $this->managedBy = $contentResponsible; + } +} diff --git a/Classes/Domain/Import/Entity/TouristInformation.php b/Classes/Domain/Import/Entity/TouristInformation.php index 3240947..e0dd021 100644 --- a/Classes/Domain/Import/Entity/TouristInformation.php +++ b/Classes/Domain/Import/Entity/TouristInformation.php @@ -23,9 +23,13 @@ declare(strict_types=1); namespace WerkraumMedia\ThueCat\Domain\Import\Entity; -class TouristInformation extends Place implements MapsToType +use WerkraumMedia\ThueCat\Domain\Import\Entity\Shared\ContainedInPlace; +use WerkraumMedia\ThueCat\Domain\Import\Entity\Shared\ManagedBy; + +class TouristInformation extends Minimum implements MapsToType { - // TODO: Only has title and description which should be moved to trait anyway + use ManagedBy; + use ContainedInPlace; public static function getSupportedTypes(): array { diff --git a/Classes/Domain/Import/Entity/TouristMarketingCompany.php b/Classes/Domain/Import/Entity/TouristMarketingCompany.php index c0da35d..3e65123 100644 --- a/Classes/Domain/Import/Entity/TouristMarketingCompany.php +++ b/Classes/Domain/Import/Entity/TouristMarketingCompany.php @@ -23,10 +23,8 @@ declare(strict_types=1); namespace WerkraumMedia\ThueCat\Domain\Import\Entity; -class TouristMarketingCompany extends Base implements MapsToType +class TouristMarketingCompany extends Minimum implements MapsToType { - // TODO: Only has title and description which should be moved to trait anyway - public static function getSupportedTypes(): array { return [ diff --git a/Classes/Domain/Import/Entity/Town.php b/Classes/Domain/Import/Entity/Town.php index 9dfac83..7fe335f 100644 --- a/Classes/Domain/Import/Entity/Town.php +++ b/Classes/Domain/Import/Entity/Town.php @@ -23,9 +23,11 @@ declare(strict_types=1); namespace WerkraumMedia\ThueCat\Domain\Import\Entity; -class Town extends Base implements MapsToType +use WerkraumMedia\ThueCat\Domain\Import\Entity\Shared\ManagedBy; + +class Town extends Minimum implements MapsToType { - // TODO: Only has title and description which should be moved to trait anyway + use ManagedBy; public static function getSupportedTypes(): array { diff --git a/Classes/Domain/Import/Typo3Converter/LanguageHandling.php b/Classes/Domain/Import/Typo3Converter/LanguageHandling.php index fdcf29e..f7950e0 100644 --- a/Classes/Domain/Import/Typo3Converter/LanguageHandling.php +++ b/Classes/Domain/Import/Typo3Converter/LanguageHandling.php @@ -48,8 +48,7 @@ class LanguageHandling implements Languages public function getLanguageUidForString(int $pageUid, string $isoCode): int { - $languages = $this->siteFinder->getSiteByPageId($pageUid)->getLanguages(); - foreach ($languages as $language) { + foreach ($this->getLanguages($pageUid) as $language) { if ($language->getTwoLetterIsoCode() === $isoCode) { return $language->getLanguageId(); } @@ -65,18 +64,11 @@ class LanguageHandling implements Languages ); } - // TODO: Check usages and remove below methods - /** * @return SiteLanguage[] */ - public function getLanguages(int $pageUid): array + private function getLanguages(int $pageUid): array { return $this->siteFinder->getSiteByPageId($pageUid)->getLanguages(); } - - public function getDefaultLanguage(int $pageUid): SiteLanguage - { - return $this->siteFinder->getSiteByPageId($pageUid)->getDefaultLanguage(); - } } diff --git a/Classes/Domain/Repository/Backend/TownRepository.php b/Classes/Domain/Repository/Backend/TownRepository.php index 9cfd278..799ff12 100644 --- a/Classes/Domain/Repository/Backend/TownRepository.php +++ b/Classes/Domain/Repository/Backend/TownRepository.php @@ -26,7 +26,6 @@ namespace WerkraumMedia\ThueCat\Domain\Repository\Backend; use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings; use TYPO3\CMS\Extbase\Persistence\Repository; -use WerkraumMedia\ThueCat\Domain\Import\Entity\Place; use WerkraumMedia\ThueCat\Domain\Import\Entity\Properties\ForeignReference; use WerkraumMedia\ThueCat\Domain\Model\Backend\Town; @@ -43,8 +42,12 @@ class TownRepository extends Repository $this->setDefaultQuerySettings($querySettings); } - public function findOneByEntity(Place $entity): ?Town + public function findOneByEntity(object $entity): ?Town { + if (method_exists($entity, 'getContainedInPlaces') === false) { + return null; + } + $remoteIds = array_map(function (ForeignReference $reference) { return $reference->getId(); }, $entity->getContainedInPlaces());