Passed
Push — develop ( 73b4e9...8d0058 )
by Daniel
05:19
created

moderate::make_sticky()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2016 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\content\services\actions\topic;
11
12
use blitze\content\services\actions\action_interface;
13
14
class moderate implements action_interface
15
{
16
	/** @var \phpbb\auth\auth */
0 ignored issues
show
Bug introduced by
The type phpbb\auth\auth was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
	protected $auth;
18
19
	/** @var \phpbb\db\driver\driver_interface */
0 ignored issues
show
Bug introduced by
The type phpbb\db\driver\driver_interface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
	protected $db;
21
22
	/** @var \phpbb\language\language */
0 ignored issues
show
Bug introduced by
The type phpbb\language\language was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
	protected $language;
24
25
	/** @var \phpbb\request\request_interface */
0 ignored issues
show
Bug introduced by
The type phpbb\request\request_interface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
	protected $request;
27
28
	/** @var string */
29
	protected $phpbb_root_path;
30
31
	/** @var string */
32
	protected $php_ext;
33
34
	/**
35
	 * Constructor
36
	 *
37
	 * @param \phpbb\auth\auth								$auth					Auth object
38
	 * @param \phpbb\db\driver\driver_interface				$db						Database connection
39
	 * @param \phpbb\language\language						$language				Language object
40
	 * @param \phpbb\request\request_interface				$request				Request object
41
	 * @param string										$phpbb_root_path		Path to the phpbb includes directory.
42
	 * @param string										$php_ext				php file extension
43
	 */
44
	public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\language\language $language, \phpbb\request\request_interface $request, $phpbb_root_path, $php_ext)
45
	{
46
		$this->auth = $auth;
47
		$this->db = $db;
48
		$this->language = $language;
49
		$this->request = $request;
50
		$this->phpbb_root_path = $phpbb_root_path;
51
		$this->php_ext = $php_ext;
52
	}
53
54
	/**
55
	 * @inheritdoc
56
	 */
57
	public function execute($u_action)
58
	{
59
		$this->language->add_lang('manager', 'blitze/content');
60
61
		$action = $this->request->variable('action', '');
62
		$topic_ids = array_filter($this->request->variable('topic_id_list', array(0)));
63
64
		if (!sizeof($topic_ids) && !$this->request->is_set_post('confirm'))
65
		{
66
			trigger_error('NO_TOPIC_SELECTED');
67
		}
68
69
		if (method_exists($this, $action))
70
		{
71
			$forum_ids = $this->get_selected_forum_ids($topic_ids);
72
			$this->{$action}($topic_ids, $forum_ids);
73
		}
74
		else
75
		{
76
			$message =  $this->language->lang('INVALID_REQUEST', $action);
77
			trigger_error($message . '<br /><br />' . $this->language->lang('RETURN_PAGE', '<a href="' . $u_action . '">', '</a>'));
78
		}
79
	}
80
81
	/**
82
	 * @param array $topic_ids
83
	 * @param array $forum_ids
84
	 * @param bool $execute
85
	 * @return void
86
	 */
87
	protected function approve(array $topic_ids, array $forum_ids, $execute = true)
88
	{
89
		include($this->phpbb_root_path . 'includes/mcp/mcp_queue.' . $this->php_ext);
90
		include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext);
91
92
		if (!(sizeof(array_intersect_key($forum_ids, $this->auth->acl_getf('m_approve', true)))))
93
		{
94
			trigger_error('NOT_AUTHORISED');
95
		}
96
97
		if ($execute)
98
		{
99
			\mcp_queue::approve_topics('approve', $topic_ids, '-blitze-content-mcp-content_module', 'content');
0 ignored issues
show
Bug introduced by
The type mcp_queue was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
100
		}
101
	}
102
103
	/**
104
	 * @param array $topic_ids
105
	 * @param array $forum_ids
106
	 * @return void
107
	 */
108
	protected function disapprove(array $topic_ids, array $forum_ids)
109
	{
110
		$post_id_list = $this->get_selected_post_ids($topic_ids);
111
112
		if (!empty($post_id_list))
113
		{
114
			$this->approve($topic_ids, $forum_ids, false);
115
			\mcp_queue::disapprove_posts($post_id_list, '-blitze-content-mcp-content_module', 'content');
116
		}
117
		else
118
		{
119
			trigger_error('NO_POST_SELECTED');
120
		}
121
	}
122
123
	/**
124
	 * @param array $topic_ids
125
	 * @return void
126
	 */
127
	protected function restore_topic(array $topic_ids)
128
	{
129
		mcp_restore_topic($topic_ids);
0 ignored issues
show
Bug introduced by
The function mcp_restore_topic was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

129
		/** @scrutinizer ignore-call */ 
130
  mcp_restore_topic($topic_ids);
Loading history...
130
	}
131
132
	/**
133
	 * @param array $topic_ids
134
	 * @param array $forum_ids
135
	 */
136
	protected function delete_topic(array $topic_ids, array $forum_ids)
137
	{
138
		$this->language->add_lang('viewtopic');
139
140
		$can_delete = (sizeof(array_intersect_key($forum_ids, $this->auth->acl_getf('m_delete', true)))) ? true : false;
141
		$soft_delete = (($this->request->is_set_post('confirm') && !$this->request->is_set_post('delete_permanent')) || !$can_delete) ? true : false;
142
143
		mcp_delete_topic($topic_ids, $soft_delete, $this->request->variable('delete_reason', '', true));
0 ignored issues
show
Bug introduced by
The function mcp_delete_topic was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

143
		/** @scrutinizer ignore-call */ 
144
  mcp_delete_topic($topic_ids, $soft_delete, $this->request->variable('delete_reason', '', true));
Loading history...
144
	}
145
146
	/**
147
	 * @param array $topic_ids
148
	 * @return void
149
	 */
150
	protected function resync(array $topic_ids)
151
	{
152
		include($this->phpbb_root_path . 'includes/mcp/mcp_forum.' . $this->php_ext);
153
154
		mcp_resync_topics($topic_ids);
0 ignored issues
show
Bug introduced by
The function mcp_resync_topics was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

154
		/** @scrutinizer ignore-call */ 
155
  mcp_resync_topics($topic_ids);
Loading history...
155
	}
156
157
	/**
158
	 * @param $action
159
	 * @param array $topic_ids
160
	 */
161
	protected function change_topic_type($action, array $topic_ids)
162
	{
163
		change_topic_type($action, $topic_ids);
0 ignored issues
show
Bug introduced by
The function change_topic_type was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

163
		/** @scrutinizer ignore-call */ 
164
  change_topic_type($action, $topic_ids);
Loading history...
164
	}
165
166
	/**
167
	 * @param array $topic_ids
168
	 * @return void
169
	 */
170
	protected function make_announce(array $topic_ids)
171
	{
172
		$this->change_topic_type('make_announce', $topic_ids);
173
	}
174
175
	/**
176
	 * @param array $topic_ids
177
	 * @return void
178
	 */
179
	protected function make_sticky(array $topic_ids)
180
	{
181
		$this->change_topic_type('make_sticky', $topic_ids);
182
	}
183
184
	/**
185
	 * @param array $topic_ids
186
	 * @return void
187
	 */
188
	protected function make_global(array $topic_ids)
189
	{
190
		$this->change_topic_type('make_global', $topic_ids);
191
	}
192
193
	/**
194
	 * @param array $topic_ids
195
	 * @return void
196
	 */
197
	protected function make_normal(array $topic_ids)
198
	{
199
		$this->change_topic_type('make_normal', $topic_ids);
200
	}
201
202
	/**
203
	 * @param array $topic_ids
204
	 * @return void
205
	 */
206
	protected function lock(array $topic_ids)
207
	{
208
		lock_unlock('lock', $topic_ids);
0 ignored issues
show
Bug introduced by
The function lock_unlock was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

208
		/** @scrutinizer ignore-call */ 
209
  lock_unlock('lock', $topic_ids);
Loading history...
209
	}
210
211
	/**
212
	 * @param array $topic_ids
213
	 * @return void
214
	 */
215
	protected function unlock(array $topic_ids)
216
	{
217
		lock_unlock('unlock', $topic_ids);
0 ignored issues
show
Bug introduced by
The function lock_unlock was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

217
		/** @scrutinizer ignore-call */ 
218
  lock_unlock('unlock', $topic_ids);
Loading history...
218
	}
219
220
	/**
221
	 * @param array $topic_ids
222
	 * @return array
223
	 */
224
	protected function get_selected_forum_ids(array $topic_ids)
225
	{
226
		if (!sizeof($topic_ids))
227
		{
228
			return array();
229
		}
230
231
		$sql = 'SELECT forum_id
232
			FROM ' . TOPICS_TABLE . '
1 ignored issue
show
Bug introduced by
The constant blitze\content\services\actions\topic\TOPICS_TABLE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
233
			WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids);
234
		$result = $this->db->sql_query($sql);
235
236
		$forum_ids = array();
237
		while ($row = $this->db->sql_fetchrow($result))
238
		{
239
			$forum_ids[$row['forum_id']] = $row['forum_id'];
240
		}
241
		$this->db->sql_freeresult($result);
242
243
		return $forum_ids;
244
	}
245
246
	/**
247
	 * @param array $topic_ids
248
	 * @return array
249
	 */
250
	protected function get_selected_post_ids(array $topic_ids)
251
	{
252
		$post_id_list = array_filter($this->request->variable('post_id_list', array(0)));
253
254
		if (sizeof($post_id_list))
255
		{
256
			return $post_id_list;
257
		}
258
259
		$sql = 'SELECT post_id
260
			FROM ' . POSTS_TABLE . '
1 ignored issue
show
Bug introduced by
The constant blitze\content\services\actions\topic\POSTS_TABLE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
261
			WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids);
262
		$result = $this->db->sql_query($sql);
263
264
		$post_id_list = array();
265
		while ($row = $this->db->sql_fetchrow($result))
266
		{
267
			$post_id_list[] = (int) $row['post_id'];
268
		}
269
		$this->db->sql_freeresult($result);
270
271
		return $post_id_list;
272
	}
273
}
274