Differential D3902 Diff 11165 src/database/migrations/2022_05_13_100000_permissions_and_room_subscriptions.php
Changeset View
Changeset View
Standalone View
Standalone View
src/database/migrations/2022_05_13_100000_permissions_and_room_subscriptions.php
Show All 32 Lines | public function up(): void | ||||
$table->string('description')->nullable(); | $table->string('description')->nullable(); | ||||
$table->softDeletes(); | $table->softDeletes(); | ||||
$table->foreign('tenant_id')->references('id')->on('tenants')->onDelete('set null'); | $table->foreign('tenant_id')->references('id')->on('tenants')->onDelete('set null'); | ||||
} | } | ||||
); | ); | ||||
// Create the new SKUs | // Create the new SKUs | ||||
if (!\App\Sku::where('title', 'room')->first()) { | $sku = \App\Sku::where('title', 'room')->first(); | ||||
$sku = \App\Sku::create([ | |||||
'title' => 'group-room', | |||||
'name' => 'Group conference room', | |||||
'description' => 'Shareable audio & video conference room', | |||||
'cost' => 0, | |||||
'units_free' => 0, | |||||
'period' => 'monthly', | |||||
'handler_class' => 'App\Handlers\GroupRoom', | |||||
'active' => true, | |||||
]); | |||||
$sku = \App\Sku::create([ | |||||
'title' => 'room', | |||||
'name' => 'Standard conference room', | |||||
'description' => 'Audio & video conference room', | |||||
'cost' => 0, | |||||
'units_free' => 0, | |||||
'period' => 'monthly', | |||||
'handler_class' => 'App\Handlers\Room', | |||||
'active' => true, | |||||
]); | |||||
// Create the entitlement for every existing room | // Create the entitlement for every existing room | ||||
foreach (\App\Meet\Room::get() as $room) { | foreach (\App\Meet\Room::get() as $room) { | ||||
$user = \App\User::find($room->user_id); // @phpstan-ignore-line | $user = \App\User::find($room->user_id); // @phpstan-ignore-line | ||||
if (!$user) { | if (!$user) { | ||||
$room->forceDelete(); | $room->forceDelete(); | ||||
continue; | continue; | ||||
} | } | ||||
// Set tenant_id | // Set tenant_id | ||||
if ($user->tenant_id) { | if ($user->tenant_id) { | ||||
$room->tenant_id = $user->tenant_id; | $room->tenant_id = $user->tenant_id; | ||||
$room->save(); | $room->save(); | ||||
} | } | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
\App\Entitlement::create([ | \App\Entitlement::create([ | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'sku_id' => $sku->id, | 'sku_id' => $sku->id, | ||||
'cost' => 0, | 'cost' => 0, | ||||
'fee' => 0, | 'fee' => 0, | ||||
'entitleable_id' => $room->id, | 'entitleable_id' => $room->id, | ||||
'entitleable_type' => \App\Meet\Room::class | 'entitleable_type' => \App\Meet\Room::class | ||||
]); | ]); | ||||
} | } | ||||
} | |||||
// Remove 'meet' SKU/entitlements | // Remove 'meet' SKU/entitlements | ||||
\App\Sku::where('title', 'meet')->delete(); | \App\Sku::where('title', 'meet')->delete(); | ||||
Schema::table( | Schema::table( | ||||
'openvidu_rooms', | 'openvidu_rooms', | ||||
function (Blueprint $table) { | function (Blueprint $table) { | ||||
$table->dropForeign('openvidu_rooms_user_id_foreign'); | $table->dropForeign('openvidu_rooms_user_id_foreign'); | ||||
Show All 34 Lines | public function down(): void | ||||
Schema::table( | Schema::table( | ||||
'openvidu_rooms', | 'openvidu_rooms', | ||||
function (Blueprint $table) { | function (Blueprint $table) { | ||||
$table->dropSoftDeletes(); | $table->dropSoftDeletes(); | ||||
} | } | ||||
); | ); | ||||
\App\Entitlement::where('entitleable_type', \App\Meet\Room::class)->forceDelete(); | \App\Entitlement::where('entitleable_type', \App\Meet\Room::class)->forceDelete(); | ||||
\App\Sku::where('title', 'room')->delete(); | |||||
\App\Sku::where('title', 'group-room')->delete(); | |||||
\App\Sku::create([ | |||||
'title' => 'meet', | |||||
'name' => 'Voice & Video Conferencing (public beta)', | |||||
'description' => 'Video conferencing tool', | |||||
'cost' => 0, | |||||
'units_free' => 0, | |||||
'period' => 'monthly', | |||||
'handler_class' => 'App\Handlers\Meet', | |||||
'active' => true, | |||||
]); | |||||
Schema::dropIfExists('permissions'); | Schema::dropIfExists('permissions'); | ||||
} | } | ||||
}; | }; |