Completed
Push — master ( c7d5ad...0208a8 )
by Sherif
02:59
created

InitializeNotifications   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 111
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B up() 0 89 2
A down() 0 8 1
1
<?php
2
3
use Illuminate\Database\Schema\Blueprint;
4
use Illuminate\Database\Migrations\Migration;
5
6
class InitializeNotifications extends Migration
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
	/**
9
	 * Run the migrations.
10
	 *
11
	 * @return void
12
	 */
13
	public function up()
14
	{
15
        /**
16
         * Delete previous permissions.
17
         */
18
		DB::table('permissions')->whereIn('model', ['notifications'])->delete();
19
20
		/**
21
         * Insert the permissions related to this module.
22
         */
23
        DB::table('permissions')->insert(
24
        	[
25
        		/**
26
        		 * Logs model permissions.
27
        		 */
28
	        	[
29
	        	'name'       => 'find',
30
	        	'model'      => 'notifications',
31
	        	'created_at' => \DB::raw('NOW()'),
32
	        	'updated_at' => \DB::raw('NOW()')
33
	        	],
34
	        	[
35
	        	'name'       => 'search',
36
	        	'model'      => 'notifications',
37
	        	'created_at' => \DB::raw('NOW()'),
38
	        	'updated_at' => \DB::raw('NOW()')
39
	        	],
40
	        	[
41
	        	'name'       => 'list',
42
	        	'model'      => 'notifications',
43
	        	'created_at' => \DB::raw('NOW()'),
44
	        	'updated_at' => \DB::raw('NOW()')
45
	        	],
46
	        	[
47
	        	'name'       => 'findby',
48
	        	'model'      => 'notifications',
49
	        	'created_at' => \DB::raw('NOW()'),
50
	        	'updated_at' => \DB::raw('NOW()')
51
	        	],
52
	        	[
53
	        	'name'       => 'first',
54
	        	'model'      => 'notifications',
55
	        	'created_at' => \DB::raw('NOW()'),
56
	        	'updated_at' => \DB::raw('NOW()')
57
	        	],
58
	        	[
59
	        	'name'       => 'paginate',
60
	        	'model'      => 'notifications',
61
	        	'created_at' => \DB::raw('NOW()'),
62
	        	'updated_at' => \DB::raw('NOW()')
63
	        	],
64
	        	[
65
	        	'name'       => 'paginateby',
66
	        	'model'      => 'notifications',
67
	        	'created_at' => \DB::raw('NOW()'),
68
	        	'updated_at' => \DB::raw('NOW()')
69
	        	],
70
	        	[
71
	        	'name'       => 'notified',
72
	        	'model'      => 'notifications',
73
	        	'created_at' => \DB::raw('NOW()'),
74
	        	'updated_at' => \DB::raw('NOW()')
75
	        	],
76
	        	[
77
	        	'name'       => 'notifyall',
78
	        	'model'      => 'notifications',
79
	        	'created_at' => \DB::raw('NOW()'),
80
	        	'updated_at' => \DB::raw('NOW()')
81
	        	],
82
        	]
83
        );
84
85
        /**
86
		 * Assign the permissions to the admin group.
87
		 */
88
		$permissionIds = DB::table('permissions')->whereIn('model', ['notifications'])->select('id')->lists('id');
89
		$adminGroupId  = DB::table('groups')->where('name', 'Admin')->first()->id;
90
		foreach ($permissionIds as $permissionId) 
91
		{
92
			DB::table('groups_permissions')->insert(
93
				[
94
				'permission_id' => $permissionId,
95
				'group_id'      => $adminGroupId,
96
				'created_at'    => \DB::raw('NOW()'),
97
				'updated_at'    => \DB::raw('NOW()')
98
				]
99
			);
100
		}
101
	}
102
103
	/**
104
	 * Reverse the migrations.
105
	 *
106
	 * @return void
107
	 */
108
	public function down()
109
	{
110
		$adminGroupId = DB::table('groups')->where('name', 'Admin')->first()->id;
111
		$adminUserId  = DB::table('users')->where('email', '[email protected]')->first()->id;
112
113
		DB::table('permissions')->whereIn('model', ['notifications'])->delete();
114
		DB::table('users_groups')->where('user_id', $adminUserId)->where('group_id', $adminGroupId)->delete();
115
	}
116
}