module_index_act_cypress.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_cat_post_rel,
  34. blog_cats,
  35. blog_posts,
  36. notify_mail,
  37. pages,
  38. settings,
  39. shop_cat_product_rel,
  40. shop_cats,
  41. shop_currencies,
  42. shop_filter_product_values,
  43. shop_filters,
  44. shop_filters_values,
  45. shop_order_products,
  46. shop_orders,
  47. shop_product_images,
  48. shop_products,
  49. users
  50. ;`,
  51. )
  52. wrap.ResetCacheBlocks()
  53. wrap.Write(`OK`)
  54. })
  55. }