module_index_act_cypress.go 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package modules
  2. import (
  3. "os"
  4. "golang-fave/engine/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. Mount: "index-cypress-reset",
  11. }, func(wrap *wrapper.Wrapper) {
  12. if !consts.ParamDebug {
  13. wrap.Write(`Access denied`)
  14. return
  15. }
  16. db, err := sqlw.Open("mysql", "root:root@tcp(localhost:3306)/fave")
  17. if err != nil {
  18. wrap.Write(err.Error())
  19. return
  20. }
  21. defer db.Close()
  22. err = db.Ping(wrap.R.Context())
  23. if err != nil {
  24. wrap.Write(err.Error())
  25. return
  26. }
  27. os.Remove(wrap.DConfig + string(os.PathSeparator) + "mysql.json")
  28. os.Remove(wrap.DConfig + string(os.PathSeparator) + "config.json")
  29. wrap.RemoveProductImageThumbnails("*", "*")
  30. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_blog_cat_post_rel DROP FOREIGN KEY FK_blog_cat_post_rel_post_id;`)
  31. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_blog_cat_post_rel DROP FOREIGN KEY FK_blog_cat_post_rel_category_id;`)
  32. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_blog_cats DROP FOREIGN KEY FK_blog_cats_user;`)
  33. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_blog_posts DROP FOREIGN KEY FK_blog_posts_user;`)
  34. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_blog_posts DROP FOREIGN KEY FK_blog_posts_category;`)
  35. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_pages DROP FOREIGN KEY FK_pages_user;`)
  36. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_shop_cat_product_rel DROP FOREIGN KEY FK_shop_cat_product_rel_product_id;`)
  37. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_shop_cat_product_rel DROP FOREIGN KEY FK_shop_cat_product_rel_category_id;`)
  38. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_shop_cats DROP FOREIGN KEY FK_shop_cats_user;`)
  39. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_shop_filter_product_values DROP FOREIGN KEY FK_shop_filter_product_values_product_id;`)
  40. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_shop_filter_product_values DROP FOREIGN KEY FK_shop_filter_product_values_filter_value_id;`)
  41. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_shop_filters_values DROP FOREIGN KEY FK_shop_filters_values_filter_id;`)
  42. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_shop_orders DROP FOREIGN KEY FK_shop_orders_currency_id;`)
  43. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_shop_order_products DROP FOREIGN KEY FK_shop_order_products_order_id;`)
  44. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_shop_order_products DROP FOREIGN KEY FK_shop_order_products_product_id;`)
  45. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_shop_product_images DROP FOREIGN KEY FK_shop_product_images_product_id;`)
  46. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_shop_products DROP FOREIGN KEY FK_shop_products_user;`)
  47. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_shop_products DROP FOREIGN KEY FK_shop_products_currency;`)
  48. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_shop_products DROP FOREIGN KEY FK_shop_products_category;`)
  49. _, _ = db.Exec(wrap.R.Context(), `ALTER TABLE fave_shop_products DROP FOREIGN KEY FK_shop_products_parent_id;`)
  50. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_blog_cat_post_rel;`)
  51. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_blog_cats;`)
  52. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_blog_posts;`)
  53. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_notify_mail;`)
  54. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_pages;`)
  55. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_settings;`)
  56. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_shop_cat_product_rel;`)
  57. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_shop_cats;`)
  58. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_shop_currencies;`)
  59. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_shop_filter_product_values;`)
  60. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_shop_filters_values;`)
  61. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_shop_filters;`)
  62. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_shop_order_products;`)
  63. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_shop_orders;`)
  64. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_shop_product_images;`)
  65. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_shop_products;`)
  66. _, _ = db.Exec(wrap.R.Context(), `DROP TABLE fave_users;`)
  67. wrap.ResetCacheBlocks()
  68. wrap.Write(`OK`)
  69. })
  70. }