module_index_act_cypress.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package modules
  2. import (
  3. "os"
  4. "golang-fave/consts"
  5. "golang-fave/engine/sqlw"
  6. "golang-fave/engine/wrapper"
  7. )
  8. func (this *Modules) RegisterAction_IndexCypressReset() *Action {
  9. return this.newAction(AInfo{
  10. WantDB: false,
  11. Mount: "index-cypress-reset",
  12. }, func(wrap *wrapper.Wrapper) {
  13. if !consts.ParamDebug {
  14. wrap.Write(`Access denied`)
  15. return
  16. }
  17. db, err := sqlw.Open("mysql", "root:root@tcp(localhost:3306)/fave")
  18. if err != nil {
  19. wrap.Write(err.Error())
  20. return
  21. }
  22. defer db.Close()
  23. err = db.Ping()
  24. if err != nil {
  25. wrap.Write(err.Error())
  26. return
  27. }
  28. os.Remove(wrap.DConfig + string(os.PathSeparator) + "mysql.json")
  29. os.Remove(wrap.DConfig + string(os.PathSeparator) + "config.json")
  30. wrap.RemoveProductImageThumbnails("*", "*")
  31. _, _ = db.Exec(
  32. `DROP TABLE
  33. blog_cats,
  34. blog_cat_post_rel,
  35. blog_posts,
  36. pages,
  37. settings,
  38. shop_cat_product_rel,
  39. shop_cats,
  40. shop_currencies,
  41. shop_filter_product_values,
  42. shop_filters,
  43. shop_filters_values,
  44. shop_product_images,
  45. shop_products,
  46. users
  47. ;`,
  48. )
  49. wrap.ResetCacheBlocks()
  50. wrap.Write(`OK`)
  51. })
  52. }