/** * Imports metadata from an XML-Document * * @param DOMDocument $data XML-Document to be imported * @return array information about the document that has been imported */ public function import($document) { $this->collections = array(); $this->values = array(); $this->series = array(); $this->personSortOrder = array(); $this->document = $document; $this->oldId = $this->document->getElementsByTagName('IdentifierOpus3')->Item(0)->getAttribute('Value'); $this->skipEmptyFields(); $this->validatePersonSubmitterEmail(); $this->checkTitleMainAbstractForDuplicateLanguage(); $this->checkTitleAdditional(); $this->mapDocumentTypeAndLanguage(); $this->mapElementLanguage(); $this->mapClassifications(); $this->mapCollections(); $this->mapValues(); $this->getSortOrder(); $this->createNewEnrichmentKeys(); $imported = array(); $doc = null; try { $doc = Opus_Document::fromXml('<Opus>' . $this->completeXML->saveXML($this->document) . '</Opus>'); // ThesisGrantor and ThesisPublisher only for Thesis-Documents if (in_array($doc->getType(), $this->thesistypes)) { if (array_key_exists('grantor', $this->values)) { $dnbGrantor = new Opus_DnbInstitute($this->values['grantor']); $doc->setThesisGrantor($dnbGrantor); } if (array_key_exists('publisherUniversity', $this->values)) { $dnbPublisher = new Opus_DnbInstitute($this->values['publisherUniversity']); $doc->setThesisPublisher($dnbPublisher); } } if (array_key_exists('licence', $this->values)) { $doc->addLicence(new Opus_Licence($this->values['licence'])); } // TODO Opus4.x : Handle SortOrder via Opus_Document_Model foreach ($doc->getPersonAuthor() as $a) { $lastname = $a->getLastName(); $firstname = $a->getFirstName(); $sortorder = $this->personSortOrder[$lastname . "," . $firstname]; $a->setSortOrder($sortorder); } foreach ($this->collections as $c) { $coll = new Opus_Collection($c); $coll->setVisible(1); $coll->store(); $doc->addCollection($coll); } foreach ($this->series as $s) { $series = new Opus_Series($s[0]); $doc->addSeries($series)->setNumber($s[1]); } //$this->logger->log("(3):".$this->completeXML->saveXML($this->document), Zend_Log::DEBUG); $doc->store(); $imported['result'] = 'success'; $imported['oldid'] = $this->oldId; $imported['newid'] = $doc->getId(); if (array_key_exists('role', $this->values)) { $imported['roleid'] = $this->values['role']; //$this->logger->log("ROLE_ID'" . $this->values['roleid'] . "', Zend_Log::DEBUG); } } catch (Exception $e) { $imported['result'] = 'failure'; $imported['message'] = $e->getMessage(); if (!is_null($doc)) { $imported['entry'] = $doc->toXml()->saveXML(); } else { $imported['entry'] = $this->completeXML->saveXML($this->document); } $imported['oldid'] = $this->oldId; } unset($this->collections); unset($this->series); unset($this->values); unset($this->document); unset($this->oldId); return $imported; }
* * 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 Thoralf Klein <*****@*****.**> * @copyright Copyright (c) 2011, OPUS 4 development team * @license http://www.gnu.org/licenses/gpl.html General Public License * @version $Id$ */ // 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 $filename) { error_log("loading filename {$filename}..."); $content = file_get_contents($filename); $doc = Opus_Document::fromXml($content); $docId = $doc->store(); error_log("loading filename {$filename}... done. Document {$docId}."); }