Browse Source

Reset products images cache

Vova Tkach 5 years ago
parent
commit
afd7b681cf
1 changed files with 11 additions and 1 deletions
  1. 11 1
      modules/module_settings_act_thumbnails.go

+ 11 - 1
modules/module_settings_act_thumbnails.go

@@ -1,6 +1,8 @@
 package modules
 
 import (
+	"os"
+	"path/filepath"
 	"strconv"
 
 	"golang-fave/engine/wrapper"
@@ -94,7 +96,15 @@ func (this *Modules) RegisterAction_SettingsThumbnails() *Action {
 			return
 		}
 
-		// TODO: Reset images cache if changed
+		// Reset products images cache
+		pattern := wrap.DHtdocs + string(os.PathSeparator) + "products" + string(os.PathSeparator) + "images" + string(os.PathSeparator) + "*" + string(os.PathSeparator) + "thumb-*"
+		if files, err := filepath.Glob(pattern); err == nil {
+			for _, file := range files {
+				if err := os.Remove(file); err != nil {
+					wrap.LogError("Thumbnail file (%s) delete error: %s", file, err.Error())
+				}
+			}
+		}
 
 		// Reload current page
 		wrap.Write(`window.location.reload(false);`)