Merge branch 'seeddms-5.1.x' into seeddms-6.0.x

This commit is contained in:
Uwe Steinmann 2023-01-19 15:02:19 +01:00
commit f6ae2c3868
2 changed files with 39 additions and 7 deletions

View File

@ -33,11 +33,18 @@ 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) {
$service->setConversionMgr($this);
$this->services[$service->from][$service->to][] = $service; $this->services[$service->from][$service->to][] = $service;
return $service; return $service;
} }
@ -53,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
@ -86,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;
} }

View File

@ -36,6 +36,11 @@ abstract class SeedDMS_ConversionServiceBase {
*/ */
protected $logger; protected $logger;
/**
* conversion manager
*/
protected $conversionmgr;
/** /**
* @var $success set to false if conversion failed * @var $success set to false if conversion failed
*/ */
@ -45,12 +50,22 @@ abstract class SeedDMS_ConversionServiceBase {
$this->from = null; $this->from = null;
$this->to = null; $this->to = null;
$this->success = true; $this->success = true;
$this->logger = null;
$this->conversionmgr = null;
} }
public function setLogger($logger) { public function setLogger($logger) {
$this->logger = $logger; $this->logger = $logger;
} }
public function setConversionMgr($conversionmgr) {
$this->conversionmgr = $conversionmgr;
}
public function getConversionMgr() {
return $this->conversionmgr;
}
public function getInfo() { public function getInfo() {
return 'Conversion service'; return 'Conversion service';
} }