Fix #6753 - serve Only
authorAlan Knowles <alan@roojs.com>
Mon, 17 May 2021 06:44:52 +0000 (14:44 +0800)
committerAlan Knowles <alan@roojs.com>
Mon, 17 May 2021 06:44:52 +0000 (14:44 +0800)
File/Convert.php
File/Convert/Solution.php
File/Convert/Solution/anydwgtopdf.php

index 227b1df..f7cd25d 100644 (file)
@@ -182,6 +182,15 @@ class File_Convert
         
         
     }
+    
+    function serveOnly($type=false, $filename =false, $delete_after = false)
+    {
+        $this->target = $this->fn;
+        $this->to = $this->mimetype;
+        $this->serve($type, $filename , $delete_after );
+    }
+    
+    
     /**
      * Serve the file to a browser so it can be downloaded, or viewed.
      *
@@ -192,7 +201,7 @@ class File_Convert
      */
     function serve($type=false, $filename =false, $delete_after = false) // may die **/
     {
-         if (empty($this->target)) {
+        if (empty($this->target)) {
             // broken image? for images...
             $cmd = isset($this->lastaction->cmd) ? $this->lastaction->cmd : "No Method";
             die("not available in this format was: {$this->mimetype}, request: {$this->to}<BR>
index 2d50102..d1a83f5 100644 (file)
@@ -80,7 +80,7 @@ class File_Convert_Solution
     
     function targetName($fn,$x,$y)
     {
-         return $fn .'.'. $this->ext;
+        return $fn .'.'. $this->ext;
     }
     
     
@@ -110,8 +110,9 @@ class File_Convert_Solution
     function deleteOnExitAdd($name)
     {
         if (self::$deleteOnExit === false) {
-            register_shutdown_function(array('Pman','deleteOnExit'));
             self::$deleteOnExit  = array();
+            register_shutdown_function(array('File_Convert_Solution','deleteOnExit'));
+            
         }
         self::$deleteOnExit[] = $name;
     }
@@ -129,9 +130,11 @@ class File_Convert_Solution
     
     }
    
-     static function deleteOnExit()
+    static function deleteOnExit()
     {
-        
+        if (count(func_get_args())) {
+            trigger_error("Call deleteOnExitAdd ?!?");
+        }
         foreach(self::$deleteOnExit as $fn) {
             if (file_exists($fn)) {
                 unlink($fn);
index a8d553c..ed9c4c6 100644 (file)
@@ -10,7 +10,8 @@
  * /usr/bin/xvfb-run --auto /usr/bin/wine dp.exe /InFile C:\\KNT1431-BO-TP-001.dwg /OutFile C:\\KNT1431-BO-TP-001.pdf /OutMode AlltoOne /Overwrite /OutLayout Paper /OutArea ZoomExtends
  
 */
-class File_Convert_Solution_anydwgtopdf {
+class File_Convert_Solution_anydwgtopdf extends File_Convert_Solution
+{
     
     static $rules = array(
         array(
@@ -28,7 +29,7 @@ class File_Convert_Solution_anydwgtopdf {
                 'drawing/dwg'
             ),
             'to' =>    array( //target
-               'application/pdf'
+                'application/pdf'
             )
         ),
       
@@ -39,6 +40,11 @@ class File_Convert_Solution_anydwgtopdf {
         //b) run the conversion
         //c) copy (link) out the files (and delete)
         
+        $tn = $this->targetName($fn, $x,$y);
+        if (file_exists($tn)) {
+            return $tn;
+        }
+        
         $wine = $this->which('wine');
         $xvfb = $this->which('xvfb-run');
         
@@ -51,23 +57,22 @@ class File_Convert_Solution_anydwgtopdf {
         $dir = '/var/www/.wine/drive_c/';
         $wfrom = $dir . $fromb;
         $wto = $dir . $tob;
-        $this->deleteOnExit($wfrom);
-        $this->deleteOnExit($wto);
+        $this->deleteOnExitAdd($wfrom);
+        $this->deleteOnExitAdd($wto);
+        link($fn,$wfrom);
         
-        link($wfrom, $fn);
         
         
         
-        
-        $cmd = "{$xvfb} --auto {$wine} /InFile C:\\{$fromb} /OutFile C:\\{$tob}" .
+        $cmd = "{$xvfb} --auto {$wine} \"/var/www/.wine/drive_c/Program Files (x86)/Any DWG to PDF Converter Pro/dp.exe\" /InFile C:\\\\{$fromb} /OutFile C:\\\\{$tob}" .
             "/OutMode AlltoOne /Overwrite /OutLayout Paper /OutArea ZoomExtends";
         $this->exec($cmd);
         if (!file_Exists($wto)) {
             // failed.
             return false;
         }
-        $tn = $this->targetName();
-        link($tn, $wto);
+        
+        link( $wto,$tn);
         
         clearstatcache();
         return file_exists($tn) ? $tn : false;