diff --git a/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php b/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php index 3330f491e70..623a6b9c8c6 100644 --- a/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php +++ b/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php @@ -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)) diff --git a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php index 8aa417c83c0..b65c6171430 100644 --- a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php +++ b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php @@ -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)) diff --git a/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php b/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php index 4c81babaa55..a2f8c5fd07a 100644 --- a/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php +++ b/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php @@ -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)) diff --git a/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php b/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php index d4e485562a4..6a7384ba4d9 100644 --- a/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php +++ b/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php @@ -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)) diff --git a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php index ca93ab1880e..fc609a3de61 100644 --- a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php +++ b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php @@ -314,10 +314,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)) diff --git a/htdocs/includes/odtphp/odf.php b/htdocs/includes/odtphp/odf.php index 03136a20b63..5326af0e116 100644 --- a/htdocs/includes/odtphp/odf.php +++ b/htdocs/includes/odtphp/odf.php @@ -452,14 +452,17 @@ 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; + //$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) { @@ -471,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)) { @@ -492,19 +495,25 @@ IMG; throw new OdfException("headers already sent ($filename at $linenum)"); } - /*if (!empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + if (!empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="'.$name.'.pdf"'); readfile("$name.pdf"); - }*/ + } 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:
"; - foreach($output_arr as $line) - echo $line."
"; - //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."
"; + } + throw new OdfException('ODT to PDF convert fail : ' . $errors); + } } } diff --git a/htdocs/includes/odtphp/odt2pdf.sh b/htdocs/includes/odtphp/odt2pdf.sh index 28f9ef32b22..9268b4a680f 100755 --- a/htdocs/includes/odtphp/odt2pdf.sh +++ b/htdocs/includes/odtphp/odt2pdf.sh @@ -1,18 +1,41 @@ #!/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 ] + nbprocess=$(pgrep -c soffice) + if [ $nbprocess -ne 1 ] then - soffice --invisible --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard --headless & + 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" - if [ $? -ne 0 ] + retcode=$? + if [ $retcode -ne 0 ] then - echo "Error while converting odt to pdf" + echo "Error while converting odt to pdf: $retcode" exit 1 fi sleep 1