callbacks.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. return [
  3. app\common\events\PluginWasEnabled::class => function ($plugins) {
  4. if (!$plugins->isEnabled()) {
  5. //禁用插件时不判断
  6. if (!extension_loaded('mongodb')) {
  7. throw new \app\common\exceptions\ShopException('请先安装Mongodb扩展');
  8. } else {
  9. try {
  10. \Illuminate\Support\Facades\DB::connection('mongodb')//选择使用mongodb
  11. ->collection('yz_instation_message_data')
  12. ->limit(1)
  13. ->get();
  14. if(!\Illuminate\Support\Facades\Schema::connection('mongodb')->hasTable('yz_instation_message_data')) {
  15. \Illuminate\Support\Facades\Schema::connection('mongodb')->create('yz_instation_message_data', function ($collection) {
  16. $collection->index('uniacid');
  17. $collection->index('member_id');
  18. $collection->index('type_id');
  19. $collection->index('plugin');
  20. });
  21. }
  22. if(\Illuminate\Support\Facades\Schema::connection('mongodb')->hasTable('yz_instation_message_data')) {
  23. \Illuminate\Support\Facades\Schema::connection('mongodb')->table('yz_instation_message_data', function ($collection) {
  24. try {
  25. $collection->dropIndex('uniacid_1_member_id_1');
  26. } catch (\Exception $e) {
  27. }
  28. });
  29. }
  30. } catch (\Exception $e) {
  31. throw new \app\common\exceptions\ShopException('请确保mongodb数据库已安装和数据库配置信息正确');
  32. }
  33. }
  34. }
  35. \Artisan::call('migrate',['--path'=>'plugins/instation-message/migrations','--force'=>true]);
  36. },
  37. app\common\events\PluginWasDeleted::class => function ($plugins) {
  38. \Artisan::call('migrate:rollback',['--path'=>'plugins/instation-message/migrations']);
  39. }
  40. ];