1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* Auto Groups extension for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com> |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace phpbb\autogroups; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* This ext class is optional and can be omitted if left empty. |
15
|
|
|
* However you can add special (un)installation commands in the |
16
|
|
|
* methods enable_step(), disable_step() and purge_step(). As it is, |
17
|
|
|
* these methods are defined in \phpbb\extension\base, which this |
18
|
|
|
* class extends, but you can overwrite them to give special |
19
|
|
|
* instructions for those cases. |
20
|
|
|
*/ |
21
|
|
|
class ext extends \phpbb\extension\base |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Check whether or not the extension can be enabled. |
25
|
|
|
* The current phpBB version should meet or exceed |
26
|
|
|
* the minimum version required by this extension: |
27
|
|
|
* |
28
|
|
|
* Requires phpBB 3.2.0 due to the revised notifications system |
29
|
|
|
* and new group helper. Requires PHP 5.5 due to array_column(). |
30
|
|
|
* |
31
|
|
|
* @return bool |
32
|
|
|
* @access public |
33
|
|
|
*/ |
34
|
|
|
public function is_enableable() |
35
|
|
|
{ |
36
|
|
|
return $this->check_phpbb_version() && $this->check_php_version(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
protected function check_phpbb_version() |
40
|
|
|
{ |
41
|
|
|
return phpbb_version_compare(PHPBB_VERSION, '3.2.0', '>='); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function check_php_version() |
45
|
|
|
{ |
46
|
|
|
return phpbb_version_compare(PHP_VERSION, '5.5.0', '>='); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Overwrite enable_step to enable Auto Groups notifications |
51
|
|
|
* before any included migrations are installed. |
52
|
|
|
* |
53
|
|
|
* @param mixed $old_state State returned by previous call of this method |
54
|
|
|
* @return mixed Returns false after last step, otherwise temporary state |
55
|
|
|
* @access public |
56
|
|
|
*/ |
57
|
|
|
public function enable_step($old_state) |
58
|
|
|
{ |
59
|
|
|
switch ($old_state) |
60
|
|
|
{ |
61
|
|
|
case '': // Empty means nothing has run yet |
62
|
|
|
|
63
|
|
|
// Enable Auto Groups notifications |
64
|
|
|
return $this->notification_handler('enable', array( |
65
|
|
|
'phpbb.autogroups.notification.type.group_added', |
66
|
|
|
'phpbb.autogroups.notification.type.group_removed', |
67
|
|
|
)); |
68
|
|
|
|
69
|
|
|
break; |
70
|
|
|
|
71
|
|
|
default: |
72
|
|
|
|
73
|
|
|
// Run parent enable step method |
74
|
|
|
return parent::enable_step($old_state); |
75
|
|
|
|
76
|
|
|
break; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Overwrite disable_step to disable Auto Groups notifications |
82
|
|
|
* before the extension is disabled. |
83
|
|
|
* |
84
|
|
|
* @param mixed $old_state State returned by previous call of this method |
85
|
|
|
* @return mixed Returns false after last step, otherwise temporary state |
86
|
|
|
* @access public |
87
|
|
|
*/ |
88
|
|
|
public function disable_step($old_state) |
89
|
|
|
{ |
90
|
|
|
switch ($old_state) |
91
|
|
|
{ |
92
|
|
|
case '': // Empty means nothing has run yet |
93
|
|
|
|
94
|
|
|
// Disable Auto Groups notifications |
95
|
|
|
return $this->notification_handler('disable', array( |
96
|
|
|
'phpbb.autogroups.notification.type.group_added', |
97
|
|
|
'phpbb.autogroups.notification.type.group_removed', |
98
|
|
|
)); |
99
|
|
|
|
100
|
|
|
break; |
101
|
|
|
|
102
|
|
|
default: |
103
|
|
|
|
104
|
|
|
// Run parent disable step method |
105
|
|
|
return parent::disable_step($old_state); |
106
|
|
|
|
107
|
|
|
break; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Overwrite purge_step to purge Auto Groups notifications before |
113
|
|
|
* any included and installed migrations are reverted. |
114
|
|
|
* |
115
|
|
|
* @param mixed $old_state State returned by previous call of this method |
116
|
|
|
* @return mixed Returns false after last step, otherwise temporary state |
117
|
|
|
* @access public |
118
|
|
|
*/ |
119
|
|
|
public function purge_step($old_state) |
120
|
|
|
{ |
121
|
|
|
switch ($old_state) |
122
|
|
|
{ |
123
|
|
|
case '': // Empty means nothing has run yet |
124
|
|
|
|
125
|
|
|
// Purge Auto Groups notifications |
126
|
|
|
return $this->notification_handler('purge', array( |
127
|
|
|
'phpbb.autogroups.notification.type.group_added', |
128
|
|
|
'phpbb.autogroups.notification.type.group_removed', |
129
|
|
|
)); |
130
|
|
|
|
131
|
|
|
break; |
132
|
|
|
|
133
|
|
|
default: |
134
|
|
|
|
135
|
|
|
// Run parent purge step method |
136
|
|
|
return parent::purge_step($old_state); |
137
|
|
|
|
138
|
|
|
break; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Notification handler to call notification enable/disable/purge steps |
144
|
|
|
* |
145
|
|
|
* @param string $step The step (enable, disable, purge) |
146
|
|
|
* @param array $notification_types The notification type names |
147
|
|
|
* @return string Return notifications as temporary state |
148
|
|
|
* @access protected |
149
|
|
|
*/ |
150
|
|
|
protected function notification_handler($step, $notification_types) |
151
|
|
|
{ |
152
|
|
|
$phpbb_notifications = $this->container->get('notification_manager'); |
153
|
|
|
|
154
|
|
|
foreach ($notification_types as $notification_type) |
155
|
|
|
{ |
156
|
|
|
$phpbb_notifications->{$step . '_notifications'}($notification_type); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
return 'notifications'; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|