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;
/**
* @var $success set to false if conversion failed
*/
protected $success;
public function __construct() {
$this->services = array();
$this->success = true;
}
public function addService($service) {
@ -54,22 +60,30 @@ class SeedDMS_ConversionMgr {
* Return the service that would be tried first for converting
* 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.
*/
public function getService($from, $to) {
public function getService($from, $to) { /* {{{ */
if(!empty($this->services[$from][$to]))
return end($this->services[$from][$to]);
else
return null;
}
} /* }}} */
public function getServices() {
public function getServices() { /* {{{ */
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 $from mimetype of input file
@ -87,8 +101,10 @@ class SeedDMS_ConversionMgr {
for(end($services); key($services)!==null; prev($services)) {
$service = current($services);
$text = $service->convert($file, $target, $params);
if(!$service->wasSuccessful())
if(!$service->wasSuccessful()) {
$this->success = false;
return false;
}
if($text)
return $text;
}