Completed
Push — master ( fc12da...5e2dd8 )
by Matt
07:52 queued 03:39
created

ext::enable_step()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 0
cp 0
rs 9.52
c 0
b 0
f 0
cc 4
nc 5
nop 1
crap 20
1
<?php
2
/**
3
 *
4
 * Advanced BBCode Box
5
 *
6
 * @copyright (c) 2015 Matt Friedman
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace vse\abbc3;
12
13
use phpbb\filesystem\exception\filesystem_exception;
14
15
class ext extends \phpbb\extension\base
16
{
17
	const MOVE_UP = 'move_up';
18
	const MOVE_DOWN = 'move_down';
19
	const MOVE_DRAG = 'move_drag';
20
	const PHPBB_MIN_VERSION = '3.2.2'; // Require 3.2.2 due to TextFormatter and BBCode changes
21
22
	/**
23
	 * {@inheritdoc}
24
	 */
25 3
	public function is_enableable()
26
	{
27 3
		$config = $this->container->get('config');
28 3
29 3
		return phpbb_version_compare($config['version'], self::PHPBB_MIN_VERSION, '>=') &&
30
			phpbb_version_compare(PHPBB_VERSION, self::PHPBB_MIN_VERSION, '>=');
31
	}
32
33
	/**
34
	 * {@inheritdoc}
35
	 */
36
	public function enable_step($old_state)
37
	{
38
		if ($old_state === false)
39
		{
40
			$filesystem = $this->container->get('filesystem');
41
			$root_path = $this->container->getParameter('core.root_path');
42
43
			try // Make an ABBC3 icon dir in phpBB's images dir
44
			{
45
				if (!$filesystem->exists($root_path . 'images/abbc3/icons'))
46
				{
47
					$filesystem->mkdir($root_path . 'images/abbc3/icons');
48
				}
49
			}
50
			catch (filesystem_exception $e)
51
			{
52
				$user = $this->container->get('user');
53
				$this->container->get('log')->add('critical', $user->data['user_id'], $user->ip, 'LOG_ABBC3_ENABLE_FAIL', false, [$e->get_filename()]);
54
			}
55
56
			return 'abbc3-step';
57
		}
58
59
		return parent::enable_step($old_state);
60
	}
61
}
62