Exemple #1
0
 /**
  * @see {Opus_Model_Plugin_Interface::postDelete}
  */
 public function postDelete($modelId)
 {
     $cache = new Opus_Model_Xml_Cache();
     $omx = new Opus_Model_Xml();
     // xml version 1
     $omx->setStrategy(new Opus_Model_Xml_Version1());
     $cache->remove($modelId, floor($omx->getStrategyVersion()));
     // xml version 2
     $omx->setStrategy(new Opus_Model_Xml_Version2());
     $cache->remove($modelId, floor($omx->getStrategyVersion()));
 }
 /**
  * @param boolean $useCache
  * @return DOMNode Opus_Document node
  */
 public function getNode($useCache = true)
 {
     $xmlModel = new Opus_Model_Xml();
     $xmlModel->setModel($this->_document);
     $xmlModel->excludeEmptyFields();
     // needed for preventing handling errors
     $xmlModel->setStrategy(new Opus_Model_Xml_Version1());
     if ($useCache) {
         $xmlModel->setXmlCache(new Opus_Model_Xml_Cache());
     }
     $result = $xmlModel->getDomDocument();
     return $result->getElementsByTagName('Opus_Document')->item(0);
 }
 * 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-2011, OPUS 4 development team
 * @license     http://www.gnu.org/licenses/gpl.html General Public License
 * @version     $Id$
 */
/**
 * Returns the XML representation of the document with given id $id.
 */
if (isset($argv[2]) && !empty($argv[2]) && is_numeric($argv[2])) {
    $id = $argv[2];
} else {
    $id = 91;
}
try {
    $doc = new Opus_Document($id);
} catch (Opus_Model_NotFoundException $e) {
    echo "document with id {$id} does not exist";
    exit;
}
$xmlModel = new Opus_Model_Xml();
$xmlModel->setModel($doc);
$xmlModel->setStrategy(new Opus_Model_Xml_Version1());
$xmlModel->excludeEmptyFields();
echo $xmlModel->getDomDocument()->saveXML();
exit;
 * 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-2011, OPUS 4 development team
 * @license     http://www.gnu.org/licenses/gpl.html General Public License
 * @version     $Id$
 */
/**
 * Imports the XML representation from stdin and creates a new OPUS 4
 * document (with a new ID).
 */
$xml = '';
while (FALSE !== ($line = fgets(STDIN))) {
    $xml .= $line;
}
$xmlModel = new Opus_Model_Xml();
$xmlModel->setStrategy(new Opus_Model_Xml_Version1());
$xmlModel->setXml($xml);
$doc = $xmlModel->getModel();
$doc->store();
exit;
 * 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      Thoralf Klein <*****@*****.**>
 * @copyright   Copyright (c) 2010, OPUS 4 development team
 * @license     http://www.gnu.org/licenses/gpl.html General Public License
 * @version     $Id: opus-dump-document-xml.php 9015 2011-09-15 16:01:23Z tklein $
 */
// Bootstrapping
require_once dirname(__FILE__) . '/common/bootstrap.php';
// Remove first argument
array_shift($argv);
// Dump given documents
error_log("dumping document(s): " . implode(", ", $argv));
foreach ($argv as $docId) {
    error_log("<!-- dumping document-id {$docId}: -->");
    $d = new Opus_Document($docId);
    $xmlModel = new Opus_Model_Xml();
    $xmlModel->setModel($d);
    $xmlModel->excludeEmptyFields();
    $xmlModel->setStrategy(new Opus_Model_Xml_Version1());
    // $xmlModel->setXmlCache(new Opus_Model_Xml_Cache);
    $d_xml = $xmlModel->getDomDocument();
    $d_xml->formatOutput = true;
    echo $d_xml->saveXml();
}
$docFinder = new Opus_DocumentFinder();
foreach ($docFinder->ids() as $id) {
    $doc = null;
    try {
        $doc = new Opus_Document($id);
    } catch (Opus_Model_NotFoundException $e) {
        // document with id $id does not exist
        continue;
    }
    echo "try to export document {$id} ... ";
    $xmlModelOutput = new Opus_Model_Xml();
    $xmlModelOutput->setModel($doc);
    $xmlModelOutput->setStrategy(new Opus_Model_Xml_Version1());
    $xmlModelOutput->excludeEmptyFields();
    $domDocument = $xmlModelOutput->getDomDocument();
    echo "export of document {$id} was successful.\n";
    echo "try to import document based on the exported dom tree ... ";
    $xmlModelImport = new Opus_Model_Xml();
    $xmlModelImport->setStrategy(new Opus_Model_Xml_Version1());
    $xmlModelImport->setXml($domDocument->saveXML());
    try {
        $doc = $xmlModelImport->getModel();
        $doc->store();
        echo "OK - import of document {$id} was successful.\n";
    } catch (Exception $e) {
        echo "ERR - import of document {$id} was NOT successful.\n";
        echo $e;
    }
    echo "\n\n";
}
exit;
 * 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();
    echo "Cache refreshed for document#{$docId}\n";
}
Exemple #8
0
 /**
  * Returns a DOM representation of the filtered model.
  *
  * @param array $excludeFields Array of fields that shall not be serialized.
  * @param Opus_Model_Xml_Strategy $strategy Version of Xml to process
  * @param bool $excludeEmptyFields If set to false, fields with empty values are included in the resulting DOM.
  * @return DomDocument A Dom representation of the model.
  */
 public function toXml(array $excludeFields = null, $strategy = null, $excludeEmptyFields = true)
 {
     if (is_null($excludeFields) === true) {
         $excludeFields = array();
     }
     if (is_null($strategy) === true) {
         $strategy = new Opus_Model_Xml_Version1();
     }
     $xml = new Opus_Model_Xml();
     $xml->setModel($this)->exclude($excludeFields)->setStrategy($strategy);
     if ($excludeEmptyFields === true) {
         $xml->excludeEmptyFields();
     }
     return $xml->getDomDocument();
 }
 /**
  *
  * @param Opus_Document $document
  * @return DOMNode
  * @throws Exception
  */
 private function getDocumentXmlDomNode($document)
 {
     if (!in_array($document->getServerState(), $this->_deliveringDocumentStates)) {
         $message = 'Trying to get a document in server state "' . $document->getServerState() . '"';
         Zend_Registry::get('Zend_Log')->err($message);
         throw new Exception($message);
     }
     $xmlModel = new Opus_Model_Xml();
     $xmlModel->setModel($document);
     $xmlModel->excludeEmptyFields();
     $xmlModel->setStrategy(new Opus_Model_Xml_Version1());
     $xmlModel->setXmlCache(new Opus_Model_Xml_Cache());
     return $xmlModel->getDomDocument()->getElementsByTagName('Opus_Document')->item(0);
 }
Exemple #10
0
 /**
  * Instantiates an Opus_Model from xml as delivered by the toXml() method.
  *
  * @param  DomDocument|string  $xml                The xml representing the model.
  * @param  Opus_Model_Xml      $customDeserializer (Optional) Specify a custom deserializer object.
  * @return Opus_Model_Abstract The Opus_Model derived from xml.
  */
 public static function fromXml($xml, Opus_Model_Xml $customDeserializer = null)
 {
     if (is_null($customDeserializer)) {
         $customDeserializer = new Opus_Model_Xml();
     }
     if ($xml instanceof DomDocument) {
         $customDeserializer->setDomDocument($xml);
     } else {
         if (is_string($xml)) {
             $customDeserializer->setXml($xml);
         } else {
             throw new Opus_Model_Exception('Either DomDocument or xml string must be passed.');
         }
     }
     return $customDeserializer->getModel();
 }
Exemple #11
0
 /**
  * Returns an xml representation of the given document in the format that is
  * expected by Solr.
  *
  * @param Opus_Document $doc
  * @return DOMDocument
  */
 private function getSolrXmlDocument(Opus_Document $doc)
 {
     // Set up caching xml-model and get XML representation of document.
     $caching_xml_model = new Opus_Model_Xml();
     $caching_xml_model->setModel($doc);
     $caching_xml_model->excludeEmptyFields();
     $caching_xml_model->setStrategy(new Opus_Model_Xml_Version1());
     $cache = new Opus_Model_Xml_Cache($doc->hasPlugin('Opus_Document_Plugin_Index'));
     $caching_xml_model->setXmlCache($cache);
     $config = Zend_Registry::get('Zend_Config');
     $modelXml = $caching_xml_model->getDomDocument();
     // extract fulltext from file and append it to the generated xml.
     $this->attachFulltextToXml($modelXml, $doc->getFile(), $doc->getId());
     // Set up XSLT stylesheet
     $xslt = new DomDocument();
     if (isset($config->searchengine->solr->xsltfile)) {
         $xsltFilePath = $config->searchengine->solr->xsltfile;
         if (!file_exists($xsltFilePath)) {
             throw new Application_Exception('Solr XSLT file not found.');
         }
         $xslt->load($xsltFilePath);
     }
     // Set up XSLT processor
     $proc = new XSLTProcessor();
     $proc->importStyleSheet($xslt);
     $solrXmlDocument = new DOMDocument();
     $solrXmlDocument->preserveWhiteSpace = false;
     $solrXmlDocument->loadXML($proc->transformToXML($modelXml));
     if (isset($config->log->prepare->xml) && $config->log->prepare->xml) {
         $modelXml->formatOutput = true;
         $this->log->debug("input xml\n" . $modelXml->saveXML());
         $solrXmlDocument->formatOutput = true;
         $this->log->debug("transformed solr xml\n" . $solrXmlDocument->saveXML());
     }
     return $solrXmlDocument;
 }
} catch (Exception $e) {
    echo $e;
    exit;
}
$docFinder = new Opus_DocumentFinder();
$opusDocuments = new DOMDocument('1.0', 'utf-8');
$opusDocuments->formatOutput = true;
$export = $opusDocuments->createElement('export');
$docFinder = new Opus_DocumentFinder();
foreach ($docFinder->ids() as $id) {
    $doc = null;
    try {
        $doc = new Opus_Document($id);
    } catch (Opus_Model_NotFoundException $e) {
        // document with id $id does not exist
        continue;
    }
    $xmlModelOutput = new Opus_Model_Xml();
    $xmlModelOutput->setModel($doc);
    $xmlModelOutput->setStrategy(new Opus_Model_Xml_Version1());
    $xmlModelOutput->excludeEmptyFields();
    $domDocument = $xmlModelOutput->getDomDocument();
    $opusDocument = $domDocument->getElementsByTagName('Opus_Document')->item(0);
    $node = $opusDocuments->importNode($opusDocument, true);
    $export->appendChild($node);
}
$opusDocuments->appendChild($export);
$_exportFile = fopen($exportFile, 'w');
fputs($_exportFile, $opusDocuments->saveXML());
fclose($_exportFile);
exit;