mirror of
https://github.com/Yetangitu/owncloud-apps.git
synced 2025-10-02 14:49:17 +02:00
files_opds:
- throw exceptions from epub constructor, catch them in metadata gatherer to avoid problems with bad files - change datetime format in metadata to avoid problems with empty database on some installations
This commit is contained in:
parent
ede5449eec
commit
33348f0af7
2 changed files with 26 additions and 25 deletions
|
@ -37,15 +37,12 @@ class Epub {
|
||||||
$this->file = $file;
|
$this->file = $file;
|
||||||
$zip = new \ZipArchive();
|
$zip = new \ZipArchive();
|
||||||
if(!($zip->open($this->file))){
|
if(!($zip->open($this->file))){
|
||||||
\OC_Log::write('epub', "Failed to read epub file", \OC_Log::ERROR);
|
throw new \Exception("Failed to read epub file");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// read container data
|
// read container data
|
||||||
$data = $zip->getFromName('META-INF/container.xml');
|
if(!($data = $zip->getFromName('META-INF/container.xml'))) {
|
||||||
if($data == false){
|
throw new \Exception("Failed to access epub container data");
|
||||||
\OC_Log::write('epub', "Failed to access epub container data", \OC_Log::ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$xml = new DOMDocument();
|
$xml = new DOMDocument();
|
||||||
|
@ -56,17 +53,17 @@ class Epub {
|
||||||
$this->meta = $nodes->item(0)->attr('full-path');
|
$this->meta = $nodes->item(0)->attr('full-path');
|
||||||
|
|
||||||
// load metadata
|
// load metadata
|
||||||
$data = $zip->getFromName($this->meta);
|
if(!($data = $zip->getFromName($this->meta))) {
|
||||||
if(!$data){
|
throw new \Exception("Failed to access epub metadata");
|
||||||
\OC_Log::write('epub', 'Failed to access epub metadata', \OC_Log::ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->xml = new \DOMDocument();
|
$this->xml = new \DOMDocument();
|
||||||
$this->xml->registerNodeClass('DOMElement','\OCA\Files_Opds\EPubDOMElement');
|
$this->xml->registerNodeClass('DOMElement','\OCA\Files_Opds\EPubDOMElement');
|
||||||
$this->xml->loadXML($data);
|
$this->xml->loadXML($data);
|
||||||
$this->xml->formatOutput = true;
|
$this->xml->formatOutput = true;
|
||||||
$this->xpath = new EPubDOMXPath($this->xml);
|
if(!($this->xpath = new EPubDOMXPath($this->xml))) {
|
||||||
|
throw new \Exception("Failed to instantiate xpath");
|
||||||
|
}
|
||||||
|
|
||||||
$zip->close();
|
$zip->close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ class Meta
|
||||||
* scanned once, even if they don't contain valid metadate.
|
* scanned once, even if they don't contain valid metadate.
|
||||||
*/
|
*/
|
||||||
$meta['id'] = $id;
|
$meta['id'] = $id;
|
||||||
$meta['updated'] = date("Y-m-d\TH:i:sP");
|
$meta['updated'] = date("Y-m-d H:i:s");
|
||||||
$meta['date'] = '';
|
$meta['date'] = '';
|
||||||
$meta['author'] = '';
|
$meta['author'] = '';
|
||||||
$meta['title'] = '';
|
$meta['title'] = '';
|
||||||
|
@ -189,6 +189,7 @@ class Meta
|
||||||
*/
|
*/
|
||||||
public static function epub($path,&$meta) {
|
public static function epub($path,&$meta) {
|
||||||
$success = false;
|
$success = false;
|
||||||
|
try {
|
||||||
$epub = new Epub($path);
|
$epub = new Epub($path);
|
||||||
/* first try ISBN */
|
/* first try ISBN */
|
||||||
if(!(($isbn = $epub->ISBN()) && (Isbn::get($isbn, $meta)))) {
|
if(!(($isbn = $epub->ISBN()) && (Isbn::get($isbn, $meta)))) {
|
||||||
|
@ -203,6 +204,9 @@ class Meta
|
||||||
$meta['isbn'] = $epub->ISBN();
|
$meta['isbn'] = $epub->ISBN();
|
||||||
$meta['subjects'] = json_encode($epub->Subjects());
|
$meta['subjects'] = json_encode($epub->Subjects());
|
||||||
}
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
\OC_Log::write(get_class(), $e->getMessage(), \OC_LOG::ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue