module_index_act_cypress.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_product_images,
  46. shop_products,
  47. users
  48. ;`,
  49. )
  50. wrap.ResetCacheBlocks()
  51. wrap.Write(`OK`)
  52. })
  53. }