Skip to content

Commit

Permalink
#1240 Coding style fixes (merge 'master')
Browse files Browse the repository at this point in the history
  • Loading branch information
j3nsch committed Oct 14, 2024
2 parents 3bb1c7c + 9a5fccb commit 1a7cc9c
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 58 deletions.
8 changes: 5 additions & 3 deletions library/Application/Form/Element/SearchFieldModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

use Opus\Search\Util\Query;

class Application_Form_Element_SearchFieldModifier extends Application_Form_Element_Select
{
public function init()
{
parent::init();

$options = [
Opus\Search\Util\Query::SEARCH_MODIFIER_CONTAINS_ALL => 'advanced_search_form_modifier_all',
Opus\Search\Util\Query::SEARCH_MODIFIER_CONTAINS_ANY => 'advanced_search_form_modifier_one',
Opus\Search\Util\Query::SEARCH_MODIFIER_CONTAINS_NONE => 'advanced_search_form_modifier_none',
Query::SEARCH_MODIFIER_CONTAINS_ALL => 'advanced_search_form_modifier_all',
Query::SEARCH_MODIFIER_CONTAINS_ANY => 'advanced_search_form_modifier_one',
Query::SEARCH_MODIFIER_CONTAINS_NONE => 'advanced_search_form_modifier_none',
];

$this->addMultiOptions($options);
Expand Down
7 changes: 4 additions & 3 deletions modules/export/models/XmlExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Opus\Common\Document;
use Opus\Common\Repository;
use Opus\Common\Security\Realm;
use Opus\Search\Util\Query;

/**
* Export plugin for exporting documents as XML.
Expand Down Expand Up @@ -319,7 +320,7 @@ public function prepareXml()
*/
public function getMaxRows()
{
$maxRows = Opus\Search\Util\Query::MAX_ROWS;
$maxRows = Query::MAX_ROWS;

$config = $this->getConfig();

Expand All @@ -338,8 +339,8 @@ public function getMaxRows()
}

// Do not allows configured values to exceed java.lang.Integer.MAX_VALUE (Solr)
if ($maxRows > Opus\Search\Util\Query::MAX_ROWS) {
$maxRows = Opus\Search\Util\Query::MAX_ROWS;
if ($maxRows > Query::MAX_ROWS) {
$maxRows = Query::MAX_ROWS;
}

return $maxRows;
Expand Down
5 changes: 3 additions & 2 deletions modules/solrsearch/controllers/BrowseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/

use Opus\Search\SearchException;
use Opus\Search\Util\Query;

/**
* TODO move list handling into model
Expand Down Expand Up @@ -83,7 +84,7 @@ public function doctypesAction()
}

$facetname = 'doctype';
$query = new Opus\Search\Util\Query(Opus\Search\Util\Query::FACET_ONLY);
$query = new Query(Query::FACET_ONLY);
$query->setFacetField($facetname);

try {
Expand Down Expand Up @@ -119,7 +120,7 @@ public function yearsAction()

$facetname = 'year';

$query = new Opus\Search\Util\Query(Opus\Search\Util\Query::FACET_ONLY);
$query = new Query(Query::FACET_ONLY);

$facetManager = new Application_Search_FacetManager();
$facet = $facetManager->getFacet($facetname);
Expand Down
4 changes: 3 additions & 1 deletion modules/solrsearch/forms/AdvancedSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

use Opus\Search\Util\Query;

/**
* Advanced search form.
*
Expand Down Expand Up @@ -203,7 +205,7 @@ public function addSearchField($name)
]);

if ($name === 'fulltext') {
$modifier->removeMultiOption(Opus\Search\Util\Query::SEARCH_MODIFIER_CONTAINS_ANY);
$modifier->removeMultiOption(Query::SEARCH_MODIFIER_CONTAINS_ANY);
}
$this->addElement($modifier);

Expand Down
3 changes: 2 additions & 1 deletion modules/solrsearch/models/FacetMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/

use Opus\Common\CollectionRole;
use Opus\Search\Facet\Set;

/**
* TODO refactor as view helper or something better
Expand All @@ -45,7 +46,7 @@ class Solrsearch_Model_FacetMenu extends Application_Model_Abstract
public function buildFacetArray($paramSet)
{
// TODO not sure I like processing request parameters in *opus4-search* class (backend code)
return Opus\Search\Facet\Set::getFacetLimitsFromInput($paramSet);
return Set::getFacetLimitsFromInput($paramSet);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions modules/solrsearch/models/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

use Opus\Search\Util\Query;

/**
* Modelklasse fuer Suchfunktionalität, die von den Controllern verwendet wird.
*/
Expand Down Expand Up @@ -89,7 +91,7 @@ public function createAdvancedSearchUrlParams($request)
$params[$fieldname] = $fieldvalue;
$params[$fieldname . 'modifier'] = $request->getParam(
$fieldname . 'modifier',
Opus\Search\Util\Query::SEARCH_MODIFIER_CONTAINS_ALL
Query::SEARCH_MODIFIER_CONTAINS_ALL
);
}
}
Expand All @@ -104,7 +106,7 @@ public function createBasicSearchParams($request)
{
return [
'start' => $request->getParam('start', '0'),
'rows' => $request->getParam('rows', Opus\Search\Util\Query::getDefaultRows()),
'rows' => $request->getParam('rows', Query::getDefaultRows()),
'sortfield' => $request->getParam('sortfield', 'score'),
'sortorder' => $request->getParam('sortorder', 'desc'),
];
Expand Down
3 changes: 2 additions & 1 deletion modules/solrsearch/models/Search/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

use Opus\Search\Config;
use Opus\Search\Result\Base;
use Opus\Search\SearchException;
use Opus\Search\Util\Query;
Expand Down Expand Up @@ -67,7 +68,7 @@ public function __construct()

$this->filterFields = [];

$filters = Opus\Search\Config::getFacetNames();
$filters = Config::getFacetNames();
if (! count($filters)) {
$logger->debug('key searchengine.solr.facets is not present in config. skipping filter queries');
} else {
Expand Down
6 changes: 4 additions & 2 deletions scripts/snippets/find_modified_docs_in_searchindex.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

use Opus\Common\Document;
use Opus\Common\Repository;
use Opus\Search\QueryFactory;
use Opus\Search\Service;

/**
* Dieses Skript findet alle Dokumente mit ServerState=published, deren ServerDateModified im Solr-Index kleiner ist
Expand All @@ -49,8 +51,8 @@

foreach ($finder->getIds() as $docId) {
// check if document with id $docId is already persisted in search index
$search = Opus\Search\Service::selectSearchingService();
$query = Opus\Search\QueryFactory::selectDocumentById($search, $docId);
$search = Service::selectSearchingService();
$query = QueryFactory::selectDocumentById($search, $docId);

if ($search->customSearch($query)->getAllMatchesCount() !== 1) {
echo "ERROR: document # $docId is not stored in search index\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

use Opus\Search\Util\Query;

class Application_Form_Element_SearchFieldModifierTest extends ControllerTestCase
{
public function testOptions()
Expand All @@ -39,18 +41,18 @@ public function testOptions()

$this->assertCount(3, $options);

$this->assertNotNull($element->getMultiOption(Opus\Search\Util\Query::SEARCH_MODIFIER_CONTAINS_ALL));
$this->assertNotNull($element->getMultiOption(Opus\Search\Util\Query::SEARCH_MODIFIER_CONTAINS_ANY));
$this->assertNotNull($element->getMultiOption(Opus\Search\Util\Query::SEARCH_MODIFIER_CONTAINS_NONE));
$this->assertNotNull($element->getMultiOption(Query::SEARCH_MODIFIER_CONTAINS_ALL));
$this->assertNotNull($element->getMultiOption(Query::SEARCH_MODIFIER_CONTAINS_ANY));
$this->assertNotNull($element->getMultiOption(Query::SEARCH_MODIFIER_CONTAINS_NONE));
}

public function testValidationTrue()
{
$element = new Application_Form_Element_SearchFieldModifier('modifier');

$this->assertTrue($element->isValid(Opus\Search\Util\Query::SEARCH_MODIFIER_CONTAINS_ALL));
$this->assertTrue($element->isValid(Opus\Search\Util\Query::SEARCH_MODIFIER_CONTAINS_ANY));
$this->assertTrue($element->isValid(Opus\Search\Util\Query::SEARCH_MODIFIER_CONTAINS_NONE));
$this->assertTrue($element->isValid(Query::SEARCH_MODIFIER_CONTAINS_ALL));
$this->assertTrue($element->isValid(Query::SEARCH_MODIFIER_CONTAINS_ANY));
$this->assertTrue($element->isValid(Query::SEARCH_MODIFIER_CONTAINS_NONE));
}

public function testValidationFalse()
Expand Down
21 changes: 11 additions & 10 deletions tests/modules/admin/controllers/IndexmaintenanceControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Opus\Common\Job;
use Opus\Common\Log;
use Opus\Job\Runner;
use Opus\Search\Task\ConsistencyCheck;

/**
* @covers Admin_IndexmaintenanceController
Expand Down Expand Up @@ -59,7 +60,7 @@ public function tearDown(): void
}

// Cleanup of Jobs Table
$jobs = Job::getByLabels([Opus\Search\Task\ConsistencyCheck::LABEL]);
$jobs = Job::getByLabels([ConsistencyCheck::LABEL]);
foreach ($jobs as $job) {
try {
$job->delete();
Expand Down Expand Up @@ -248,7 +249,7 @@ public function testCheckconsistencyActionWithEnabledFeature()
{
$this->enableAsyncIndexmaintenanceMode();

$numOfJobs = Job::getCountForLabel(Opus\Search\Task\ConsistencyCheck::LABEL);
$numOfJobs = Job::getCountForLabel(ConsistencyCheck::LABEL);
$this->assertEquals(0, $numOfJobs);

$this->getRequest()->setMethod('POST');
Expand All @@ -257,27 +258,27 @@ public function testCheckconsistencyActionWithEnabledFeature()
$this->assertResponseCode(302);
$this->assertResponseLocationHeader($this->getResponse(), '/admin/indexmaintenance');

$this->assertEquals(1, Job::getCountForLabel(Opus\Search\Task\ConsistencyCheck::LABEL));
$this->assertEquals(1, Job::getCountForLabel(ConsistencyCheck::LABEL));

$jobs = Job::getByLabels([Opus\Search\Task\ConsistencyCheck::LABEL]);
$jobs = Job::getByLabels([ConsistencyCheck::LABEL]);
$jobs[0]->delete();

$this->assertEquals(0, Job::getCountForLabel(Opus\Search\Task\ConsistencyCheck::LABEL));
$this->assertEquals(0, Job::getCountForLabel(ConsistencyCheck::LABEL));
}

public function testCheckconsistencyActionResult()
{
$this->enableAsyncIndexmaintenanceMode();

$this->assertEquals(0, Job::getCountForLabel(Opus\Search\Task\ConsistencyCheck::LABEL), 'missing cleanup of jobs table');
$this->assertEquals(0, Job::getCountForLabel(ConsistencyCheck::LABEL), 'missing cleanup of jobs table');

$this->getRequest()->setMethod('POST');
$this->dispatch('/admin/indexmaintenance/checkconsistency');

$this->assertResponseCode(302);
$this->assertResponseLocationHeader($this->getResponse(), '/admin/indexmaintenance');

$this->assertEquals(1, Job::getCountForLabel(Opus\Search\Task\ConsistencyCheck::LABEL), 'consistency check job was not stored in database');
$this->assertEquals(1, Job::getCountForLabel(ConsistencyCheck::LABEL), 'consistency check job was not stored in database');

/*
* check if job was scheduled for execution
Expand All @@ -300,11 +301,11 @@ public function testCheckconsistencyActionResult()
*/
$jobrunner = new Runner();
$jobrunner->setLogger(Log::get());
$worker = new Opus\Search\Task\ConsistencyCheck();
$worker = new ConsistencyCheck();
$jobrunner->registerWorker($worker);
$jobrunner->run();

$jobs = Job::getByLabels([Opus\Search\Task\ConsistencyCheck::LABEL]);
$jobs = Job::getByLabels([ConsistencyCheck::LABEL]);
if (count($jobs) > 0) {
$job = $jobs[0];
$message = 'at least one unexpected job found (Label: \'%s\', State: \'%s\', Data: \'%s\', Errors: \'%s\, SHA1 Hash: \'%s\')';
Expand All @@ -316,7 +317,7 @@ public function testCheckconsistencyActionResult()
$this->fail(sprintf($message, $label, $state, $data, $errors, $hash));
}

$this->assertEquals(0, Job::getCountForLabel(Opus\Search\Task\ConsistencyCheck::LABEL), 'consistency check job was not removed from database after execution');
$this->assertEquals(0, Job::getCountForLabel(ConsistencyCheck::LABEL), 'consistency check job was not removed from database after execution');

$this->resetResponse();
$this->resetRequest();
Expand Down
13 changes: 7 additions & 6 deletions tests/modules/admin/models/IndexMaintenanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Opus\Common\Job;
use Opus\Common\Log;
use Opus\Job\Runner;
use Opus\Search\Task\ConsistencyCheck;

class Admin_Model_IndexMaintenanceTest extends ControllerTestCase
{
Expand Down Expand Up @@ -61,7 +62,7 @@ public function tearDown(): void
}

// Cleanup of Jobs Table
$jobs = Job::getByLabels([Opus\Search\Task\ConsistencyCheck::LABEL]);
$jobs = Job::getByLabels([ConsistencyCheck::LABEL]);
foreach ($jobs as $job) {
try {
$job->delete();
Expand Down Expand Up @@ -147,7 +148,7 @@ public function testNotAllowConsistencyCheck()
$model->createJob();
$this->assertFalse($model->allowConsistencyCheck());

$this->assertEquals(1, Job::getCountForLabel(Opus\Search\Task\ConsistencyCheck::LABEL));
$this->assertEquals(1, Job::getCountForLabel(ConsistencyCheck::LABEL));
}

public function testNotAllowConsistencyCheckAlt()
Expand All @@ -158,7 +159,7 @@ public function testNotAllowConsistencyCheckAlt()
$model->createJob();
$this->assertFalse($model->allowConsistencyCheck());

$this->assertEquals(1, Job::getCountForLabel(Opus\Search\Task\ConsistencyCheck::LABEL));
$this->assertEquals(1, Job::getCountForLabel(ConsistencyCheck::LABEL));
}

public function testProcessingStateInvalidContext()
Expand All @@ -170,15 +171,15 @@ public function testProcessingStateInvalidContext()

private function runJobImmediately()
{
$this->assertEquals(1, Job::getCountForLabel(Opus\Search\Task\ConsistencyCheck::LABEL));
$this->assertEquals(1, Job::getCountForLabel(ConsistencyCheck::LABEL));

$jobrunner = new Runner();
$jobrunner->setLogger(Log::get());
$worker = new Opus\Search\Task\ConsistencyCheck();
$worker = new ConsistencyCheck();
$jobrunner->registerWorker($worker);
$jobrunner->run();

$this->assertEquals(0, Job::getCountForLabel(Opus\Search\Task\ConsistencyCheck::LABEL));
$this->assertEquals(0, Job::getCountForLabel(ConsistencyCheck::LABEL));
}

public function testProcessingStateInitial()
Expand Down
5 changes: 3 additions & 2 deletions tests/modules/export/models/XmlExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

use Opus\Common\Repository;
use Opus\Common\Title;
use Opus\Search\Util\Query;

/**
* @covers \Export_Model_XmlExport
Expand Down Expand Up @@ -237,7 +238,7 @@ public function testXmlExportForSearchtypeIdWithUnpublishedDocument()

public function testGetMaxRows()
{
$this->assertEquals(Opus\Search\Util\Query::MAX_ROWS, $this->plugin->getMaxRows());
$this->assertEquals(Query::MAX_ROWS, $this->plugin->getMaxRows());

$this->enableSecurity();

Expand All @@ -249,7 +250,7 @@ public function testGetMaxRows()

$this->loginUser('admin', 'adminadmin');

$this->assertEquals(Opus\Search\Util\Query::MAX_ROWS, $this->plugin->getMaxRows());
$this->assertEquals(Query::MAX_ROWS, $this->plugin->getMaxRows());
}

public function testGetValueIfValid()
Expand Down
5 changes: 3 additions & 2 deletions tests/modules/home/controllers/IndexControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

use Opus\Search\Result\Base;
use Opus\Search\SearchException;
use Opus\Search\Util\Query;

/**
* Basic unit test for inded controller of home module.
Expand Down Expand Up @@ -144,9 +145,9 @@ public function testNoticeAction()
private function getDocsInSearchIndex($checkConsistency = true)
{
$searcher = Application_Search_SearcherFactory::getSearcher();
$query = new Opus\Search\Util\Query();
$query = new Query();
$query->setCatchAll("*:*");
$query->setRows(Opus\Search\Util\Query::MAX_ROWS);
$query->setRows(Query::MAX_ROWS);
return $searcher->search($query, $checkConsistency);
}

Expand Down
Loading

0 comments on commit 1a7cc9c

Please sign in to comment.