Code

< 40 %
40-60 %
> 60 %
1
<?php
2
/**
3
 *
4
 * Akismet. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2018 Jakub Senko <[email protected]>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace senky\akismet;
12
13
/**
14
 * Extension class for custom enable/disable/purge actions
15
 *
16
 * We need this because we're adding notification types. We
17
 * can't leave this to the migrations, as, for example, the
18
 * revert_data only runs when the admin chooses to delete the
19
 * extension data, not just when the extension is disabled.
20
 * If they simply disable the extension, we *must* ensure
21
 * that our custom notifications are purged/disabled, as
22
 * otherwise the board will continue trying to use them even
23
 * though their code is disabled.
24
 */
25
class ext extends \phpbb\extension\base
26
{
27
	protected static $notification_types = array(
28
			'senky.akismet.notification.type.topic_in_queue',
29
			'senky.akismet.notification.type.post_in_queue',
30
	);
31
32
	/**
33
	 * Enable our notifications.
34
	 *
35
	 * @param mixed $old_state State returned by previous call of this method
36
	 * @return mixed Returns false after last step, otherwise temporary state
37
	 * @access public
38
	 */
39
	public function enable_step($old_state)
40
	{
41
		switch ($old_state)
42
		{
43
			case '': // Empty means nothing has run yet
44
				/* @var $phpbb_notifications \phpbb\notification\manager */
45
				$phpbb_notifications = $this->container->get('notification_manager');
46
				foreach (self::$notification_types as $type)
47
				{
48
					$phpbb_notifications->enable_notifications($type);
49
				}
50
				return 'notifications';
51
			break;
52
			default:
53
				// Run parent enable step method
54
				return parent::enable_step($old_state);
55
			break;
56
		}
57
	}
58
59
	/**
60
	 * Disable our notifications.
61
	 *
62
	 * @param mixed $old_state State returned by previous call of this method
63
	 * @return mixed Returns false after last step, otherwise temporary state
64
	 * @access public
65
	 */
66
	public function disable_step($old_state)
67
	{
68
		switch ($old_state)
69
		{
70
			case '': // Empty means nothing has run yet
71
				/* @var $phpbb_notifications \phpbb\notification\manager */
72
				$phpbb_notifications = $this->container->get('notification_manager');
73
				foreach (self::$notification_types as $type)
74
				{
75
					$phpbb_notifications->disable_notifications($type);
76
				}
77
				return 'notifications';
78
			break;
79
			default:
80
				// Run parent disable step method
81
				return parent::disable_step($old_state);
82
			break;
83
		}
84
	}
85
86
	/**
87
	 * Purge our notifications
88
	 *
89
	 * @param mixed $old_state State returned by previous call of this method
90
	 * @return mixed Returns false after last step, otherwise temporary state
91
	 * @access public
92
	 */
93
	public function purge_step($old_state)
94
	{
95
		switch ($old_state)
96
		{
97
			case '': // Empty means nothing has run yet
98
				/* @var $phpbb_notifications \phpbb\notification\manager */
99
				$phpbb_notifications = $this->container->get('notification_manager');
100
				foreach (self::$notification_types as $type)
101
				{
102
					$phpbb_notifications->purge_notifications($type);
103
				}
104
				return 'notifications';
105
			break;
106
			default:
107
				// Run parent purge step method
108
				return parent::purge_step($old_state);
109
			break;
110
		}
111
	}
112
}
113