/** * Test list document ids, metadataPrefix=XMetaDissPlus, different intervals * list possible intervals *NOT* containing "2010-06-05" */ public function testIntervalOAIPMHQueryWithoutTestDoc() { $doc = $this->createTestDocument(); $doc->setServerState('published'); $this->docId = $doc->store(); $doc = new Opus_Document($this->docId); $serverDateModified = $doc->getServerDateModified(); $today = new DateTime(); $today->setDate($serverDateModified->getYear(), $serverDateModified->getMonth(), $serverDateModified->getDay()); $yesterday = clone $today; $yesterday->modify('-1 day'); $dayBeforeYesterday = clone $yesterday; $dayBeforeYesterday->modify('-1 day'); $tomorrow = clone $today; $tomorrow->modify('+1 day'); $dayAfterTomorrow = clone $tomorrow; $dayAfterTomorrow->modify('+1 day'); $yesterdayStr = date_format($yesterday, 'Y-m-d'); $dayBeforeYesterdayStr = date_format($dayBeforeYesterday, 'Y-m-d'); $tomorrowStr = date_format($tomorrow, 'Y-m-d'); $dayAfterTomorrowStr = date_format($dayAfterTomorrow, 'Y-m-d'); $intervals = array(array('from' => $tomorrowStr), array('until' => $yesterdayStr), array('from' => $tomorrowStr, 'until' => $dayAfterTomorrowStr), array('from' => $dayBeforeYesterdayStr, 'until' => $yesterdayStr)); foreach ($intervals as $interval) { $oaiRequest = array('verb' => 'ListRecords', 'metadataPrefix' => 'XMetaDissPlus'); $oaiRequest = array_merge($interval, $oaiRequest); $docListModel = new Oai_Model_DocumentList(); $docListModel->deliveringDocumentStates = array('published', 'deleted'); $docListModel->xMetaDissRestriction = array(); $docIds = $docListModel->query($oaiRequest); $this->assertFalse(in_array($this->docId, $docIds), "Response must NOT contain document id {$this->docId}: " . var_export($interval, true)); } }
/** * Regression Test for OPUSVIER-3051 */ public function testDocumentServerDateModifiedNotUpdatedWhenCollectionSortOrderChanged() { // check for expected test data $collectionRole1 = new Opus_CollectionRole(1); $this->assertEquals(1, $collectionRole1->getPosition(), 'Test setup changed'); $collectionRole2 = new Opus_CollectionRole(2); $this->assertEquals(2, $collectionRole2->getPosition(), 'Test setup changed'); $docfinder = new Opus_DocumentFinder(); $docfinder->setCollectionRoleId(2); $collectionRoleDocs = $docfinder->ids(); $this->assertTrue(in_array(146, $collectionRoleDocs), 'Test setup changed'); // test if server_date_modified is altered $docBefore = new Opus_Document(146); $this->dispatch('/admin/collectionroles/move/roleid/1/pos/2'); $docAfter = new Opus_Document(146); // revert change in test data $this->resetRequest(); $this->resetResponse(); $this->dispatch('/admin/collectionroles/move/roleid/1/pos/1'); $this->assertEquals((string) $docBefore->getServerDateModified(), (string) $docAfter->getServerDateModified()); }
* */ $numOfModified = 0; $numOfErrors = 0; $finder = new Opus_DocumentFinder(); $finder->setServerState('published'); foreach ($finder->ids() 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); if ($search->customSearch($query)->getAllMatchesCount() != 1) { echo "ERROR: document # {$docId} is not stored in search index\n"; $numOfErrors++; } else { $result = $search->getResults(); $solrModificationDate = $result[0]->getServerDateModified(); $document = new Opus_Document($docId); $docModificationDate = $document->getServerDateModified()->getUnixTimestamp(); if ($solrModificationDate != $docModificationDate) { $numOfModified++; echo "document # {$docId} is modified\n"; } } } if ($numOfErrors > 0) { echo "{$numOfErrors} missing documents were found\n"; echo "{$numOfModified} modified documents were found\n"; } else { echo "no missing or modified documents were found\n"; } exit;
/** * 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.'); } } } }