From 51a2f1fc14f61696b1733669540c54b833931511 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Thu, 11 Jun 2020 10:40:17 -0400 Subject: [PATCH] Add "Deprecated" content providers. - Provides a mechanism for eliminating handlers without breaking legacy configurations. --- .../src/VuFind/Content/Covers/Deprecated.php | 74 +++++++++++++++++++ .../VuFind/Content/Covers/PluginManager.php | 1 + .../VuFind/src/VuFind/Content/Deprecated.php | 59 +++++++++++++++ .../VuFind/Content/Reviews/PluginManager.php | 3 + .../Content/Covers/DeprecatedTest.php | 71 ++++++++++++++++++ 5 files changed, 208 insertions(+) create mode 100644 module/VuFind/src/VuFind/Content/Covers/Deprecated.php create mode 100644 module/VuFind/src/VuFind/Content/Deprecated.php create mode 100644 module/VuFind/tests/unit-tests/src/VuFindTest/Content/Covers/DeprecatedTest.php diff --git a/module/VuFind/src/VuFind/Content/Covers/Deprecated.php b/module/VuFind/src/VuFind/Content/Covers/Deprecated.php new file mode 100644 index 00000000000..daf19819f5b --- /dev/null +++ b/module/VuFind/src/VuFind/Content/Covers/Deprecated.php @@ -0,0 +1,74 @@ +<?php +/** + * Deprecated cover content loader (for backward-compatibility with deprecated + * settings). + * + * PHP version 7 + * + * Copyright (C) Villanova University 2020. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * 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 + * + * @category VuFind + * @package Content + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace VuFind\Content\Covers; + +/** + * Deprecated cover content loader (for backward-compatibility with deprecated + * settings). + * + * @category VuFind + * @package Content + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class Deprecated extends \VuFind\Content\AbstractCover +{ + /** + * Does this plugin support the provided ID array? + * + * @param array $ids IDs that will later be sent to load() -- see below. + * + * @return bool + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function supports($ids) + { + error_log('Deprecated cover provider called; check configuration.'); + return false; + } + + /** + * Get image URL for a particular API key and set of IDs (or false if invalid). + * + * @param string $key API key + * @param string $size Size of image to load (small/medium/large) + * @param array $ids Associative array of identifiers (keys may include 'isbn' + * pointing to an ISBN object and 'issn' pointing to a string) + * + * @return string|bool + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function getUrl($key, $size, $ids) + { + return false; + } +} diff --git a/module/VuFind/src/VuFind/Content/Covers/PluginManager.php b/module/VuFind/src/VuFind/Content/Covers/PluginManager.php index 8c47623fb5c..f260e3a13d4 100644 --- a/module/VuFind/src/VuFind/Content/Covers/PluginManager.php +++ b/module/VuFind/src/VuFind/Content/Covers/PluginManager.php @@ -70,6 +70,7 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager BrowZine::class => BrowZineFactory::class, Buchhandel::class => BuchhandelFactory::class, ContentCafe::class => ContentCafeFactory::class, + Deprecated::class => InvokableFactory::class, Google::class => InvokableFactory::class, LibraryThing::class => InvokableFactory::class, LocalFile::class => InvokableFactory::class, diff --git a/module/VuFind/src/VuFind/Content/Deprecated.php b/module/VuFind/src/VuFind/Content/Deprecated.php new file mode 100644 index 00000000000..966d1ffa5f3 --- /dev/null +++ b/module/VuFind/src/VuFind/Content/Deprecated.php @@ -0,0 +1,59 @@ +<?php +/** + * Deprecated content loader (used for backward compatibility with deprecated + * settings). + * + * PHP version 7 + * + * Copyright (C) Villanova University 2020. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package Content + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:developer_manual Wiki + */ +namespace VuFind\Content; + +/** + * Deprecated content loader (used for backward compatibility with deprecated + * settings). + * + * @category VuFind2 + * @package Content + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:developer_manual Wiki + */ +class Deprecated extends \VuFind\Content\AbstractBase +{ + /** + * Return empty data. + * + * @param string $key API key + * @param \VuFindCode\ISBN $isbnObj ISBN object + * + * @throws \Exception + * @return array Returns array with table of contents data. + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function loadByIsbn($key, \VuFindCode\ISBN $isbnObj) + { + error_log('Deprecated content provider called; check configuration.'); + return []; + } +} diff --git a/module/VuFind/src/VuFind/Content/Reviews/PluginManager.php b/module/VuFind/src/VuFind/Content/Reviews/PluginManager.php index 4b7b678eebd..81e575fd1d3 100644 --- a/module/VuFind/src/VuFind/Content/Reviews/PluginManager.php +++ b/module/VuFind/src/VuFind/Content/Reviews/PluginManager.php @@ -27,6 +27,8 @@ */ namespace VuFind\Content\Reviews; +use VuFind\Content\Deprecated; + /** * Reviews content loader plugin manager * @@ -63,6 +65,7 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager AmazonEditorial::class => \VuFind\Content\AbstractAmazonFactory::class, Booksite::class => BooksiteFactory::class, Demo::class => \Laminas\ServiceManager\Factory\InvokableFactory::class, + Deprecated::class => \Laminas\ServiceManager\Factory\InvokableFactory::class, Guardian::class => \Laminas\ServiceManager\Factory\InvokableFactory::class, Syndetics::class => \VuFind\Content\AbstractSyndeticsFactory::class, SyndeticsPlus::class => \VuFind\Content\AbstractSyndeticsFactory::class, diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Content/Covers/DeprecatedTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Content/Covers/DeprecatedTest.php new file mode 100644 index 00000000000..1066fb25de9 --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Content/Covers/DeprecatedTest.php @@ -0,0 +1,71 @@ +<?php + +/** + * Unit tests for Deprecated cover loader. + * + * PHP version 7 + * + * Copyright (C) Villanova University 2010. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * 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 + * + * @category VuFind + * @package Search + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org + */ +namespace VuFindTest\Content\Covers; + +use VuFindCode\ISBN; + +/** + * Unit tests for Deprecated cover loader. + * + * @category VuFind + * @package Search + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org + */ +class DeprecatedTest extends \PHPUnit\Framework\TestCase +{ + /** + * Test that the handler never actually does anything. + * + * @return void + */ + public function testEverythingDisabled() + { + $sizes = ['small', 'medium', 'large']; + foreach ($sizes as $size) { + $this->assertFalse($this->getUrl($size)); + } + } + + /** + * Simulate retrieval of a cover URL for a particular size. + * + * @param string $size Size to retrieve + * @param string $isbn ISBN to retrieve (empty for none) + * + * @return string + */ + protected function getUrl($size, $isbn = '0739313126') + { + $deprecated = new \VuFind\Content\Covers\Deprecated(); + $params = empty($isbn) ? [] : ['isbn' => new ISBN($isbn)]; + return $deprecated->getUrl('fakekey', $size, $params); + } +} -- GitLab