1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sqits\UserStamps\Database\Schema\Macros; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Schema\Blueprint; |
6
|
|
|
use Illuminate\Database\SQLiteConnection; |
7
|
|
|
use Illuminate\Support\Facades\DB; |
8
|
|
|
|
9
|
|
|
class UserStampsMacro implements MacroInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Bootstrap the schema macro. |
13
|
|
|
* |
14
|
|
|
* @return void |
15
|
|
|
*/ |
16
|
|
|
public function register() |
17
|
|
|
{ |
18
|
|
|
$this->registerUserstamps(); |
19
|
|
|
$this->registerSoftUserstamps(); |
20
|
|
|
$this->registerDropUserstamps(); |
21
|
|
|
$this->registerDropSoftUserstamps(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
private function registerUserstamps() |
25
|
|
|
{ |
26
|
|
|
Blueprint::macro('userstamps', function () { |
27
|
|
|
if (config('userstamps.users_table_column_type') === 'bigIncrements') { |
28
|
|
|
$this->unsignedBigInteger(config('userstamps.created_by_column'))->nullable(); |
|
|
|
|
29
|
|
|
$this->unsignedBigInteger(config('userstamps.updated_by_column'))->nullable(); |
30
|
|
|
} elseif (config('userstamps.users_table_column_type') === 'uuid') { |
31
|
|
|
$this->uuid(config('userstamps.created_by_column'))->nullable(); |
|
|
|
|
32
|
|
|
$this->uuid(config('userstamps.updated_by_column'))->nullable(); |
33
|
|
|
} elseif (config('userstamps.users_table_column_type') === 'ulid') { |
34
|
|
|
$this->ulid(config('userstamps.created_by_column'))->nullable(); |
|
|
|
|
35
|
|
|
$this->ulid(config('userstamps.updated_by_column'))->nullable(); |
36
|
|
|
} else { |
37
|
|
|
$this->unsignedInteger(config('userstamps.created_by_column'))->nullable(); |
|
|
|
|
38
|
|
|
$this->unsignedInteger(config('userstamps.updated_by_column'))->nullable(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$this->foreign(config('userstamps.created_by_column')) |
|
|
|
|
42
|
|
|
->references(config('userstamps.users_table_column_id_name')) |
43
|
|
|
->on(config('userstamps.users_table')) |
44
|
|
|
->onDelete('set null'); |
45
|
|
|
|
46
|
|
|
$this->foreign(config('userstamps.updated_by_column')) |
47
|
|
|
->references(config('userstamps.users_table_column_id_name')) |
48
|
|
|
->on(config('userstamps.users_table')) |
49
|
|
|
->onDelete('set null'); |
50
|
|
|
|
51
|
|
|
return $this; |
52
|
|
|
}); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
private function registerSoftUserstamps() |
56
|
|
|
{ |
57
|
|
|
Blueprint::macro('softUserstamps', function () { |
58
|
|
|
if (config('userstamps.users_table_column_type') === 'bigIncrements') { |
59
|
|
|
$this->unsignedBigInteger(config('userstamps.deleted_by_column'))->nullable(); |
60
|
|
|
} elseif (config('userstamps.users_table_column_type') === 'uuid') { |
61
|
|
|
$this->uuid(config('userstamps.deleted_by_column'))->nullable(); |
62
|
|
|
} elseif (config('userstamps.users_table_column_type') === 'ulid') { |
63
|
|
|
$this->ulid(config('userstamps.deleted_by_column'))->nullable(); |
64
|
|
|
} else { |
65
|
|
|
$this->unsignedInteger(config('userstamps.deleted_by_column'))->nullable(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$this->foreign(config('userstamps.deleted_by_column')) |
69
|
|
|
->references(config('userstamps.users_table_column_id_name')) |
70
|
|
|
->on(config('userstamps.users_table')) |
71
|
|
|
->onDelete('set null'); |
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
}); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
private function registerDropUserstamps() |
78
|
|
|
{ |
79
|
|
|
Blueprint::macro('dropUserstamps', function () { |
80
|
|
|
if (! DB::connection() instanceof SQLiteConnection) { |
81
|
|
|
$this->dropForeign([ |
|
|
|
|
82
|
|
|
config('userstamps.created_by_column'), |
83
|
|
|
]); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if (! DB::connection() instanceof SQLiteConnection) { |
87
|
|
|
$this->dropForeign([ |
88
|
|
|
config('userstamps.updated_by_column'), |
89
|
|
|
]); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$this->dropColumn([ |
|
|
|
|
93
|
|
|
config('userstamps.created_by_column'), |
94
|
|
|
config('userstamps.updated_by_column'), |
95
|
|
|
]); |
96
|
|
|
}); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
private function registerDropSoftUserstamps() |
100
|
|
|
{ |
101
|
|
|
Blueprint::macro('dropSoftUserstamps', function () { |
102
|
|
|
if (! DB::connection() instanceof SQLiteConnection) { |
103
|
|
|
$this->dropForeign([ |
104
|
|
|
config('userstamps.deleted_by_column'), |
105
|
|
|
]); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$this->dropColumn(config('userstamps.deleted_by_column')); |
109
|
|
|
}); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.