Beispiel #1
0
 /**
  * Check for each database document in serverState publish if it exists in
  * Solr index. Furthermore, compare field value of serverDateModified in
  * database and Solr index.
  * 
  */
 private function checkDatabase()
 {
     $finder = new Opus_DocumentFinder();
     $finder->setServerState('published');
     $ids = $finder->ids();
     $this->logger->info('checking ' . $finder->count() . ' published documents for consistency.');
     foreach ($ids as $id) {
         try {
             $doc = new Opus_Document($id);
         } catch (Opus_Model_NotFoundException $e) {
             // ignore: document was deleted from database in meantime
             continue;
         }
         $serverDataModified = $doc->getServerDateModified()->getUnixTimestamp();
         // retrieve document from index and compare serverDateModified fields
         $query = new Opus_SolrSearch_Query(Opus_SolrSearch_Query::DOC_ID);
         $query->setField('id', $id);
         $resultList = $this->searcher->search($query, $this->validateDocIds);
         $results = $resultList->getResults();
         if ($resultList->getNumberOfHits() == 0) {
             $this->logger->info("inconsistency found for document {$id}: document is in database, but is not in Solr index.");
             $this->numOfInconsistencies++;
             if ($this->forceReindexing($doc)) {
                 $this->numOfUpdates++;
             }
         } else {
             if ($resultList->getNumberOfHits() == 1) {
                 if ($results[0]->getServerDateModified() != $serverDataModified) {
                     $this->numOfInconsistencies++;
                     $this->logger->info("inconsistency found for document {$id}: mismatch between values of server_date_modified in database and Solr index.");
                     if ($this->forceReindexing($doc)) {
                         $this->numOfUpdates++;
                     }
                 }
             } else {
                 $this->logger->err('unexpected state: document with id ' . $id . ' exists multiple times in index.');
             }
         }
     }
 }
Beispiel #2
0
 public function testNumberOfDocuments()
 {
     $odf = new Opus_DocumentFinder();
     $this->assertEquals('0', $odf->count());
 }
Beispiel #3
0
 /**
  * prevent URN collisions: check that given URN is unique (in our database)
  */
 private function _validateURN()
 {
     if (!array_key_exists('IdentifierUrn', $this->extendedData)) {
         return true;
     }
     $urn = $this->extendedData['IdentifierUrn'];
     $value = $urn['value'];
     if (trim($value) == '') {
         return true;
     }
     // check URN $urn for collision
     $finder = new Opus_DocumentFinder();
     $finder->setIdentifierTypeValue('urn', $value);
     if ($finder->count() == 0) {
         return true;
     }
     $element = $this->form->getElement('IdentifierUrn');
     if (!is_null($element)) {
         $element->clearErrorMessages();
         $element->addError($this->translate('publish_error_urn_collision'));
     }
     return false;
 }
 /**
  * Regression test for OPUSVIER-849
  */
 public function testStartPageContainsTotalNumOfDocs()
 {
     // get total number of documents from all doc search
     $this->dispatch('/solrsearch/index/search/searchtype/all');
     $document = new DOMDocument();
     $document->loadHTML($this->getResponse()->getBody());
     $element = $document->getElementById('search-result-numofhits');
     $numOfHits = $element->firstChild->textContent;
     $docsInIndex = $this->getDocsInSearchIndex();
     $numOfIndexDocs = $docsInIndex->getNumberOfHits();
     $this->assertEquals($numOfIndexDocs, $numOfHits);
     $this->getResponse()->clearBody();
     $this->dispatch('/home');
     $document = new DOMDocument();
     $document->loadHTML($this->getResponse()->getBody());
     $element = $document->getElementById('solrsearch-totalnumofdocs');
     $numOfDocs = $element->firstChild->textContent;
     $docFinder = new Opus_DocumentFinder();
     $docFinder->setServerState('published');
     $numOfDbDocs = $docFinder->count();
     $this->assertEquals($numOfDbDocs, $numOfDocs);
     // kurze Erklärung des Vorhabens: die Dokumentanzahl bei der Catch-All-Suche
     // wird auf Basis einer Indexsuche ermittelt; die Anzahl der Dokument, die
     // auf der Startseite erscheint, wird dagegen über den DocumentFinder
     // ermittelt: im Idealfall sollten diese beiden Zahlen nicht voneinander
     // abweichen
     // wenn sie abweichen, dann aufgrund einer Inkonsistenz zwischen Datenbank
     // und Suchindex (das sollte im Rahmen der Tests eigentlich nicht auftreten)
     if ($numOfDbDocs != $numOfIndexDocs) {
         // ermittle die Doc-IDs, die im Index, aber nicht in der DB existieren
         // bzw. die in der DB, aber nicht im Index existieren
         $idsIndex = array();
         $results = $docsInIndex->getResults();
         foreach ($results as $result) {
             array_push($idsIndex, $result->getId());
         }
         $idsDb = $docFinder->ids();
         $idsIndexOnly = array_diff($idsIndex, $idsDb);
         $this->assertEquals(0, count($idsIndexOnly), 'Document IDs in search index, but not in database: ' . var_export($idsIndexOnly, true));
         $idsDbOnly = array_diff($idsDb, $idsIndex);
         $this->assertEquals(0, count($idsDbOnly), 'Document IDs in database, but not in search index: ' . var_export($idsDbOnly, true));
         $this->assertEquals($numOfDbDocs, $numOfIndexDocs, "number of docs in database ({$numOfDbDocs}) and search index ({$numOfIndexDocs}) differ from each other");
     }
     $this->assertEquals($numOfDocs, $numOfHits);
 }
Beispiel #5
0
 /**
  * Returns sum of all documents published before the $thresholdYear.
  */
 public function getNumDocsUntil($thresholdYear)
 {
     $finder = new Opus_DocumentFinder();
     $finder->setServerState('published');
     $finder->setServerDatePublishedBefore($thresholdYear + 1);
     return $finder->count();
 }
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the Licence, or any later version.
 * OPUS 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 OPUS; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * @category    Application
 * @author      Sascha Szott <*****@*****.**>
 * @copyright   Copyright (c) 2008-2012, OPUS 4 development team
 * @license     http://www.gnu.org/licenses/gpl.html General Public License
 * @version     $Id: delete_non-demo_docs.php 10249 2012-02-15 17:00:09Z sszott $
 */
/**
 * Erstellt die Demoinstanz, in der nur die Testdokumente mit den IDs 91 bis 110
 * enthalten sind.
 *
 */
$finder = new Opus_DocumentFinder();
foreach ($finder->ids() as $id) {
    if (intval($id) < 91 || intval($id) > 110) {
        $doc = new Opus_Document($id);
        $doc->deletePermanent();
        echo "document " . $id . " was deleted.\n";
    }
}
$finder = new Opus_DocumentFinder();
echo "done -- num of remaining docs: " . $finder->count() . "\n";
exit;
Beispiel #7
0
 *
 * LICENCE
 * OPUS 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 Licence, or any later version.
 * OPUS 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 OPUS; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * @category    Application
 * @author      Sascha Szott <*****@*****.**>
 * @copyright   Copyright (c) 2008-2012, OPUS 4 development team
 * @license     http://www.gnu.org/licenses/gpl.html General Public License
 * @version     $Id: delete_all_docs.php 10244 2012-02-14 14:57:36Z sszott $
 */
/**
 * Removes all documents
 *
 */
$finder = new Opus_DocumentFinder();
foreach ($finder->ids() as $id) {
    $doc = new Opus_Document($id);
    $doc->deletePermanent();
    echo "document " . $id . " was deleted.\n";
}
$finder = new Opus_DocumentFinder();
echo "done -- num of docs: " . $finder->count() . "\n";
exit;
Beispiel #8
0
 public function indexAction()
 {
     $this->_helper->mainMenu('home');
     $finder = new Opus_DocumentFinder();
     $finder->setServerState('published');
     $this->view->totalNumOfDocs = $finder->count();
 }
 /**
  * Regression test for OPUSVIER-2144
  *
  * IMPORTANT: Unit Test funktioniert nicht mehr, wenn die Zahl der Dokumente 20 übersteigt.
  */
 public function testLastPageUrlEqualsNextPageUrlDocTypeArticle()
 {
     $docFinder = new Opus_DocumentFinder();
     $docFinder->setType('article')->setServerState('published');
     $this->assertEquals(20, $docFinder->count(), "Test data changed!");
     $this->doStandardControllerTest('/solrsearch/index/search/searchtype/simple/query/*%3A*/browsing/true/doctypefq/article', null, null);
     $this->assertTrue(4 == substr_count($this->getResponse()->getBody(), '/solrsearch/index/search/searchtype/simple/query/%2A%3A%2A/browsing/true/doctypefq/article/start/10/rows/10">'));
     $this->assertNotContains('solrsearch/index/search/searchtype/simple/query/%2A%3A%2A/browsing/true/doctypefq/doctoralthesis/start/19/rows/10">', $this->getResponse()->getBody());
     $this->assertEquals(20, $this->getNumOfHits());
 }
 public function testReadLogfileWithNonEmptyFile()
 {
     $this->enableAsyncMode();
     $finder = new Opus_DocumentFinder();
     $finder->setServerState('published');
     $numOfPublishedDocs = $finder->count();
     $model = new Admin_Model_IndexMaintenance();
     $model->createJob();
     $this->runJobImmediately();
     $logdata = $model->readLogFile();
     $this->assertNotNull($logdata);
     $this->assertNotNull($logdata->getContent());
     $this->assertNotNull($logdata->getModifiedDate());
     $this->assertContains("checking {$numOfPublishedDocs} published documents for consistency.", $logdata->getContent(), "content of logfile:\n" . $logdata->getContent());
     $this->assertContains('No inconsistency was detected.', $logdata->getContent());
     $this->assertContains('Completed operation after ', $logdata->getContent());
 }
 public function testShowAllHits()
 {
     $docFinder = new Opus_DocumentFinder();
     $docFinder->setServerState('unpublished');
     $unpublishedDocs = $docFinder->count();
     $this->dispatch('/admin/documents/index/state/unpublished/hitsperpage/all');
     $this->assertQueryCount('span.title', $unpublishedDocs);
 }