add wasSuccessful() to check if last conversion was successful

This commit is contained in:
Uwe Steinmann 2023-01-19 15:01:43 +01:00
parent 872c66158b
commit b197639dd2

View File

@ -33,8 +33,14 @@ class SeedDMS_ConversionMgr {
*/ */
public $services; public $services;
/**
* @var $success set to false if conversion failed
*/
protected $success;
public function __construct() { public function __construct() {
$this->services = array(); $this->services = array();
$this->success = true;
} }
public function addService($service) { public function addService($service) {
@ -54,22 +60,30 @@ class SeedDMS_ConversionMgr {
* Return the service that would be tried first for converting * Return the service that would be tried first for converting
* the document. * the document.
* *
* The conversion may not use this service but choose a different * The conversion manager may not use this service but choose a different
* one when it fails. * one when it fails.
*/ */
public function getService($from, $to) { public function getService($from, $to) { /* {{{ */
if(!empty($this->services[$from][$to])) if(!empty($this->services[$from][$to]))
return end($this->services[$from][$to]); return end($this->services[$from][$to]);
else else
return null; return null;
} } /* }}} */
public function getServices() { public function getServices() { /* {{{ */
return $this->services; return $this->services;
} } /* }}} */
public function wasSuccessful() { /* {{{ */
return $this->success;
} /* }}} */
/** /**
* Convert a file * Convert a file from one format into another format
*
* This method will try each conversion service until a service
* fails or was successful. If a service succeeds it must not
* return false, null, '' or 0
* *
* @param string $file name of file to convert * @param string $file name of file to convert
* @param string $from mimetype of input file * @param string $from mimetype of input file
@ -87,8 +101,10 @@ class SeedDMS_ConversionMgr {
for(end($services); key($services)!==null; prev($services)) { for(end($services); key($services)!==null; prev($services)) {
$service = current($services); $service = current($services);
$text = $service->convert($file, $target, $params); $text = $service->convert($file, $target, $params);
if(!$service->wasSuccessful()) if(!$service->wasSuccessful()) {
$this->success = false;
return false; return false;
}
if($text) if($text)
return $text; return $text;
} }