module_index_act_cypress.go 1.2 KB

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