Merge pull request #873 from FHenry/develop

Add debug script and better ODT error management
This commit is contained in:
Laurent Destailleur
2013-04-24 09:02:20 -07:00
14 changed files with 131 additions and 42 deletions

View File

@@ -137,6 +137,8 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($conf->liste_limit +1, $offset);
dol_syslog('comm:list.php: sql='.$sql,LOG_DEBUG);
$result = $db->query($sql);
if ($result)
{

View File

@@ -245,10 +245,10 @@ abstract class CommonDocGenerator
$array_key.'_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement),
$array_key.'_payment_term_code'=>$object->cond_reglement_code,
$array_key.'_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):$object->cond_reglement),
$array_key.'_total_ht'=>price2num($object->total_ht2,2),
$array_key.'_total_vat'=>price2num($object->total_tva,2),
$array_key.'_total_ttc'=>price2num($object->total_ttc,2),
$array_key.'_total_discount_ht' => price2num($object->getTotalDiscount(),2),
$array_key.'_total_ht'=>price($object->total_ht2),
$array_key.'_total_vat'=>price($object->total_tva),
$array_key.'_total_ttc'=>price($object->total_ttc),
$array_key.'_total_discount_ht' => price($object->getTotalDiscount()),
$array_key.'_vatrate'=>vatrate($object->tva),
$array_key.'_note_private'=>$object->note,
$array_key.'_note'=>$object->note_public,
@@ -293,12 +293,12 @@ abstract class CommonDocGenerator
'line_product_label'=>$line->product_label,
'line_desc'=>$line->desc,
'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits),
'line_up'=>price2num($line->subprice, 2),
'line_up'=>price($line->subprice),
'line_qty'=>$line->qty,
'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''),
'line_price_ht'=>price2num($line->total_ht,2),
'line_price_ttc'=>price2num($line->total_ttc,2),
'line_price_vat'=>price2num($line->total_tva,2),
'line_price_ht'=>price($line->total_ht),
'line_price_ttc'=>price($line->total_ttc),
'line_price_vat'=>price($line->total_tva),
'line_date_start'=>$line->date_start,
'line_date_end'=>$line->date_end
);

View File

@@ -520,10 +520,20 @@ class doc_generic_order_odt extends ModelePDFCommandes
// Write new file
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
$odfHandler->exportAsAttachedPDF($file);
try {
$odfHandler->exportAsAttachedPDF($file);
}catch (Exception $e){
$this->error=$e->getMessage();
return -1;
}
}
else {
try {
$odfHandler->saveToDisk($file);
}catch (Exception $e){
$this->error=$e->getMessage();
return -1;
}
}
if (! empty($conf->global->MAIN_UMASK))

View File

@@ -498,10 +498,20 @@ class doc_generic_invoice_odt extends ModelePDFFactures
// Write new file
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
$odfHandler->exportAsAttachedPDF($file);
try {
$odfHandler->exportAsAttachedPDF($file);
}catch (Exception $e){
$this->error=$e->getMessage();
return -1;
}
}
else {
try {
$odfHandler->saveToDisk($file);
}catch (Exception $e){
$this->error=$e->getMessage();
return -1;
}
}
if (! empty($conf->global->MAIN_UMASK))

View File

@@ -974,10 +974,20 @@ class doc_generic_project_odt extends ModelePDFProjects
// Write new file
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
$odfHandler->exportAsAttachedPDF($file);
try {
$odfHandler->exportAsAttachedPDF($file);
}catch (Exception $e){
$this->error=$e->getMessage();
return -1;
}
}
else {
try {
$odfHandler->saveToDisk($file);
}catch (Exception $e){
$this->error=$e->getMessage();
return -1;
}
}
if (! empty($conf->global->MAIN_UMASK))

View File

@@ -483,10 +483,20 @@ class doc_generic_proposal_odt extends ModelePDFPropales
// Write new file
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
$odfHandler->exportAsAttachedPDF($file);
try {
$odfHandler->exportAsAttachedPDF($file);
}catch (Exception $e){
$this->error=$e->getMessage();
return -1;
}
}
else {
try {
$odfHandler->saveToDisk($file);
}catch (Exception $e){
$this->error=$e->getMessage();
return -1;
}
}
if (! empty($conf->global->MAIN_UMASK))

View File

@@ -325,10 +325,20 @@ class doc_generic_odt extends ModeleThirdPartyDoc
// Write new file
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
$odfHandler->exportAsAttachedPDF($file);
try {
$odfHandler->exportAsAttachedPDF($file);
}catch (Exception $e){
$this->error=$e->getMessage();
return -1;
}
}
else {
try {
$odfHandler->saveToDisk($file);
}catch (Exception $e){
$this->error=$e->getMessage();
return -1;
}
}
if (! empty($conf->global->MAIN_UMASK))

View File

@@ -452,14 +452,18 @@ IMG;
if( $name == "" ) $name = md5(uniqid());
//dol_syslog(get_class($this).'::exportAsAttachedPDF $name='.$name, LOG_DEBUG);
dol_syslog(get_class($this).'::exportAsAttachedPDF $name='.$name, LOG_DEBUG);
$this->saveToDisk($name);
$execmethod=(empty($conf->global->MAIN_EXEC_USE_POPEN)?1:2); // 1 or 2
$name=str_replace('.odt', '', $name);
$command = DOL_DOCUMENT_ROOT.'/includes/odtphp/odt2pdf.sh '.$name;
//dol_syslog('$execmethod='.$execmethod.' Run command='.$command);
//$dirname=dirname($name);
//$command = DOL_DOCUMENT_ROOT.'/includes/odtphp/odt2pdf.sh '.$name.' '.$dirname;
dol_syslog(get_class($this).'::exportAsAttachedPDF $execmethod='.$execmethod.' Run command='.$command,LOG_DEBUG);
if ($execmethod == 1)
{
exec($command, $output_arr, $retval);
@@ -470,7 +474,7 @@ IMG;
$handle = fopen($outputfile, 'w');
if ($handle)
{
dol_syslog("Run command ".$command);
dol_syslog(get_class($this)."Run command ".$command,LOG_DEBUG);
$handlein = popen($command, 'r');
while (!feof($handlein))
{
@@ -486,7 +490,7 @@ IMG;
if($retval == 0)
{
//dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG);
dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG);
if (headers_sent($filename, $linenum)) {
throw new OdfException("headers already sent ($filename at $linenum)");
}
@@ -498,12 +502,18 @@ IMG;
}
unlink("$name.odt");
} else {
//dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG);
//dol_syslog(get_class($this).'::exportAsAttachedPDF $output_arr='.var_export($output_arr,true), LOG_DEBUG);
echo "Error occured:<br>";
foreach($output_arr as $line)
echo $line."<br>";
//dol_syslog(get_class($this).'::exportAsAttachedPDF ERROR $line='.$line, LOG_DEBUG);
dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG);
dol_syslog(get_class($this).'::exportAsAttachedPDF $output_arr='.var_export($output_arr,true), LOG_DEBUG);
if ($retval==126) {
throw new OdfException('Permission execute convert script : ' . $command);
}
else {
foreach($output_arr as $line) {
$errors.= $line."<br>";
}
throw new OdfException('ODT to PDF convert fail : ' . $errors);
}
}
}

View File

@@ -1,22 +1,45 @@
#!/bin/bash
# @copyright GPL License 2010 - Vikas Mahajan - http://vikasmahajan.wordpress.com
# @copyright GPL License 2013 - Florian HEnry - florian.henry@open-concept.pro
#
#if [ -f "$1.odt" ]
# then
# soffice --invisible --convert-to pdf:writer_pdf_Export --outdir $2 "$1.odt"
# retcode=$?
# if [ $retcode -ne 0 ]
# then
# echo "Error while converting odt to pdf: $retcode";
# exit 1
# fi
# else
# echo "Error: Odt file does not exist"
# exit 1
#fi
if [ -f "$1.odt" ]
then
pgrep -U `id -u` soffice
if [ $? -ne 0 ]
then
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
sleep 2
fi
jodconverter "$1.odt" "$1.pdf"
if [ $? -ne 0 ]
then
echo "Error while converting odt to pdf"
exit 1
fi
sleep 1
else
echo "Error: Odt file does not exist"
exit 1
then
nbprocess=$(pgrep -c soffice)
if [ $nbprocess -ne 1 ]
then
soffice --invisible --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard --headless
retcode=$?
if [ $retcode -ne 0 ]
then
echo "Error running soffice: $retcode"
exit 1
fi
sleep 2
fi
jodconverter "$1.odt" "$1.pdf"
retcode=$?
if [ $retcode -ne 0 ]
then
echo "Error while converting odt to pdf: $retcode"
exit 1
fi
sleep 1
else
echo "Error: Odt file does not exist"
exit 1
fi

View File

@@ -354,6 +354,7 @@ ExtrafieldPhone=Telèfon
ExtrafieldPrice=Preu
ExtrafieldMail=Correu
ExtrafieldSelect=Llista de selecció
ExtrafieldSelectList=Llista de selecció de table
ExtrafieldSeparator=Separador
ExtrafieldCheckBox=Casella de verificació
ExtrafieldRadio=Botó de selecció excloent

View File

@@ -359,6 +359,7 @@ ExtrafieldPhone = Phone
ExtrafieldPrice = Price
ExtrafieldMail = Email
ExtrafieldSelect = Select list
ExtrafieldSelectList = Select from table
ExtrafieldSeparator=Separator
ExtrafieldCheckBox=Checkbox
ExtrafieldRadio=Radio button

View File

@@ -356,6 +356,7 @@ ExtrafieldPhone=Teléfono
ExtrafieldPrice=Precio
ExtrafieldMail=Correo
ExtrafieldSelect=Lista de selección
ExtrafieldSelectList=Llista de selección de table
ExtrafieldSeparator=Separador
ExtrafieldCheckBox=Casilla de verificación
ExtrafieldRadio=Botón de selección excluyente

View File

@@ -356,6 +356,7 @@ ExtrafieldPhone = Téléphone
ExtrafieldPrice = Prix
ExtrafieldMail = Email
ExtrafieldSelect = Liste de sélection
ExtrafieldSelectList = Liste issue d'une table
ExtrafieldSeparator = Séparateur de champ
ExtrafieldCheckBox=Case à cocher
ExtrafieldRadio=Case d'option

View File

@@ -169,7 +169,7 @@ else
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit + 1, $offset);
dol_syslog("sql=".$sql);
dol_syslog("product:list.php: sql=".$sql);
$resql = $db->query($sql);
if ($resql)
{