Browse Source

Reset action for cypress

Vova Tkach 6 years ago
parent
commit
d36dc1a1bd
1 changed files with 48 additions and 0 deletions
  1. 48 0
      modules/module_index_act_cypress.go

+ 48 - 0
modules/module_index_act_cypress.go

@@ -0,0 +1,48 @@
+package modules
+
+import (
+	"os"
+
+	"golang-fave/consts"
+	"golang-fave/engine/wrapper"
+)
+
+func (this *Modules) RegisterAction_IndexCypressReset() *Action {
+	return this.newAction(AInfo{
+		WantDB: true,
+		Mount:  "index-cypress-reset",
+	}, func(wrap *wrapper.Wrapper) {
+		if !consts.ParamDebug {
+			wrap.Write(`Access denied`)
+			return
+		}
+
+		_, err := wrap.DB.Query(
+			`DROP TABLE
+				blog_cats,
+				blog_cat_post_rel,
+				blog_posts,
+				pages,
+				users
+			;`,
+		)
+		if err != nil {
+			wrap.Write(err.Error())
+			return
+		}
+
+		err = os.Remove(wrap.DConfig + string(os.PathSeparator) + ".installed")
+		if err != nil {
+			wrap.Write(err.Error())
+			return
+		}
+
+		err = os.Remove(wrap.DConfig + string(os.PathSeparator) + "mysql.json")
+		if err != nil {
+			wrap.Write(err.Error())
+			return
+		}
+
+		wrap.Write(`OK`)
+	})
+}