noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 02/02: fix issue PHP8.1 ZIP::addGlob gives an


From: dwm
Subject: [Noalyss-commit] [noalyss] 02/02: fix issue PHP8.1 ZIP::addGlob gives an error , name too long
Date: Mon, 11 Mar 2024 17:13:31 -0400 (EDT)

sparkyx pushed a commit to branch stable
in repository noalyss.

commit 4bd53c202baa284b1901e03fa839698dad64c3fd
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Mon Mar 11 22:10:13 2024 +0100

    fix issue PHP8.1 ZIP::addGlob gives an error , name too long
---
 include/class/document_export.class.php   | 19 ++++++++++++++-----
 include/export/export_anc_receipt_pdf.php |  1 +
 include/lib/progress_bar.class.php        |  2 +-
 include/lib/zip_extended.class.php        | 24 ++++++++++++++++++++++++
 4 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/include/class/document_export.class.php 
b/include/class/document_export.class.php
index e1d0a20b5..af09edabb 100644
--- a/include/class/document_export.class.php
+++ b/include/class/document_export.class.php
@@ -87,11 +87,16 @@ class Document_Export
         $zip=new Zip_Extended();
         $res=$zip->open("{$this->store_pdf}/result.zip",ZipArchive::CREATE);
         if ($res !== true) {
-            error_log("DE89 cannot create zip file");
+            error_log("ERR-DE89 cannot create zip file");
             throw new Exception ( __FILE__.":".__LINE__."cannot recreate zip");
         }
         chdir($this->store_pdf);
-        $zip->addGlob("*.pdf");
+        // addGmpn
+        $res=$zip->add_file_pattern($this->store_pdf,"/.*.pdf/");
+        if ($res == 0) {
+            error_log("ERR-DE96 aucun fichier trouvé");
+            throw new Exception ( __FILE__.":".__LINE__."cannot recreate zip");
+        }
         $zip->close();
 
     }
@@ -130,7 +135,7 @@ class Document_Export
      */
     function send_zip()
     {
-        header('Content-Type: application/x-download');
+        header('Content-Type: application/zip');
         header('Content-Disposition: attachment; filename="result.zip"');
         header('Cache-Control: private, max-age=0, must-revalidate');
         header('Pragma: public');
@@ -167,7 +172,7 @@ class Document_Export
      */
     function     export_all($p_array, Progress_Bar 
$progress,$p_separate=1,$reconcilied_document=2)
     {
-        $this->progress=$this->progress;
+        $this->progress=$progress;
 
         $this->check_file();
         if (count($p_array)==0)
@@ -338,7 +343,11 @@ class Document_Export
         $cn->start();
         $cn->lo_export($file[0]['jr_pj'], $this->store_convert.'/'.$filename);
         $cn->commit();
-        
+
+        if ( ! file_exists( $this->store_convert.'/'.$filename) ){
+            throw new \Exception("ERR:DE342 Ne peut pas exporter le fichier 
$filename");
+        }
+
         // Convert this file into PDF 
         if ($file[0]['jr_pj_type']!='application/pdf')
         {
diff --git a/include/export/export_anc_receipt_pdf.php 
b/include/export/export_anc_receipt_pdf.php
index cf991be56..33414295b 100644
--- a/include/export/export_anc_receipt_pdf.php
+++ b/include/export/export_anc_receipt_pdf.php
@@ -25,6 +25,7 @@ if (!defined('ALLOWED'))
 
 // unlock session
 session_write_close();
+
 /**
  * export all the selected documents for Ana Accountancy in PDF
  */
diff --git a/include/lib/progress_bar.class.php 
b/include/lib/progress_bar.class.php
index f459fc1ea..1d1c2151f 100644
--- a/include/lib/progress_bar.class.php
+++ b/include/lib/progress_bar.class.php
@@ -58,7 +58,7 @@ class Progress_Bar
         $this->db=new Database();
         $this->task_id=$p_task_id;
         // Find value from db
-        $this->value = $this->db->exec_sql("select p_value from progress where 
p_id=$1",
+        $this->value = $this->db->get_value("select p_value from progress 
where p_id=$1",
                 [$p_task_id]);
         
         // if task doesn't exists, create it
diff --git a/include/lib/zip_extended.class.php 
b/include/lib/zip_extended.class.php
index f5d4d910c..8a9686bd7 100644
--- a/include/lib/zip_extended.class.php
+++ b/include/lib/zip_extended.class.php
@@ -75,4 +75,28 @@ class Zip_Extended extends ZipArchive
       }
   }
 
+    /**
+     * @brief  add file to the current file from a folder matching the pattern 
$p_pattern
+     * @param $p_folder string folder where are the file to add
+     * @param $p_pattern string pattern syntax preg_match
+     * @return int number of files added
+     */
+  function add_file_pattern( $p_folder,$p_pattern):int
+  {
+      if (!is_dir($p_folder)) {
+          throw new \Exception("ERR-ZE87");
+
+      }
+        $dir=opendir($p_folder);
+        if( $p_folder==false) throw new \Exception("ERR-ZE90");
+       $added=0;
+       while( ($entry=readdir($dir)) != false) {
+           if ( preg_match($p_pattern, $entry)) {
+               $this->addFile($p_folder . "/" . $entry,$entry);
+               $added++;
+           }
+       }
+       return $added;
+  }
+
 }
\ No newline at end of file



reply via email to

[Prev in Thread] Current Thread [Next in Thread]