Completed
Push — develop-3.2 ( 3685db...4cc568 )
by Matt
32:16
created

v322_m11_reparse::depends_on()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
/**
3
*
4
* Advanced BBCode Box
5
*
6
* @copyright (c) 2018 Matt Friedman
7
* @license GNU General Public License, version 2 (GPL-2.0)
8
*
9
*/
10
11
namespace vse\abbc3\migrations;
12
13
use phpbb\db\migration\container_aware_migration;
14
15
class v322_m11_reparse extends container_aware_migration
16
{
17
	/**
18
	 * {@inheritdoc}
19
	 */
20
	public static function depends_on()
21
	{
22
		return array(
23
			'\phpbb\db\migration\data\v320\text_reparser',
24
			'\vse\abbc3\migrations\v310_m4_install_data',
25
			'\vse\abbc3\migrations\v310_m5_update_bbcodes',
26
			'\vse\abbc3\migrations\v310_m6_update_bbcodes',
27
			'\vse\abbc3\migrations\v310_m7_update_bbcodes',
28
			'\vse\abbc3\migrations\v322_m8_update_bbcodes',
29
			'\vse\abbc3\migrations\v322_m9_delete_bbcodes',
30
			'\vse\abbc3\migrations\v322_m10_merge_duplicate_bbcodes',
31
		);
32
	}
33
34
	/**
35
	 * {@inheritdoc}
36
	 */
37
	public function effectively_installed()
38
	{
39
		return $this->config->offsetExists('abbc3_reparse');
40
	}
41
42
	/**
43
	 * {@inheritdoc}
44
	 */
45
	public function update_data()
46
	{
47
		return array(
48
			array('config.add', array('abbc3_reparse', time())),
49
			array('if', array(
50
				$this->config->offsetExists('reparse_lock'),
51
				array('config.remove', array('reparse_lock', 0)),
52
			)),
53
			array('if', array(
54
				!$this->config->offsetExists('text_reparser.pm_text_last_cron'),
55
				array('config.add', array('text_reparser.pm_text_last_cron', 0)),
56
			)),
57
			array('if', array(
58
				!$this->config->offsetExists('text_reparser.pm_text_cron_interval'),
59
				array('config.add', array('text_reparser.pm_text_cron_interval', 10)),
60
			)),
61
			array('if', array(
62
				!$this->config->offsetExists('text_reparser.post_text_last_cron'),
63
				array('config.add', array('text_reparser.post_text_last_cron', 0)),
64
			)),
65
			array('if', array(
66
				!$this->config->offsetExists('text_reparser.post_text_cron_interval'),
67
				array('config.add', array('text_reparser.post_text_cron_interval', 10)),
68
			)),
69
			array('custom', array(array($this, 'reset_reparsers'))),
70
		);
71
	}
72
73
	/**
74
	 * Initialize post/pm reparsers
75
	 */
76
	public function reset_reparsers()
77
	{
78
		/** @var \phpbb\textreparser\manager $reparser_manager */
79
		$reparser_manager = $this->container->get('text_reparser.manager');
80
81
		/** @var \phpbb\di\service_collection $reparsers */
82
		$reparsers = $this->container->get('text_reparser_collection');
83
84
		/**
85
		 * @var string $name
86
		 * @var \phpbb\textreparser\reparser_interface $reparser
87
		 */
88
		foreach ($reparsers as $name => $reparser)
89
		{
90
			if (in_array($name, ['text_reparser.post_text', 'text_reparser.pm_text']))
91
			{
92
				$reparser_manager->update_resume_data($name, 1, $reparser->get_max_id(), 100);
93
			}
94
		}
95
	}
96
}
97