public function testUpdateOnLicenceChange() { $document = $this->createTestDocument(); $document->store(); $documentCacheTable = new Opus_Db_DocumentXmlCache(); $docXmlCache = $documentCacheTable->find($document->getId(), '1')->current()->xml_data; $domDoc = new DomDocument(); $domDoc->loadXML($docXmlCache); $licences = $domDoc->getElementsByTagName('Licence'); $this->assertTrue($licences->length == 0, 'Expected no Licence element in dom.'); $licence = new Opus_Licence(); $licence->setNameLong('TestLicence'); $licence->setLinkLicence('http://example.org/licence'); $licenceId = $licence->store(); $document->setServerState('published'); $document->setLicence($licence); $docId = $document->store(); $licence = new Opus_Licence($licenceId); $licence->setNameLong('TestLicenceAltered'); $licence->store(); $docXmlCacheResult = $documentCacheTable->find($document->getId(), '1'); $this->assertTrue($docXmlCacheResult->count() == 0, 'Expected empty document xml cache'); $this->executeScript('cron-update-document-cache.php'); $docXmlCacheAfter = $documentCacheTable->find($docId, '1')->current()->xml_data; $domDocAfter = new DomDocument(); $domDocAfter->loadXML($docXmlCacheAfter); $licencesAfter = $domDocAfter->getElementsByTagName('Licence'); $this->assertTrue($licencesAfter->length == 1, 'Expected one Licence element in dom.'); $licences = $document->getLicence(); $licences[0]->delete(); }
public function testXmlSortOrder() { $firstDoc = $this->createTestDocument(); $firstDoc->setPublishedYear(9999); $firstDoc->setServerState('published'); $firstDocId = $firstDoc->store(); $secondDoc = $this->createTestDocument(); $secondDoc->setPublishedYear(9998); $secondDoc->setServerState('published'); $secondDocId = $secondDoc->store(); $forthDoc = $this->createTestDocument(); $forthDoc->setPublishedYear(9996); $forthDoc->setServerState('published'); $forthDocId = $forthDoc->store(); $thirdDoc = $this->createTestDocument(); $thirdDoc->setPublishedYear(9997); $thirdDoc->setServerState('published'); $thirdDocId = $thirdDoc->store(); // Dokument aus dem Cache löschen $documentCacheTable = new Opus_Db_DocumentXmlCache(); $documentCacheTable->delete('document_id = ' . $secondDocId); $documentCacheTable->delete('document_id = ' . $firstDocId); $this->getRequest()->setMethod('POST')->setPost(array('searchtype' => 'all', 'sortfield' => 'year', 'sortorder' => 'desc', 'rows' => '10')); $this->plugin->prepareXml(); $xpath = new DOMXPath($this->plugin->getXml()); $result = $xpath->query('//Opus_Document'); $this->assertEquals(10, $result->length); $this->assertEquals($firstDocId, $result->item(0)->attributes->item(0)->nodeValue); $this->assertEquals($secondDocId, $result->item(1)->attributes->item(0)->nodeValue); $this->assertEquals($thirdDocId, $result->item(2)->attributes->item(0)->nodeValue); $this->assertEquals($forthDocId, $result->item(3)->attributes->item(0)->nodeValue); }
* 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 Edouard Simon <*****@*****.**> * @copyright Copyright (c) 2011-2013, OPUS 4 development team * @license http://www.gnu.org/licenses/gpl.html General Public License * @version $Id: cron-update-document-cache.php 11732 2013-06-24 12:26:11Z esimon $ */ define('APPLICATION_ENV', 'development'); // Bootstrapping require_once dirname(__FILE__) . '/../common/bootstrap.php'; $opusDocCacheTable = new Opus_Db_DocumentXmlCache(); $db = Zend_Registry::get('db_adapter'); // $select = $db->select(); $select->from($opusDocCacheTable->info('name'), 'document_id'); $docFinder = new Opus_DocumentFinder(); $docFinder->setSubSelectNotExists($select); $docIds = $docFinder->ids(); echo "processing " . count($docIds) . " documents\n"; foreach ($docIds as $docId) { $model = new Opus_Document($docId); $cache = new Opus_Model_Xml_Cache(); // xml version 1 $omx = new Opus_Model_Xml(); $omx->setStrategy(new Opus_Model_Xml_Version1())->excludeEmptyFields()->setModel($model)->setXmlCache($cache); $dom = $omx->getDomDocument();
/** * Returns a list of documents from cache. * @param $resultIds ids of documents for export * @return array Map of docId to Document XML */ private function getDocumentsFromCache($documentIds) { $documents = array(); $documentCacheTable = new Opus_Db_DocumentXmlCache(); $docXmlCache = $documentCacheTable->fetchAll($documentCacheTable->select()->where('document_id IN (?)', $documentIds)); //->find($this->document->getId(), '1')->current()->xml_data; foreach ($docXmlCache as $row) { $fragment = new DomDocument(); $fragment->loadXML($row->xml_data); $node = $fragment->getElementsByTagName('Opus_Document')->item(0); $documents[$row->document_id] = $node; } return $documents; }
/** * Removes a all cache entries matching given constraint. * * @param Zend_Db_Select $select Select statement to use as subselect * The statement MUST return a list of document ids * @return void */ public function removeAllEntriesWhereSubSelect($select) { $where = 'document_id IN (' . $select->assemble() . ')'; $this->_table->delete($where); }