2016-10-09 19:58:22 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
2021-06-26 17:23:15 +02:00
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
2016-10-09 19:58:22 +02:00
|
|
|
|
2016-11-12 15:12:26 +01:00
|
|
|
class CreateAttachmentsTable extends Migration
|
2016-10-09 19:58:22 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the migrations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function up()
|
|
|
|
{
|
2016-11-12 15:12:26 +01:00
|
|
|
Schema::create('attachments', function (Blueprint $table) {
|
2016-10-09 19:58:22 +02:00
|
|
|
$table->increments('id');
|
|
|
|
$table->string('name');
|
|
|
|
$table->string('path');
|
2016-10-23 14:36:45 +02:00
|
|
|
$table->string('extension', 20);
|
2016-10-09 19:58:22 +02:00
|
|
|
$table->integer('uploaded_to');
|
|
|
|
|
|
|
|
$table->boolean('external');
|
|
|
|
$table->integer('order');
|
|
|
|
|
|
|
|
$table->integer('created_by');
|
|
|
|
$table->integer('updated_by');
|
|
|
|
|
|
|
|
$table->index('uploaded_to');
|
|
|
|
$table->timestamps();
|
|
|
|
});
|
2016-10-10 21:30:27 +02:00
|
|
|
|
|
|
|
// Get roles with permissions we need to change
|
|
|
|
$adminRoleId = DB::table('roles')->where('system_name', '=', 'admin')->first()->id;
|
|
|
|
|
|
|
|
// Create & attach new entity permissions
|
|
|
|
$ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
|
2016-11-12 15:12:26 +01:00
|
|
|
$entity = 'Attachment';
|
2016-10-10 21:30:27 +02:00
|
|
|
foreach ($ops as $op) {
|
|
|
|
$permissionId = DB::table('role_permissions')->insertGetId([
|
2021-06-26 17:23:15 +02:00
|
|
|
'name' => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)),
|
2016-10-10 21:30:27 +02:00
|
|
|
'display_name' => $op . ' ' . $entity . 's',
|
2021-06-26 17:23:15 +02:00
|
|
|
'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
|
|
|
|
'updated_at' => \Carbon\Carbon::now()->toDateTimeString(),
|
2016-10-10 21:30:27 +02:00
|
|
|
]);
|
|
|
|
DB::table('permission_role')->insert([
|
2021-06-26 17:23:15 +02:00
|
|
|
'role_id' => $adminRoleId,
|
|
|
|
'permission_id' => $permissionId,
|
2016-10-10 21:30:27 +02:00
|
|
|
]);
|
|
|
|
}
|
2016-10-09 19:58:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reverse the migrations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function down()
|
|
|
|
{
|
2016-11-12 15:12:26 +01:00
|
|
|
Schema::dropIfExists('attachments');
|
2016-10-10 21:30:27 +02:00
|
|
|
|
|
|
|
// Create & attach new entity permissions
|
|
|
|
$ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
|
2016-11-12 15:12:26 +01:00
|
|
|
$entity = 'Attachment';
|
2016-10-10 21:30:27 +02:00
|
|
|
foreach ($ops as $op) {
|
|
|
|
$permName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op));
|
2016-10-23 14:36:45 +02:00
|
|
|
DB::table('role_permissions')->where('name', '=', $permName)->delete();
|
2016-10-10 21:30:27 +02:00
|
|
|
}
|
2016-10-09 19:58:22 +02:00
|
|
|
}
|
|
|
|
}
|