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 the extension can be enabled. |
||
25 | * The current phpBB version should meet or exceed |
||
26 | * the minimum version required by this extension: |
||
27 | * |
||
28 | * @return bool|array |
||
29 | * @access public |
||
30 | */ |
||
31 | public function is_enableable() |
||
32 | { |
||
33 | $enableable = $this->check_phpbb_version() && $this->check_php_version(); |
||
34 | |||
35 | if (!$enableable && phpbb_version_compare(PHPBB_VERSION, '3.3.0-b1', '>=')) |
||
36 | { |
||
37 | $language = $this->container->get('language'); |
||
38 | $language->add_lang('autogroups_install', 'phpbb/autogroups'); |
||
39 | return $language->lang('AUTOGROUPS_NOT_ENABLEABLE'); |
||
40 | } |
||
41 | |||
42 | return $enableable; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Require phpBB 3.2.0 due to the revised notifications system and new group helper. |
||
47 | * |
||
48 | * @return bool |
||
49 | */ |
||
50 | protected function check_phpbb_version() |
||
51 | { |
||
52 | return phpbb_version_compare(PHPBB_VERSION, '3.2.0', '>='); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Requires PHP 5.5 due to array_column(). |
||
57 | * |
||
58 | * @return bool |
||
59 | */ |
||
60 | protected function check_php_version() |
||
61 | { |
||
62 | return phpbb_version_compare(PHP_VERSION, '5.5.0', '>='); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Overwrite enable_step to enable Auto Groups notifications |
||
67 | * before any included migrations are installed. |
||
68 | * |
||
69 | * @param mixed $old_state State returned by previous call of this method |
||
70 | * @return mixed Returns false after last step, otherwise temporary state |
||
71 | * @access public |
||
72 | */ |
||
73 | public function enable_step($old_state) |
||
74 | { |
||
75 | // if nothing has run yet |
||
76 | if ($old_state === false) |
||
77 | { |
||
78 | // Enable Auto Groups notifications |
||
79 | return $this->notification_handler('enable', array( |
||
80 | 'phpbb.autogroups.notification.type.group_added', |
||
81 | 'phpbb.autogroups.notification.type.group_removed', |
||
82 | )); |
||
83 | } |
||
84 | |||
85 | // Run parent enable step method |
||
86 | return parent::enable_step($old_state); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Overwrite disable_step to disable Auto Groups notifications |
||
91 | * before the extension is disabled. |
||
92 | * |
||
93 | * @param mixed $old_state State returned by previous call of this method |
||
94 | * @return mixed Returns false after last step, otherwise temporary state |
||
95 | * @access public |
||
96 | */ |
||
97 | public function disable_step($old_state) |
||
98 | { |
||
99 | // if nothing has run yet |
||
100 | if ($old_state === false) |
||
101 | { |
||
102 | // Disable Auto Groups notifications |
||
103 | return $this->notification_handler('disable', array( |
||
104 | 'phpbb.autogroups.notification.type.group_added', |
||
105 | 'phpbb.autogroups.notification.type.group_removed', |
||
106 | )); |
||
107 | } |
||
108 | |||
109 | // Run parent disable step method |
||
110 | return parent::disable_step($old_state); |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * Overwrite purge_step to purge Auto Groups notifications before |
||
115 | * any included and installed migrations are reverted. |
||
116 | * |
||
117 | * @param mixed $old_state State returned by previous call of this method |
||
118 | * @return mixed Returns false after last step, otherwise temporary state |
||
119 | * @access public |
||
120 | */ |
||
121 | public function purge_step($old_state) |
||
122 | { |
||
123 | // if nothing has run yet |
||
124 | if ($old_state === false) |
||
125 | { |
||
126 | // Purge Auto Groups notifications |
||
127 | return $this->notification_handler('purge', array( |
||
128 | 'phpbb.autogroups.notification.type.group_added', |
||
129 | 'phpbb.autogroups.notification.type.group_removed', |
||
130 | )); |
||
131 | } |
||
132 | |||
133 | // Run parent purge step method |
||
134 | return parent::purge_step($old_state); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Notification handler to call notification enable/disable/purge steps |
||
139 | * |
||
140 | * @param string $step The step (enable, disable, purge) |
||
141 | * @param array $notification_types The notification type names |
||
142 | * @return string Return notifications as temporary state |
||
143 | * @access protected |
||
144 | */ |
||
145 | protected function notification_handler($step, $notification_types) |
||
146 | { |
||
147 | $phpbb_notifications = $this->container->get('notification_manager'); |
||
148 | |||
149 | foreach ($notification_types as $notification_type) |
||
150 | { |
||
151 | $phpbb_notifications->{$step . '_notifications'}($notification_type); |
||
152 | } |
||
153 | |||
154 | return 'notifications'; |
||
155 | } |
||
156 | } |
||
157 |