[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 173/173: if a document cannot be generate, a
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 173/173: if a document cannot be generate, a error message is displaid and the whole operation is not cancelled |
Date: |
Mon, 22 Mar 2021 12:59:27 -0400 (EDT) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit a02ebdaa6f1ba0229f5923851ace23712112a109
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Mon Mar 22 17:51:34 2021 +0100
if a document cannot be generate, a error message is displaid
and the whole operation is not cancelled
---
include/class/document.class.php | 164 ++++++++++++++++++++-------------------
include/lib/ac_common.php | 3 +-
2 files changed, 87 insertions(+), 80 deletions(-)
diff --git a/include/class/document.class.php b/include/class/document.class.php
index 2c7a8dc..36854cf 100644
--- a/include/class/document.class.php
+++ b/include/class/document.class.php
@@ -109,97 +109,103 @@ class Document
function generate($p_array, $p_filename="")
{
- // create a temp directory in /tmp to unpack file and to parse it
- $dirname=tempnam($_ENV['TMP'], 'doc_');
-
-
- unlink($dirname);
- mkdir($dirname);
- // Retrieve the lob and save it into $dirname
- $this->db->start();
- $dm_info="select md_name,md_type,md_lob,md_filename,md_mimetype
- from document_modele where md_id=$1";
- $Res=$this->db->exec_sql($dm_info, [$this->md_id]);
-
- $row=Database::fetch_array($Res, 0);
- $this->d_lob=$row['md_lob'];
- $this->d_filename=$row['md_filename'];
- $this->d_mimetype=$row['md_mimetype'];
- $this->d_name=$row['md_name'];
-
-
- chdir($dirname);
- $filename=$row['md_filename'];
- $exp=$this->db->lo_export($row['md_lob'],
$dirname.DIRECTORY_SEPARATOR.$filename);
- if ($exp===false)
- {
- record_log(sprintf('D1 , export failed %s', $filename));
- throw new Exception(sprintf(_("Export a échoué pour %s",
$filename)));
- }
+ try {
+ // create a temp directory in /tmp to unpack file and to parse it
+ $dirname=tempnam($_ENV['TMP'], 'doc_');
+
+
+ unlink($dirname);
+ mkdir($dirname);
+ // Retrieve the lob and save it into $dirname
+ $this->db->start();
+ $dm_info="select md_name,md_type,md_lob,md_filename,md_mimetype
+ from document_modele where md_id=$1";
+ $Res=$this->db->exec_sql($dm_info, [$this->md_id]);
+
+ $row=Database::fetch_array($Res, 0);
+ $this->d_lob=$row['md_lob'];
+ $this->d_filename=$row['md_filename'];
+ $this->d_mimetype=$row['md_mimetype'];
+ $this->d_name=$row['md_name'];
+
+
+ chdir($dirname);
+ $filename=$row['md_filename'];
+ $exp=$this->db->lo_export($row['md_lob'],
$dirname.DIRECTORY_SEPARATOR.$filename);
+ if ($exp===false)
+ {
+ record_log(sprintf('DOCUMENT.GENERATE.D1 , export failed %s
%s',$dirname, $filename));
+ throw new Exception(sprintf(_("Export a échoué pour %s"),
$filename));
+ }
- $type="n";
- // if the doc is a OOo, we need to unzip it first
- // and the name of the file to change is always content.xml
- if (strpos($row['md_mimetype'], 'vnd.oasis')!=0)
- {
- ob_start();
- $zip=new Zip_Extended;
- if ($zip->open($filename)===TRUE)
+ $type="n";
+ // if the doc is a OOo, we need to unzip it first
+ // and the name of the file to change is always content.xml
+ if (strpos($row['md_mimetype'], 'vnd.oasis')!=0)
{
- $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
- $zip->close();
+ ob_start();
+ $zip=new Zip_Extended;
+ if ($zip->open($filename)===TRUE)
+ {
+ $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
+ $zip->close();
+ }
+ else
+ {
+ record_log(sprintf('DOCUMENT.GENERATE.D2 unzip failed
%s', $filename));
+ throw new Exception(sprintf(_("Décompression a échoué %s",
$filename)));
+ }
+
+ // Remove the file we do not need anymore
+ unlink($filename);
+ ob_end_clean();
+ $file_to_parse="content.xml";
+ $type="OOo";
}
else
{
- record_log(sprintf('D2 unzip failed %s', $filename));
- throw new Exception(sprintf(_("Décompression a échoué %s",
$filename)));
+ $file_to_parse=$filename;
}
+ // affect a number
+
$this->d_number=$this->db->get_next_seq("seq_doc_type_".$row['md_type']);
- // Remove the file we do not need anymore
- unlink($filename);
- ob_end_clean();
- $file_to_parse="content.xml";
- $type="OOo";
- }
- else
- {
- $file_to_parse=$filename;
- }
- // affect a number
-
$this->d_number=$this->db->get_next_seq("seq_doc_type_".$row['md_type']);
+ // parse the document - return the doc number ?
+ $this->parseDocument($dirname, $file_to_parse, $type, $p_array);
- // parse the document - return the doc number ?
- $this->parseDocument($dirname, $file_to_parse, $type, $p_array);
-
- $this->db->commit();
- // if the doc is a OOo, we need to re-zip it
- if (strpos($row['md_mimetype'], 'vnd.oasis')!=0)
- {
- ob_start();
- $zip=new Zip_Extended;
- $res=$zip->open($filename, ZipArchive::CREATE);
- if ($res!==TRUE)
+ $this->db->commit();
+ // if the doc is a OOo, we need to re-zip it
+ if (strpos($row['md_mimetype'], 'vnd.oasis')!=0)
{
- record_log(sprintf('D3 zip failed %s', $filename));
- throw new Exception(_('Echec compression'));
- }
- $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR);
- $zip->close();
+ ob_start();
+ $zip=new Zip_Extended;
+ $res=$zip->open($filename, ZipArchive::CREATE);
+ if ($res!==TRUE)
+ {
+ record_log(sprintf('DOCUMENT.GENERATE.D3 zip failed %s',
$filename));
+ throw new Exception(_('Echec compression'));
+ }
+ $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR);
+ $zip->close();
- ob_end_clean();
+ ob_end_clean();
- $file_to_parse=$filename;
- }
- if ($p_filename!="")
- {
- $this->d_filename=$this->compute_filename($p_filename,
$this->d_filename);
+ $file_to_parse=$filename;
+ }
+ if ($p_filename!="")
+ {
+ $this->d_filename=$this->compute_filename($p_filename,
$this->d_filename);
+ }
+ $this->saveGenerated($dirname.DIRECTORY_SEPARATOR.$file_to_parse);
+ // Invoice
+ $href=http_build_query(array('gDossier'=>Dossier::id(),
"d_id"=>$this->d_id, 'act'=>'RAW:document'));
+ $ret='<A class="mtitle"
HREF="export.php?'.$href.'">'._('Document').'</A>';
+
+ return $ret;
+ } catch (Exception $e) {
+ record_log($e->getMessage());
+ record_log($e->getTraceAsString());
+ return span(_("Génération du document a échoué"),'class="notice"');
}
- $this->saveGenerated($dirname.DIRECTORY_SEPARATOR.$file_to_parse);
- // Invoice
- $href=http_build_query(array('gDossier'=>Dossier::id(),
"d_id"=>$this->d_id, 'act'=>'RAW:document'));
- $ret='<A class="mtitle"
HREF="export.php?'.$href.'">'._('Document').'</A>';
-
- return $ret;
}
/* ! parseDocument
diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php
index 8f96a81..dde53df 100644
--- a/include/lib/ac_common.php
+++ b/include/lib/ac_common.php
@@ -1397,7 +1397,8 @@ function is_msie()
function record_log($p_message)
{
error_log("noalyss".print_r($p_message,true),0);
- error_log("noalyss GET [".json_encode($_GET)."] POST
[".json_encode($_POST)."]",0);
+ error_log("noalyss GET [".json_encode($_GET)."]");
+ error_log("_POST [".json_encode($_POST)."]",0);
}
if(!function_exists('tracedebug')) {
function tracedebug($file,$var, $label = NULL) {
- [Noalyss-commit] [noalyss] 157/173: Merge branch 'dev-8-bug-saldo-not-checked', (continued)
- [Noalyss-commit] [noalyss] 157/173: Merge branch 'dev-8-bug-saldo-not-checked', Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 161/173: Move CSS and start to integrate BootStrap, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 163/173: Move CSS and start to integrate BootStrap Add fonts, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 165/173: Currency : adapt test, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 166/173: BootStrap : set up + move CSS and font to their own folders, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 167/173: Task 0001912: Developpement DEBUG new system with level, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 168/173: Task #1911: FOLLOW : télécharger toutes les documents en une fois, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 153/173: Improve scenario test, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 158/173: Merge branch 'dev8001', Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 172/173: Erreur : fiche_attr , first param is a DatabaseCore object, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 173/173: if a document cannot be generate, a error message is displaid and the whole operation is not cancelled,
Dany De Bontridder <=