Completed
Branch release-3.2.0 (10f575)
by Daniel
03:11
created

m15_reparse_cblocks_data   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 49
rs 10
wmc 5
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2013 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\migrations\v30x;
11
12
/**
13
 * Initial schema changes needed for Extension installation
14
 */
15
class m15_reparse_cblocks_data extends \phpbb\db\migration\migration
16
{
17
	/**
18
	 * @inheritdoc
19
	 */
20
	public static function depends_on()
21
	{
22
		return array(
23
			'\blitze\sitemaker\migrations\v20x\m5_add_cblocks_schema',
24
		);
25
	}
26
27
	/**
28
	 * @inheritDoc
29
	 */
30
	public function update_data()
31
	{
32
		return array(
33
			array('custom', array(array($this, 'reparse'))),
34
		);
35
	}
36
37
	/**
38
	 * Run the custom block text reparser (see boardrules extension)
39
	 *
40
	 * @param int $current A custom block identifier
41
	 * @return bool|int A custom block identifier or true if finished
42
	 */
43
	public function reparse($current = 0)
44
	{
45
		$reparser = new \blitze\sitemaker\migrations\v30x\textreparser\plugins\custom_block_text(
46
			$this->db,
47
			$this->table_prefix . 'sm_cblocks'
48
		);
49
50
		if (empty($current))
51
		{
52
			$current = $reparser->get_max_id();
53
		}
54
55
		$limit = 50; // lets keep the reparsing conservative
56
		$start = max(1, $current + 1 - $limit);
57
		$end   = max(1, $current);
58
59
		$reparser->reparse_range($start, $end);
60
61
		$current = $start - 1;
62
63
		return ($current === 0) ? true : $current;
64
	}
65
}
66