Skip to content

Commit

Permalink
#977 Rss module PHP 8 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
j3nsch committed Jan 6, 2023
1 parent c55c674 commit 6bf466f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 67 deletions.
9 changes: 3 additions & 6 deletions modules/rss/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of OPUS. The software OPUS has been originally developed
* at the University of Stuttgart with funding from the German Research Net,
Expand All @@ -24,14 +25,10 @@
* along with OPUS; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @category Application
* @package Module_Rss
* @author Sascha Szott <[email protected]>
* @copyright Copyright (c) 2008-2011, OPUS 4 development team
* @copyright Copyright (c) 2008, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

class Rss_Bootstrap extends \Zend_Application_Module_Bootstrap
class Rss_Bootstrap extends Zend_Application_Module_Bootstrap
{

}
48 changes: 24 additions & 24 deletions modules/rss/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@
*/

use Opus\Common\Document;
use Opus\Search\Result\Base;
use Opus\Search\SearchException;

class Rss_IndexController extends Application_Controller_Xml
{
public const NUM_OF_ITEMS_PER_FEED = '25';

const NUM_OF_ITEMS_PER_FEED = '25';
public const RSS_SORT_FIELD = 'server_date_published';

const RSS_SORT_FIELD = 'server_date_published';

const RSS_SORT_ORDER = 'desc';
public const RSS_SORT_ORDER = 'desc';

public function init()
{
Expand All @@ -68,24 +68,24 @@ public function indexAction()
} catch (Application_Search_QueryBuilderException $e) {
$this->getLogger()->err(__METHOD__ . ' : ' . $e->getMessage());
$applicationException = new Application_Exception($e->getMessage());
$code = $e->getCode();
if ($code != 0) {
$code = $e->getCode();
if ($code !== 0) {
$applicationException->setHttpResponseCode($code);
}
throw $applicationException;
}

// overwrite parameters in rss context
// rss feeds have a fixed maximum number of items
$params['rows'] = self::NUM_OF_ITEMS_PER_FEED;
$params['rows'] = self::NUM_OF_ITEMS_PER_FEED;
$params['start'] = 0;
// rss feeds have both a fixed sort field and sort order
$params['sortField'] = self::RSS_SORT_FIELD;
$params['sortOrder'] = self::RSS_SORT_ORDER;

$resultList = [];
try {
$searcher = Application_Search_SearcherFactory::getSearcher();
$searcher = Application_Search_SearcherFactory::getSearcher();
$resultList = $searcher->search($search->createSearchQuery($params));
} catch (SearchException $exception) {
$this->handleSolrError($exception);
Expand Down Expand Up @@ -128,53 +128,53 @@ private function setParameters()

$feedLink = $this->view->serverUrl() . $this->getRequest()->getBaseUrl() . '/index/index/';

$this->_proc->setParameter('', 'feedTitle', $feed->getTitle());
$this->_proc->setParameter('', 'feedDescription', $feed->getDescription());
$this->_proc->setParameter('', 'link', $feedLink);
$this->proc->setParameter('', 'feedTitle', $feed->getTitle());
$this->proc->setParameter('', 'feedDescription', $feed->getDescription());
$this->proc->setParameter('', 'link', $feedLink);
}

/**
* @param array $resultList
* @param Base $resultList
* @throws Exception
*/
private function setDates($resultList)
{
if ($resultList->getNumberOfHits() > 0) {
$latestDoc = $resultList->getResults();
$document = Document::get($latestDoc[0]->getId());
$date = $document->getServerDatePublished()->getDateTime();
$document = Document::get($latestDoc[0]->getId());
$date = $document->getServerDatePublished()->getDateTime();
} else {
$date = new DateTime(); // now
}

$dateOutput = $date->format(DateTime::RFC2822);
$this->_proc->setParameter('', 'lastBuildDate', $dateOutput);
$this->_proc->setParameter('', 'pubDate', $dateOutput);
$this->proc->setParameter('', 'lastBuildDate', $dateOutput);
$this->proc->setParameter('', 'pubDate', $dateOutput);
}

/**
* @param array $resultList
* @param Base $resultList
* @throws Application_Exception
* @throws DOMException
*/
private function setItems($resultList)
{
$this->_xml->appendChild($this->_xml->createElement('Documents'));
$this->xml->appendChild($this->xml->createElement('Documents'));
foreach ($resultList->getResults() as $result) {
$document = Document::get($result->getId());
$document = Document::get($result->getId());
$documentXml = new Application_Util_Document($document);
$domNode = $this->_xml->importNode($documentXml->getNode(), true);
$domNode = $this->xml->importNode($documentXml->getNode(), true);

// add publication date in RFC_2822 format
$date = $document->getServerDatePublished()->getDateTime();
$itemPubDate = $this->_xml->createElement('ItemPubDate', $date->format(DateTime::RFC2822));
$date = $document->getServerDatePublished()->getDateTime();
$itemPubDate = $this->xml->createElement('ItemPubDate', $date->format(DateTime::RFC2822));
$domNode->appendChild($itemPubDate);
$this->_xml->documentElement->appendChild($domNode);
$this->xml->documentElement->appendChild($domNode);
}
}

private function setFrontdoorBaseUrl()
{
$this->_proc->setParameter('', 'frontdoorBaseUrl', $this->view->fullUrl() . '/frontdoor/index/index/docId/');
$this->proc->setParameter('', 'frontdoorBaseUrl', $this->view->fullUrl() . '/frontdoor/index/index/docId/');
}
}
16 changes: 9 additions & 7 deletions modules/rss/models/Feed.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of OPUS. The software OPUS has been originally developed
* at the University of Stuttgart with funding from the German Research Net,
Expand All @@ -24,20 +25,21 @@
* along with OPUS; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @category Application
* @package Module_Rss
* @author Jens Schwidder <[email protected]>
* @copyright Copyright (c) 2008-2016, OPUS 4 development team
* @copyright Copyright (c) 2008, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*
* TODO context spezifische Titel für RSS feed (latest, collections, ...)
*/

/**
* TODO context spezifische Titel für RSS feed (latest, collections, ...)
*/
class Rss_Model_Feed extends Application_Model_Abstract
{

/** @var Zend_View_Interface */
private $view;

/**
* @param Zend_View_Interface $view
*/
public function __construct($view)
{
$this->view = $view;
Expand Down
20 changes: 9 additions & 11 deletions tests/modules/rss/controllers/IndexControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@
use Opus\Common\Title;

/**
* Class Rss_IndexControllerTest
*
* TODO fix Solr configuration
*
* @covers Rss_IndexController
*/
class Rss_IndexControllerTest extends ControllerTestCase
{

/** @var string */
protected $additionalResources = 'all';

public function testIndexAction()
Expand All @@ -62,9 +60,9 @@ public function testUnavailableSolrServerReturns503()
$this->requireSolrConfig();

// manipulate solr configuration
$config = $this->getConfig();
$host = $config->searchengine->index->host;
$port = $config->searchengine->index->port;
$config = $this->getConfig();
$host = $config->searchengine->index->host;
$port = $config->searchengine->index->port;
$config->searchengine->index->app = 'solr/corethatdoesnotexist';

$this->dispatch('/rss/index/index/searchtype/all');
Expand Down Expand Up @@ -98,8 +96,8 @@ public function testSolrIndexIsNotUpToDate()
$doc1->unregisterPlugin('Opus_Document_Plugin_Index');
$doc1->store();

$docId1 = $doc1->getId();
$date = new DateTime($doc1->getServerDatePublished());
$docId1 = $doc1->getId();
$date = new DateTime($doc1->getServerDatePublished());
$dateValue1 = $date->format(DateTime::RFC2822);

$indexer = Opus\Search\Service::selectIndexingService(null, 'solr');
Expand All @@ -120,8 +118,8 @@ public function testSolrIndexIsNotUpToDate()
$doc2->setTitleMain($title);
$doc2->store();

$docId2 = $doc2->getId();
$date = new DateTime($doc2->getServerDatePublished());
$docId2 = $doc2->getId();
$date = new DateTime($doc2->getServerDatePublished());
$dateValue2 = $date->format(DateTime::RFC2822);

$this->dispatch('/rss/index/index/searchtype/all');
Expand Down Expand Up @@ -185,7 +183,7 @@ public function testOutputWithEmptySearchResult()
*/
public function testRssLink()
{
\Zend_Controller_Front::getInstance()->setBaseUrl('opus4dev');
Zend_Controller_Front::getInstance()->setBaseUrl('opus4dev');
$this->dispatch('/rss/index/index');
$this->assertXpathContentContains('//link', 'http://opus4dev/frontdoor/index/index/docId/147');
$this->assertXpathContentContains('//link', 'http://opus4dev/frontdoor/index/index/docId/150');
Expand Down
41 changes: 22 additions & 19 deletions tests/modules/rss/models/FeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,34 @@

class Rss_Model_FeedTest extends ControllerTestCase
{

/** @var bool */
protected $configModifiable = true;

/** @var string[] */
protected $additionalResources = ['view'];

private $_model;
/** @var Rss_Model_Feed */
private $model;

public function setUp(): void {
public function setUp(): void
{
parent::setUp();

$view = $this->getView();

$this->_model = new Rss_Model_Feed($view);
$this->model = new Rss_Model_Feed($view);
}

public function testGetTitle()
{
$view = $this->getView();
\Zend_Controller_Front::getInstance()->setBaseUrl('/opus4test');
Zend_Controller_Front::getInstance()->setBaseUrl('/opus4test');
$model = new Rss_Model_Feed($view);

$this->assertEquals('http:///opus4test', $model->getTitle());

$this->adjustConfiguration([
'rss' => ['default' => ['feedTitle' => 'OPUS 4 Test']]
'rss' => ['default' => ['feedTitle' => 'OPUS 4 Test']],
]);

$model->setConfig(null); // reset local reference to configuration
Expand All @@ -66,58 +69,58 @@ public function testGetTitle()
public function testGetTitleWithName()
{
$this->adjustConfiguration([
'rss' => ['default' => ['feedTitle' => '%1$s']]
'rss' => ['default' => ['feedTitle' => '%1$s']],
]);
$this->assertEquals('OPUS 4', $this->_model->getTitle());
$this->assertEquals('OPUS 4', $this->model->getTitle());
}

public function testGetTitleWithFullUrl()
{
$view = $this->getView();
\Zend_Controller_Front::getInstance()->setBaseUrl('/opus4test');
Zend_Controller_Front::getInstance()->setBaseUrl('/opus4test');
$model = new Rss_Model_Feed($view);

$this->adjustConfiguration([
'rss' => ['default' => ['feedTitle' => '%4$s']]
'rss' => ['default' => ['feedTitle' => '%4$s']],
]);
$this->assertEquals('http:///opus4test', $this->_model->getTitle());
$this->assertEquals('http:///opus4test', $this->model->getTitle());
}

public function testGetTitleWithBaseUrl()
{
$view = $this->getView();
\Zend_Controller_Front::getInstance()->setBaseUrl('/opus4test');
Zend_Controller_Front::getInstance()->setBaseUrl('/opus4test');
$model = new Rss_Model_Feed($view);

$this->adjustConfiguration([
'rss' => ['default' => ['feedTitle' => '%3$s']]
'rss' => ['default' => ['feedTitle' => '%3$s']],
]);
$this->assertEquals('opus4test', $model->getTitle());
}

public function testGetTitleWithHost()
{
$view = $this->getView();
\Zend_Controller_Front::getInstance()->setBaseUrl('/opus4test');
Zend_Controller_Front::getInstance()->setBaseUrl('/opus4test');
$view->getHelper('ServerUrl')->setHost('testhost');
$model = new Rss_Model_Feed($view);

$this->adjustConfiguration([
'rss' => ['default' => ['feedTitle' => '%2$s']]
'rss' => ['default' => ['feedTitle' => '%2$s']],
]);
$this->assertEquals('testhost', $model->getTitle());
}

public function testGetDescription()
{
$this->assertEquals('OPUS documents', $this->_model->getDescription());
$this->assertEquals('OPUS documents', $this->model->getDescription());

$this->adjustConfiguration([
'rss' => ['default' => ['feedDescription' => 'Test description.']]
'rss' => ['default' => ['feedDescription' => 'Test description.']],
]);

$this->_model->setConfig(null); // reset local reference to configuration
$this->model->setConfig(null); // reset local reference to configuration

$this->assertEquals('Test description.', $this->_model->getDescription());
$this->assertEquals('Test description.', $this->model->getDescription());
}
}

0 comments on commit 6bf466f

Please sign in to comment.