1
0

20230413104906_add_agent_article_menu_to_permission_table.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. use app\model\Permission;
  3. use app\model\Grant;
  4. use think\migration\Migrator;
  5. class AddAgentArticleMenuToPermissionTable extends Migrator
  6. {
  7. /**
  8. * Change Method.
  9. *
  10. * Write your reversible migrations using this method.
  11. *
  12. * More information on writing migrations is available here:
  13. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  14. *
  15. * The following commands can be used in this method and Phinx will
  16. * automatically reverse them when rolling back:
  17. *
  18. * createTable
  19. * renameTable
  20. * addColumn
  21. * renameColumn
  22. * addIndex
  23. * addForeignKey
  24. *
  25. * Remember to call "create()" or "update()" and NOT "save()" when working
  26. * with the Table class.
  27. */
  28. public function change()
  29. {
  30. $permission = Permission::where(['uri'=>'agents/agent_list'])->find();
  31. $addnewpr = [
  32. 'pid' => $permission->pid,
  33. 'auth_name' => '内容管理',
  34. 'uri' => 'agents/agent_article_list',
  35. 'is_menu' => 1,
  36. 'relation' => 'agents/agent_article_list,agents/add_article,agents/imgUpload,agents/edit_article,agents/del_article,agents/apipublish,agents/agtemp_artlist'
  37. ];
  38. $parent = $permission->create($addnewpr);
  39. $grant = Grant::find(1);
  40. $permission = array_merge(json_decode(json_encode($grant->permission), true), [$parent->id]);
  41. asort($permission);
  42. $grant->permission = $permission;
  43. $grant->save();
  44. }
  45. }