/** * Loads an old Opus ID * * @param Opus_Document $object Opus-Document for that the files should be registered * @return void */ public function loadSignatureFiles($id) { $object = new Opus_Document($id); $this->_tmpPath = null; $opusId = $object->getIdentifierOpus3()->getValue(); // Search the ID-directory in signaturefiles tree $this->searchDir($this->_path, $opusId); foreach ($object->getFile() as $file) { $sigfiles = $this->getFiles($this->_tmpPath, $file->getPathName()); if (count($sigfiles) > 0) { $key = 0; foreach ($sigfiles as $signatureFile) { $registered = false; $signature = implode("", file($signatureFile)); // check if this signature has been registered $hashes = $file->getHashValue(); foreach ($hashes as $hash) { if (substr($hash->getType(), 0, 4) === 'gpg-') { $key++; if ($signature === $hash->getValue()) { $registered = true; } } } // if not, add the signature if ($registered === false) { $hash = new Opus_HashValues(); $hash->setType('gpg-' . $key); $hash->setValue($signature); $file->addHashValue($hash); } unset($signatureFile); } } unset($file); } // Store signature(s) directly $object->store(); }
/** * Create hash value model objects from original file. * * TODO throws Exception in case hash computation is not possible * (e.g., if referenced file is missing in file system) * * @return void */ private function _createHashValues() { $hashtypes = array('md5', 'sha512'); $hashs = array(); foreach ($hashtypes as $type) { $hash = new Opus_HashValues(); $hash->setType($type); $hash_string = $this->getRealHash($type); $hash->setValue($hash_string); $hashs[] = $hash; } $this->setHashValue($hashs); }