v320_m1_reparse::reparse()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 4
nop 1
dl 0
loc 21
rs 9.9
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * PayPal Donation extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2015-2020 Skouat
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace skouat\ppde\migrations\v32x;
12
13
class v320_m1_reparse extends \phpbb\db\migration\container_aware_migration
14
{
15
	/**
16
	 * @inheritDoc
17
	 */
18
	public static function depends_on()
19
	{
20
		return ['\skouat\ppde\migrations\v31x\v310_m3_currency_data'];
21
	}
22
23
	/**
24
	 * @inheritDoc
25
	 */
26
	public function update_data()
27
	{
28
		return [
29
			['custom', [[$this, 'reparse']]],
30
		];
31
	}
32
33
	/**
34
	 * Run the ppde donation pages text reparser
35
	 *
36
	 * @param int $current A donation page identifier
37
	 *
38
	 * @return bool|int A donation page identifier or true if finished
39
	 */
40
	public function reparse($current = 0)
41
	{
42
		$reparser = new \skouat\ppde\textreparser\plugins\donation_pages_text(
43
			$this->db,
44
			$this->container->getParameter('core.table_prefix') . 'ppde_donation_pages'
45
		);
46
47
		if (empty($current))
48
		{
49
			$current = $reparser->get_max_id();
50
		}
51
52
		$limit = 50; // Lets keep the reparsing conservative
53
		$start = max(1, $current + 1 - $limit);
54
		$end   = max(1, $current);
55
56
		$reparser->reparse_range($start, $end);
57
58
		$current = $start - 1;
59
60
		return ($current === 0) ? true : $current;
61
	}
62
}
63