YzpluginSeeder.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. use Illuminate\Database\Seeder;
  3. class YzpluginSeeder extends Seeder
  4. {
  5. protected $table = 'yz_options';
  6. protected $uniTable = 'uni_account';
  7. public function __construct()
  8. {
  9. if (config('app.framework') == 'platform') {
  10. $this->uniTable = 'yz_uniacid_app';
  11. }
  12. }
  13. public function run()
  14. {
  15. $installed = app('plugins')->getPlugins();
  16. $is_plugin = \Illuminate\Support\Facades\DB::table($this->table)->where('option_name', 'test-plugins')->get();
  17. if ($is_plugin->isNotEmpty()) {
  18. return;
  19. }
  20. $plugins_enabled = \Illuminate\Support\Facades\DB::table($this->table)->where('option_name', 'plugins_enabled')->pluck("option_value")->first();
  21. $key = \Illuminate\Support\Facades\DB::table($this->table)->where('option_name', 'key')->pluck('option_value')->first();
  22. $market_source = \Illuminate\Support\Facades\DB::table($this->table)->where('option_name', 'market_source')->pluck("option_value")->first();
  23. $uniAccount = \Illuminate\Support\Facades\DB::table($this->uniTable)->get();
  24. $data[] = [
  25. 'uniacid' => '0',
  26. 'option_name' => 'test-plugins',
  27. 'option_value' => 'true',
  28. 'enabled' => '1',
  29. ];
  30. $data[] = [
  31. 'uniacid' => '0',
  32. 'option_name' => 'plugins-market',
  33. 'option_value' => 'true',
  34. 'enabled' => '1',
  35. ];
  36. $data[] = [
  37. 'uniacid' => '0',
  38. 'option_name' => 'market_source',
  39. 'option_value' => $market_source,
  40. 'enabled' => '1',
  41. ];
  42. $data[] = [
  43. 'uniacid' => '0',
  44. 'option_name' => 'key',
  45. 'option_value' => $key,
  46. 'enabled' => '1',
  47. ];
  48. $i = 4;
  49. foreach ($uniAccount as $u) {
  50. foreach ($installed as $key => $plugin) {
  51. if ($plugin['option_name'] == 'plugins_enabled') {
  52. continue;
  53. }
  54. if ($plugin['option_name'] == 'market_source') {
  55. continue;
  56. }
  57. if ($plugin['option_name'] == 'plugins-market') {
  58. continue;
  59. }
  60. $data[$i] = [
  61. 'uniacid' => $u['uniacid'],
  62. 'option_name' => $key,
  63. 'option_value' => 'true',
  64. 'enabled' => 0,
  65. ];
  66. if (strpos($plugins_enabled, $key)) {
  67. $data[$i]['enabled'] = 1;
  68. }
  69. $i++;
  70. }
  71. }
  72. \Illuminate\Support\Facades\DB::table($this->table)->delete();
  73. \Illuminate\Support\Facades\DB::table($this->table)->insert($data);
  74. }
  75. }