sync
authorjohn <john@roojs.com>
Wed, 15 Aug 2018 10:45:05 +0000 (18:45 +0800)
committerjohn <john@roojs.com>
Wed, 15 Aug 2018 10:45:05 +0000 (18:45 +0800)
Asset.php
UpdateDatabase.php

index 2b80a92..c090c10 100644 (file)
--- a/Asset.php
+++ b/Asset.php
@@ -36,6 +36,13 @@ class Pman_Core_Asset extends Pman {
     
     function get($s='', $opts = Array())
     {
+        if(
+            !empty($_REQUEST['_clear_cache']) &&
+            !empty($_REQUEST['_clear_module'])
+        ) {
+            $this->clearCompiledFilesCache($_REQUEST['_clear_module']);
+        }
+        
         
         $this->sessionState(0);
         
@@ -115,11 +122,12 @@ class Pman_Core_Asset extends Pman {
         exit;
         
     }
+    
     function post($s='') {
         die('invalid');
     }
      
-    static function getCompileDir($type)
+    static function getCompileDir($type, $module = '', $is_mkdir = true)
     {
         $ff = HTML_FlexyFramework::get();
         
@@ -127,12 +135,14 @@ class Pman_Core_Asset extends Pman {
         
         $compile_dir = session_save_path() . "/";
         
+        $module = (empty($module)) ? $ff->project : $module;
+        
         switch($type) {
             case 'js':
             case 'css':
                 $compile_dir .= implode("-", array(
                     $ui['name'],
-                    $ff->project,
+                    $module,
                     $ff->version,
                     "{$type}compile"
                 ));
@@ -146,6 +156,10 @@ class Pman_Core_Asset extends Pman {
             return $compile_dir;
         }
         
+        if(!$is_mkdir) {
+            return false;
+        }
+        
         if(mkdir($compile_dir, 0700, true)) {
             return $compile_dir;
         }
@@ -153,10 +167,18 @@ class Pman_Core_Asset extends Pman {
         return false;
     }
     
-    function clearCompiledFilesCache()
+    function clearCompiledFilesCache($module)
     {
-        // using getCompileDir..
+        $compile_dir = $this->getCompileDir('js', $module, false);
+        
+        if(empty($compile_dir)) {
+            $this->jok('EMPTY');
+        }
+        
+        foreach(glob($compile_dir.'/*.*') as $v){
+            unlink($v);
+        }
         
-        return;
+        $this->jok('DONE');
     }
 }
index 4d142aa..5060eee 100644 (file)
@@ -215,6 +215,8 @@ class Pman_Core_UpdateDatabase extends Pman
         $this->runExtensions();
         
         $this->clearApacheDataobjectsCache();
+        
+        $this->clearCompileFileCache();
     }
     
     function output() {
@@ -1240,6 +1242,35 @@ class Pman_Core_UpdateDatabase extends Pman
         return $response;
     }
     
-    
+    function clearCompileFileCache()
+    {
+        $a = new Pman();
+        $mods = $a->modulesList();
+        
+        $url = "http://localhost{$this->local_base_url}/Core/Asset";
+        
+        foreach ($mods as $mod) {
+            
+            $response = $this->curl($url, array(
+                '_clear_cache' => 1,
+                '_clear_module' => $mod
+            ));
+            
+            $json = json_decode($response, true);
+            
+            if(
+                empty($json['data']) ||
+                (
+                    $json['data'] != 'DONE' &&
+                    $json['data'] != 'EMPTY'
+                )
+            ){
+                echo $response. "\n";
+                echo "CURL clear compiled file failed\n";
+                exit;
+            }
+        }
+        
+    }
     
 }