-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathPaidSubscriptionUserAction.class.php
More file actions
242 lines (215 loc) · 6.4 KB
/
PaidSubscriptionUserAction.class.php
File metadata and controls
242 lines (215 loc) · 6.4 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
<?php
namespace wcf\data\paid\subscription\user;
use wcf\command\paid\subscription\AddGroupMembership;
use wcf\command\paid\subscription\RemoveGroupMembership;
use wcf\command\paid\subscription\user\ExtendPaidSubscriptionUser;
use wcf\command\paid\subscription\user\RestorePaidSubscriptionUser;
use wcf\command\paid\subscription\user\RevokePaidSubscriptionUser;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\data\paid\subscription\PaidSubscription;
use wcf\data\user\User;
use wcf\system\exception\UserInputException;
use wcf\util\DateUtil;
/**
* Executes paid subscription user-related actions.
*
* @author Marcel Werk
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*
* @extends AbstractDatabaseObjectAction<PaidSubscriptionUser, PaidSubscriptionUserEditor>
*/
class PaidSubscriptionUserAction extends AbstractDatabaseObjectAction
{
/**
* @inheritDoc
*/
protected $permissionsDelete = ['admin.paidSubscription.canManageSubscription'];
/**
* @inheritDoc
*/
protected $permissionsUpdate = ['admin.paidSubscription.canManageSubscription'];
/**
* @inheritDoc
*/
protected $requireACP = ['create', 'delete', 'update'];
/**
* @inheritDoc
*/
public function create()
{
$this->parameters['data']['subscriptionID'] = $this->parameters['subscription']->subscriptionID;
$this->parameters['data']['userID'] = $this->parameters['user']->userID;
if (!isset($this->parameters['data']['startDate'])) {
$this->parameters['data']['startDate'] = TIME_NOW;
}
if (!isset($this->parameters['data']['endDate'])) {
if (!$this->parameters['subscription']->subscriptionLength) {
$this->parameters['data']['endDate'] = 0;
} else {
$d = DateUtil::getDateTimeByTimestamp($this->parameters['data']['startDate']);
$d->add($this->parameters['subscription']->getDateInterval());
$this->parameters['data']['endDate'] = $d->getTimestamp();
}
}
if (!isset($this->parameters['data']['isActive'])) {
$this->parameters['data']['isActive'] = 1;
}
$subscriptionUser = parent::create();
(new AddGroupMembership(
$this->parameters['subscription'],
$this->parameters['user']
))();
return $subscriptionUser;
}
/**
* @inheritDoc
*/
public function validateCreate()
{
parent::validateCreate();
if (
!isset($this->parameters['subscription'])
|| !($this->parameters['subscription'] instanceof PaidSubscription)
) {
throw new UserInputException('subscription');
}
if (!isset($this->parameters['user']) || !($this->parameters['user'] instanceof User)) {
throw new UserInputException('user');
}
}
/**
* Extends an existing subscription.
*
* @return void
*
* @deprecated 6.3 Use the `ExtendPaidSubscriptionUser` command instead.
*/
public function extend()
{
if (empty($this->objects)) {
$this->readObjects();
}
foreach ($this->getObjects() as $editor) {
if (isset($this->parameters['data']['endDate'])) {
(new ExtendPaidSubscriptionUser(
$editor->getDecoratedObject(),
$this->parameters['data']['endDate']
))();
} else {
(new ExtendPaidSubscriptionUser($editor->getDecoratedObject()))();
}
}
}
/**
* @inheritDoc
*/
public function delete()
{
$this->revoke();
return parent::delete();
}
/**
* Revokes an existing subscription.
*
* @return void
*
* @deprecated 6.3 Use the `RevokePaidSubscriptionUser` command instead.
*/
public function revoke()
{
if (empty($this->objects)) {
$this->readObjects();
}
foreach ($this->getObjects() as $editor) {
(new RevokePaidSubscriptionUser($editor->getDecoratedObject()))();
}
}
/**
* Validates the revoke action.
*
* @return void
*
* @deprecated 6.3
*/
public function validateRevoke()
{
if (empty($this->objects)) {
$this->readObjects();
}
foreach ($this->getObjects() as $subscriptionUser) {
if (!$subscriptionUser->isActive) {
throw new UserInputException('objectIDs');
}
}
}
/**
* Restores an existing subscription.
*
* @return void
*
* @deprecated 6.3 use the `RestorePaidSubscriptionUser` command instead.
*/
public function restore()
{
if (empty($this->objects)) {
$this->readObjects();
}
foreach ($this->getObjects() as $editor) {
(new RestorePaidSubscriptionUser($editor->getDecoratedObject()))();
}
}
/**
* Validates the restore action.
*
* @return void
*
* @deprecated 6.3
*/
public function validateRestore()
{
if (empty($this->objects)) {
$this->readObjects();
}
foreach ($this->getObjects() as $subscriptionUser) {
if ($subscriptionUser->isActive) {
throw new UserInputException('objectIDs');
}
}
}
/**
* Applies group memberships.
*
* @return void
*
* @deprecated 6.3 Use the `AddGroupMembership` command instead.
*/
public function addGroupMemberships()
{
if (empty($this->objects)) {
$this->readObjects();
}
foreach ($this->getObjects() as $subscriptionUser) {
(new AddGroupMembership(
$subscriptionUser->getSubscription(),
$subscriptionUser->getUser()
))();
}
}
/**
* Removes group memberships.
*
* @return void
*
* @deprecated 6.3 Use the `RemoveGroupMembership` command instead.
*/
public function removeGroupMemberships()
{
if (empty($this->objects)) {
$this->readObjects();
}
foreach ($this->getObjects() as $editor) {
(new RemoveGroupMembership($editor->getSubscription(), $editor->getUser()))();
}
}
}