From 7cd241b7b766dbddf473ef6f502fcc03c5da9fce Mon Sep 17 00:00:00 2001 From: Benjamin Kott Date: Sun, 18 Aug 2019 13:21:14 +0200 Subject: [PATCH] [!!!][TASK] Drop obsolete MetaService The meta service is obsolete since TYPO3 v9 and is replaced through the usage of the MetaTag-API from core. To migrate to the new API you just need to remove all usages of the MetaService. --- Classes/Controller/PostController.php | 11 -- Classes/Service/MetaService.php | 155 ------------------------- Classes/UserFunc/MetaService.php | 39 ------- Tests/Unit/Service/MetaServiceTest.php | 57 --------- 4 files changed, 262 deletions(-) delete mode 100644 Classes/Service/MetaService.php delete mode 100644 Classes/UserFunc/MetaService.php delete mode 100644 Tests/Unit/Service/MetaServiceTest.php diff --git a/Classes/Controller/PostController.php b/Classes/Controller/PostController.php index 0a67b949..e4d8dd9b 100644 --- a/Classes/Controller/PostController.php +++ b/Classes/Controller/PostController.php @@ -19,7 +19,6 @@ use T3G\AgencyPack\Blog\Domain\Repository\PostRepository; use T3G\AgencyPack\Blog\Domain\Repository\TagRepository; use T3G\AgencyPack\Blog\Service\CacheService; -use T3G\AgencyPack\Blog\Service\MetaService; use T3G\AgencyPack\Blog\Service\MetaTagService; use T3G\AgencyPack\Blog\Utility\ArchiveUtility; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; @@ -189,8 +188,6 @@ public function listPostsByDateAction(int $year = null, int $month = null): void $dateTime->format('F'), $year, ], LocalizationUtility::translate('meta.title.listPostsByDate', 'blog')); - MetaService::set(MetaService::META_TITLE, $title); - MetaService::set(MetaService::META_DESCRIPTION, LocalizationUtility::translate('meta.description.listPostsByDate', 'blog')); MetaTagService::set(MetaTagService::META_TITLE, (string) $title); MetaTagService::set(MetaTagService::META_DESCRIPTION, (string) LocalizationUtility::translate('meta.description.listPostsByDate', 'blog')); } @@ -222,9 +219,6 @@ public function listPostsByCategoryAction(Category $category = null): void $this->view->assign('type', 'bycategory'); $this->view->assign('posts', $posts); $this->view->assign('category', $category); - MetaService::set(MetaService::META_TITLE, $category->getTitle()); - MetaService::set(MetaService::META_DESCRIPTION, $category->getDescription()); - MetaService::set(MetaService::META_CATEGORIES, [$category->getTitle()]); MetaTagService::set(MetaTagService::META_TITLE, (string) $category->getTitle()); MetaTagService::set(MetaTagService::META_DESCRIPTION, (string) $category->getDescription()); } else { @@ -246,8 +240,6 @@ public function listPostsByAuthorAction(Author $author = null): void $this->view->assign('type', 'byauthor'); $this->view->assign('posts', $posts); $this->view->assign('author', $author); - MetaService::set(MetaService::META_TITLE, $author->getName()); - MetaService::set(MetaService::META_DESCRIPTION, $author->getBio()); MetaTagService::set(MetaTagService::META_TITLE, (string) $author->getName()); MetaTagService::set(MetaTagService::META_DESCRIPTION, (string) $author->getBio()); } else { @@ -269,9 +261,6 @@ public function listPostsByTagAction(Tag $tag = null): void $this->view->assign('type', 'bytag'); $this->view->assign('posts', $posts); $this->view->assign('tag', $tag); - MetaService::set(MetaService::META_TITLE, $tag->getTitle()); - MetaService::set(MetaService::META_DESCRIPTION, $tag->getDescription()); - MetaService::set(MetaService::META_TAGS, [$tag->getTitle()]); MetaTagService::set(MetaTagService::META_TITLE, (string) $tag->getTitle()); MetaTagService::set(MetaTagService::META_DESCRIPTION, (string) $tag->getDescription()); } else { diff --git a/Classes/Service/MetaService.php b/Classes/Service/MetaService.php deleted file mode 100644 index 89346b58..00000000 --- a/Classes/Service/MetaService.php +++ /dev/null @@ -1,155 +0,0 @@ --Tag or meta title tags - public const META_TITLE = 'title'; - - // -Description tag - public const META_DESCRIPTION = 'description'; - - // Creation date - public const META_PUBLISHED_DATE = 'published_date'; - - // Last modified date (field: tstamp) - public const META_MODIFIED_DATE = 'modified_date'; - - // Overwrite the canonical URL - public const META_URL = 'url'; - - // The tags of the blog post - public const META_TAGS = 'tags'; - - // The categories of the blog post - public const META_CATEGORIES = 'categories'; - - /** - * Registry object provides storage for shared objects. - * - * @var MetaService - */ - private static $instance; - - /** - * Retrieves the default registry instance. - * - * @return MetaService - * - * @throws \RuntimeException - */ - public static function getInstance() : self - { - if (self::$instance === null) { - self::init(); - } - - return self::$instance; - } - - /** - * Set the default registry instance to a specified instance. - * - * @param self $instance - */ - public static function setInstance(self $instance): void - { - if (self::$instance !== null) { - throw new \RuntimeException('Registry is already initialized', 1398536572); - } - self::$instance = $instance; - } - - /** - * Initialize the default registry instance. - * - * @throws \RuntimeException - */ - protected static function init(): void - { - self::setInstance(new self()); - } - - /** - * getter method, basically same as offsetGet(). - * - * This method can be called from an object of type Registry, or it - * can be called statically. In the latter case, it uses the default - * static instance stored in the class. - * - * @param string $index - get the value associated with $index - * - * @return mixed - * - * @throws \RuntimeException if no entry is registerd for $index. - */ - public static function get($index) - { - $instance = self::getInstance(); - if (!$instance->offsetExists($index)) { - throw new \RuntimeException('No entry is registered for key \'' . $index . '\'', 1398536594); - } - - return $instance->offsetGet($index); - } - - /** - * setter method, basically same as offsetSet(). - * - * This method can be called from an object of type Registry, or it - * can be called statically. In the latter case, it uses the default - * static instance stored in the class. - * - * @param string $index The location in the ArrayObject in which to store - * the value. - * @param mixed $value The object to store in the ArrayObject. - * - * @throws \RuntimeException - */ - public static function set($index, $value): void - { - $instance = self::getInstance(); - $instance->offsetSet($index, $value); - } - - /** - * Returns TRUE if the $index is a named value in the registry, - * or FALSE if $index was not found in the registry. - * - * @param string $index - * - * @return bool - */ - public static function isRegistered($index) : bool - { - if (self::$instance === null) { - return false; - } - - return self::$instance->offsetExists($index); - } - - /** - * Method to check if offset exists. - * Workaround for http://bugs.php.net/bug.php?id=40442 (ZF-960). - * - * @param mixed $index - * @return bool - */ - public function offsetExists($index): bool - { - return array_key_exists($index, $this); - } -} diff --git a/Classes/UserFunc/MetaService.php b/Classes/UserFunc/MetaService.php deleted file mode 100644 index 55d3e93a..00000000 --- a/Classes/UserFunc/MetaService.php +++ /dev/null @@ -1,39 +0,0 @@ -getCode() === 1398536594) { - return ''; - } - } - } - - return ''; - } -} diff --git a/Tests/Unit/Service/MetaServiceTest.php b/Tests/Unit/Service/MetaServiceTest.php deleted file mode 100644 index d9769eaf..00000000 --- a/Tests/Unit/Service/MetaServiceTest.php +++ /dev/null @@ -1,57 +0,0 @@ -metaService = MetaService::getInstance(); - } - - /** - * @return array - */ - public function metaDataDataProvider() : array - { - return [ - MetaService::META_TITLE => [MetaService::META_TITLE], - MetaService::META_DESCRIPTION => [MetaService::META_DESCRIPTION], - MetaService::META_PUBLISHED_DATE => [MetaService::META_PUBLISHED_DATE], - MetaService::META_MODIFIED_DATE => [MetaService::META_MODIFIED_DATE], - MetaService::META_URL => [MetaService::META_URL], - MetaService::META_TAGS => [MetaService::META_TAGS], - MetaService::META_CATEGORIES => [MetaService::META_CATEGORIES], - ]; - } - - /** - * @test - * @dataProvider metaDataDataProvider - * - * @param string $key - */ - public function ensureDataCanStoredInMetaService(string $key) - { - $this->initialize(); - - MetaService::set($key, $key); - self::assertSame($key, MetaService::get($key)); - } -}