| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- return [
- app\common\events\PluginWasEnabled::class => function ($plugins) {
- if (!$plugins->isEnabled()) {
- //禁用插件时不判断
- if (!extension_loaded('mongodb')) {
- throw new \app\common\exceptions\ShopException('请先安装Mongodb扩展');
- } else {
- try {
- \Illuminate\Support\Facades\DB::connection('mongodb')//选择使用mongodb
- ->collection('yz_instation_message_data')
- ->limit(1)
- ->get();
- if(!\Illuminate\Support\Facades\Schema::connection('mongodb')->hasTable('yz_instation_message_data')) {
- \Illuminate\Support\Facades\Schema::connection('mongodb')->create('yz_instation_message_data', function ($collection) {
- $collection->index('uniacid');
- $collection->index('member_id');
- $collection->index('type_id');
- $collection->index('plugin');
- });
- }
- if(\Illuminate\Support\Facades\Schema::connection('mongodb')->hasTable('yz_instation_message_data')) {
- \Illuminate\Support\Facades\Schema::connection('mongodb')->table('yz_instation_message_data', function ($collection) {
- try {
- $collection->dropIndex('uniacid_1_member_id_1');
- } catch (\Exception $e) {
- }
- });
- }
- } catch (\Exception $e) {
- throw new \app\common\exceptions\ShopException('请确保mongodb数据库已安装和数据库配置信息正确');
- }
- }
- }
- \Artisan::call('migrate',['--path'=>'plugins/instation-message/migrations','--force'=>true]);
- },
- app\common\events\PluginWasDeleted::class => function ($plugins) {
- \Artisan::call('migrate:rollback',['--path'=>'plugins/instation-message/migrations']);
- }
- ];
|