-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
255 lines (230 loc) · 7.9 KB
/
plugin.php
File metadata and controls
255 lines (230 loc) · 7.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
/**
* Plugin.php
*
* This file is part of the Xpressengine package.
*
* PHP version 7
*
* @category Mailing
* @package Xpressengine\Plugins\Mailing
* @author XE Developers <developers@xpressengine.com>
* @copyright 2019 Copyright XEHub Corp. <https://www.xehub.io>
* @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html LGPL
* @link https://xpressengine.io
*/
namespace Xpressengine\Plugins\Mailing;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Console\Application as Artisan;
use Route;
use Schema;
use Xpressengine\Plugin\AbstractPlugin;
use Xpressengine\Plugins\Mailing\Commands\AgreeCommand;
use Xpressengine\Plugins\Mailing\Commands\ReconfirmCommand;
use Xpressengine\Plugins\Mailing\Parts\MailingAgreePart;
use Xpressengine\User\UserHandler;
/**
* Plugin
*
* @category Mailing
* @package Xpressengine\Plugins\Mailing
* @author XE Developers <developers@xpressengine.com>
* @copyright 2019 Copyright XEHub Corp. <https://www.xehub.io>
* @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html LGPL
* @link https://xpressengine.io
*/
class Plugin extends AbstractPlugin
{
/**
* register
*
* @return void
*/
public function register()
{
app()->singleton(Handler::class, function ($app) {
$proxyClass = app('xe.interception')->proxy(Handler::class, 'Mailing');
return new $proxyClass(config('services.mailing'));
});
app()->alias(Handler::class, 'mailing::handler');
// register commands
app()->singleton(
'mailing::command.reconfirm',
function ($app) {
return new ReconfirmCommand(app('mailing::handler'));
}
);
app()->singleton(
'mailing::command.agree',
function ($app) {
return new AgreeCommand(app('mailing::handler'));
}
);
$commands = ['mailing::command.reconfirm', 'mailing::command.agree'];
Artisan::starting(function ($artisan) use ($commands) {
$artisan->resolveCommands($commands);
});
// set configuration
$config = config('services.mailing');
$default = include('config.php');
if ($config) {
$new = array_replace_recursive($default, $config);
config(['services.mailing' => $new]);
} else {
config(['services.mailing' => $default]);
}
}
/**
* 이 메소드는 활성화(activate) 된 플러그인이 부트될 때 항상 실행됩니다.
*
* @return void
*/
public function boot()
{
$this->route();
UserHandler::setSettingsSections('mailing@agreement', [
'title' => '프로모션 메일링 설정',
'content' => function () {
return app()->call('Xpressengine\Plugins\Mailing\Controllers\SettingController@index');
}
]);
UserHandler::addRegisterPart(MailingAgreePart::class);
intercept(
'XeUser@create',
'mailing@create',
function ($target, $data, $token = null) {
$agree = array_get($data, 'agree_mailing');
$user = $target($data, $token);
if ($agree === 'on') {
app('mailing::handler')->agree($user->id);
}
return $user;
}
);
$schedule = app('Illuminate\Console\Scheduling\Schedule');
$at = config('services.mailing.scheduled_at');
if ($at) {
$schedule->command('mailing:reconfirm')->dailyAt($at)->appendOutputTo('storage/logs/mailing.log');
}
}
/**
* register route
*
* @return void
*/
protected function route()
{
Route::fixed(
static::getId(),
function () {
Route::group(
['namespace' => 'Xpressengine\Plugins\Mailing\Controllers'],
function () {
Route::get(
'users/{user_id}/mailing',
['as' => 'mailing::deny.show', 'uses' => 'Controller@show']
);
Route::put(
'users/{user_id}/mailing',
['as' => 'mailing::deny.update', 'uses' => 'Controller@update']
);
Route::get(
'user/setting',
[
'as' => 'mailing::setting.show',
'uses' => 'SettingController@show',
'middleware' => 'auth'
]
);
Route::post(
'user/setting',
[
'as' => 'mailing::setting.update',
'uses' => 'SettingController@update',
'middleware' => 'auth'
]
);
}
);
}
);
}
/**
* 플러그인이 활성화될 때 실행할 코드를 여기에 작성한다.
*
* @param string|null $installedVersion 현재 XpressEngine에 설치된 플러그인의 버전정보
*
* @return void
*/
public function activate($installedVersion = null)
{
// implement code
}
/**
* 플러그인을 설치한다. 플러그인이 설치될 때 실행할 코드를 여기에 작성한다
*
* @return void
*/
public function install()
{
if (!Schema::hasTable('mailing')) {
Schema::create(
'mailing',
function (Blueprint $table) {
$table->engine = "InnoDB";
//user_id VARCHAR(36) PRIMARY KEY NOT NULL,
$table->string('user_id', 36);
$table->char('status', 20);
$table->string('deny_token', 36)->nullable();
$table->timestamp('created_at')->index();
$table->timestamp('updated_at')->index();
$table->primary('user_id');
}
);
}
if (!Schema::hasTable('mailing_log')) {
Schema::create(
'mailing_log',
function (Blueprint $table) {
$table->engine = "InnoDB";
$table->increments('id');
$table->string('user_id', 36);
$table->string('action', 20); //
$table->string('result', 20); // successd, failed
$table->string('content');
$table->timestamp('created_at')->index();
$table->timestamp('updated_at');
$table->index('user_id');
}
);
}
}
/**
* 해당 플러그인이 설치된 상태라면 true, 설치되어있지 않다면 false를 반환한다.
* 이 메소드를 구현하지 않았다면 기본적으로 설치된 상태(true)를 반환한다.
*
* @return boolean 플러그인의 설치 유무
*/
public function checkInstalled()
{
return Schema::hasTable('mailing') && Schema::hasTable('mailing_log');
}
/**
* 플러그인을 업데이트한다.
*
* @return void
*/
public function update()
{
}
/**
* 해당 플러그인이 최신 상태로 업데이트가 된 상태라면 true, 업데이트가 필요한 상태라면 false를 반환함.
* 이 메소드를 구현하지 않았다면 기본적으로 최신업데이트 상태임(true)을 반환함.
*
* @return boolean 플러그인의 설치 유무,
*/
public function checkUpdated()
{
return true;
}
}