- Added new config entry DOCSBOX_ENABLED to config/global.config-default.inc.php

- Added new library application/libraries/DocsboxLib.php to manage document conversion using docsbox
- Added new config file application/config/docsbox.php
- Integrated DocsboxLib into include/dokument_export.class.php
This commit is contained in:
Paolo
2021-10-14 11:34:27 +02:00
parent ab59c265d4
commit 2fb4be0e55
5 changed files with 372 additions and 148 deletions
-112
View File
@@ -1,112 +0,0 @@
<?php
/* Copyright (C) 2021 fhcomplete.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
*/
require_once(dirname(__FILE__).'/../vendor/nategood/httpful/bootstrap.php');
class Docsbox
{
/**
*
*/
public static function convert($inputFileName, $outputFileName)
{
try
{
$response = \Httpful\Request::post('http://docconverter.technikum-wien.at/api/v1/')
->attach(array('file' => $inputFileName))
->expectsJson()
->send();
var_dump($response);exit;
}
catch(\Httpful\Exception\ConnectionErrorException $cee)
{
// Error
}
catch (Exception $e)
{
// Error
}
if (is_object($response) && isset($response->id) && isset($response->status))
{
$status = null;
$result_url = null;
while ($status == null)
{
try
{
$response = \Httpful\Request::get('http://docconverter.technikum-wien.at/api/v1/'.$response->id)
->expectsJson()
->send();
var_dump($response);
}
catch(\Httpful\Exception\ConnectionErrorException $cee)
{
// Error
}
catch (Exception $e)
{
// Error
}
if (is_object($response) && isset($response->id) && isset($response->status))
{
if ($response->status == 'finished' && isset($response->result_url))
{
$status = $response->status;
$result_url = $response->result_url;
}
else
{
// Error
}
}
else
{
// Error
}
}
try
{
$response = \Httpful\Request::get($result_url)->send();
var_dump($response);
}
catch(\Httpful\Exception\ConnectionErrorException $cee)
{
// Error
}
catch (Exception $e)
{
// Error
}
var_dump($response);exit;
}
else
{
// Error
}
}
}
+65 -36
View File
@@ -37,6 +37,7 @@ class dokument_export
private $images=array();
private $sourceDir;
public $errormsg;
private $unoconv_version;
private $sign;
private $sign_user;
private $sign_profile;
@@ -49,6 +50,25 @@ class dokument_export
if(!isset($vorlage))
return;
if (defined('DOCSBOX_ENABLED') && DOCSBOX_ENABLED === true)
{
// Use docsbox!!
}
else
{
exec('unoconv --version',$ret_arr);
if(isset($ret_arr[0]))
{
$hlp = explode(' ',$ret_arr[0]);
if(isset($hlp[1]))
$this->unoconv_version = $hlp[1];
else
die('Could not get Unoconv Version');
}
else
die('Unoconv not found');
}
//Vorlage aus der Datenbank holen
$this->vorlage = new vorlage();
if(!$this->vorlage->getAktuelleVorlage($oe_kurzbz, $vorlage, $version))
@@ -263,32 +283,36 @@ class dokument_export
{
case 'pdf':
case 'doc':
$ret = 0;
$this->temp_filename = $this->temp_folder . '/out.' . $this->outputformat;
// Unoconv Version 0.6 hat eine Bug wodurch die Berechtigungen des PDF/Doc nicht korrekt gesetzt
// werden. Deshalb wird dies hier speziell behandelt.
// Die 2. Variante hat den Vorteil dass hier eine bessere Fehlerbehandlung moeglich ist
//if($this->unoconv_version=='0.6')
// $command = 'unoconv -e IsSkipEmptyPages=false -f ' . $this->outputformat . ' %2$s > %1$s';
//else
// $command = 'unoconv -e IsSkipEmptyPages=false -f ' . $this->outputformat . ' --output %s %s 2>&1';
// If it is set to use docsbox
if (defined('DOCSBOX_ENABLED') && DOCSBOX_ENABLED === true)
{
require_once(dirname(__FILE__).'/../application/libraries/DocsboxLib.php');
//$command = sprintf($command, $this->temp_filename, $tempname_zip);
$ret = DocsboxLib::convert($tempname_zip, $this->temp_filename);
}
else // otherwise use unoconv
{
// Unoconv Version 0.6 hat eine Bug wodurch die Berechtigungen des PDF/Doc nicht korrekt gesetzt
// werden. Deshalb wird dies hier speziell behandelt.
// Die 2. Variante hat den Vorteil dass hier eine bessere Fehlerbehandlung moeglich ist
if ($this->unoconv_version == '0.6')
$command = 'unoconv -e IsSkipEmptyPages=false -f ' . $this->outputformat . ' %2$s > %1$s';
else
$command = 'unoconv -e IsSkipEmptyPages=false -f ' . $this->outputformat . ' --output %s %s 2>&1';
//exec($command, $out, $ret);
$command = sprintf($command, $this->temp_filename, $tempname_zip);
require_once('Docsbox.php');
exec($command, $out, $ret);
}
var_dump($tempname_zip);
var_dump($this->temp_filename);
Docsbox::convert($tempname_zip, $this->temp_filename);
//if($ret!=0)
//{
// $this->errormsg = 'Dokumentenkonvertierung ist derzeit nicht möglich. Bitte versuchen Sie es in einer Minute erneut oder kontaktieren Sie einen Administrator';
// return false;
//}
if ($ret != 0)
{
$this->errormsg = 'Dokumentenkonvertierung ist derzeit nicht möglich. Bitte versuchen Sie es in einer Minute erneut oder kontaktieren Sie einen Administrator';
return false;
}
break;
case 'odt':
default:
@@ -449,26 +473,31 @@ class dokument_export
*/
public function convert($inFile, $outFile, $format = "pdf")
{
//require_once('Docsbox.php');
$ret = 0;
//var_dump($inFile);
//var_dump($outFile);
// If it is set to use DOCSBOX
if (defined('DOCSBOX_ENABLED') && DOCSBOX_ENABLED === true)
{
require_once(dirname(__FILE__).'/../application/libraries/DocsboxLib.php');
//Docsbox::convert();
$ret = DocsboxLib::convert($inFile, $outFile);
}
else // fallback to unoconv
{
if($this->unoconv_version=='0.6')
$command = 'unoconv -f %1$s %3$s > %2$s';
else
$command = 'unoconv -f %s --output %s %s 2>&1';
$command = sprintf($command, $format, $outFile, $inFile);
//if($this->unoconv_version=='0.6')
// $command = 'unoconv -f %1$s %3$s > %2$s';
//else
// $command = 'unoconv -f %s --output %s %s 2>&1';
//$command = sprintf($command, $format, $outFile, $inFile);
exec($command, $out, $ret);
}
//exec($command, $out, $ret);
//if($ret!=0)
//{
// $this->errormsg = 'Dokumentenkonvertierung ist derzeit nicht möglich. Bitte versuchen Sie es in einer Minute erneut oder kontaktieren Sie einen Administrator';
// return false;
//}
if ($ret != 0)
{
$this->errormsg = 'Dokumentenkonvertierung ist derzeit nicht möglich. Bitte versuchen Sie es in einer Minute erneut oder kontaktieren Sie einen Administrator';
return false;
}
return true;
}