HookController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-present http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 老猫 <zxxjjforever@163.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller;
  12. use app\admin\logic\HookLogic;
  13. use cmf\controller\AdminBaseController;
  14. use app\admin\model\HookModel;
  15. use app\admin\model\PluginModel;
  16. use app\admin\model\HookPluginModel;
  17. /**
  18. * Class HookController 钩子管理控制器
  19. * @package app\admin\controller
  20. */
  21. class HookController extends AdminBaseController
  22. {
  23. /**
  24. * 钩子管理
  25. * @adminMenu(
  26. * 'name' => '钩子管理',
  27. * 'parent' => 'admin/Plugin/default',
  28. * 'display'=> true,
  29. * 'hasView'=> true,
  30. * 'order' => 10000,
  31. * 'icon' => '',
  32. * 'remark' => '钩子管理',
  33. * 'param' => ''
  34. * )
  35. */
  36. public function index()
  37. {
  38. $hookModel = new HookModel();
  39. $hooks = $hookModel->select();
  40. $this->assign('hooks', $hooks);
  41. return $this->fetch();
  42. }
  43. /**
  44. * 钩子插件管理
  45. * @adminMenu(
  46. * 'name' => '钩子插件管理',
  47. * 'parent' => 'index',
  48. * 'display'=> false,
  49. * 'hasView'=> true,
  50. * 'order' => 10000,
  51. * 'icon' => '',
  52. * 'remark' => '钩子插件管理',
  53. * 'param' => ''
  54. * )
  55. */
  56. public function plugins()
  57. {
  58. $hook = $this->request->param('hook');
  59. $pluginModel = new PluginModel();
  60. $plugins = $pluginModel
  61. ->field('a.*,b.hook,b.plugin,b.list_order,b.status as hook_plugin_status,b.id as hook_plugin_id')
  62. ->alias('a')
  63. ->join('hook_plugin b', 'a.name = b.plugin')
  64. ->where('b.hook', $hook)
  65. ->order('b.list_order asc')
  66. ->select();
  67. $this->assign('plugins', $plugins);
  68. return $this->fetch();
  69. }
  70. /**
  71. * 钩子插件排序
  72. * @adminMenu(
  73. * 'name' => '钩子插件排序',
  74. * 'parent' => 'index',
  75. * 'display'=> false,
  76. * 'hasView'=> false,
  77. * 'order' => 10000,
  78. * 'icon' => '',
  79. * 'remark' => '钩子插件排序',
  80. * 'param' => ''
  81. * )
  82. */
  83. public function pluginListOrder()
  84. {
  85. $hookPluginModel = new HookPluginModel();
  86. parent::listOrders($hookPluginModel);
  87. $this->success("排序更新成功!");
  88. }
  89. /**
  90. * 同步钩子
  91. * @adminMenu(
  92. * 'name' => '同步钩子',
  93. * 'parent' => 'index',
  94. * 'display'=> false,
  95. * 'hasView'=> true,
  96. * 'order' => 10000,
  97. * 'icon' => '',
  98. * 'remark' => '同步钩子',
  99. * 'param' => ''
  100. * )
  101. */
  102. public function sync()
  103. {
  104. $apps = cmf_scan_dir($this->app->getAppPath() . '*', GLOB_ONLYDIR);
  105. array_push($apps, 'cmf', 'admin', 'user', 'swoole');
  106. foreach ($apps as $app) {
  107. HookLogic::importHooks($app);
  108. }
  109. return $this->fetch();
  110. }
  111. }