Task_DB_Migrate_Redo::_execute()   B
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 30
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 8.5806
c 0
b 0
f 0
nc 6
cc 4
eloc 14
nop 1
1
<?php defined('SYSPATH') OR die('No direct script access.');
2
3
/**
4
 * Migrate down then up one migration. Behavior changes when supplied any of the parameters
5
 *
6
 * options:
7
 *  - version: migrate all the way down to the specified migration, and then all the way back up.
8
 *  - steps: how many times to migrate down before going back up.
9
 *  - dry-run: if this flag is set, will run the migration without accually touching the database, only showing the result.
10
 */
11
class Task_DB_Migrate_Redo extends Minion_Migration {
12
13
	protected $_options = array(
14
		'version' => NULL,
15
		'steps' => 1,
16
		'dry-run' => FALSE
17
	);
18
19
	protected function _execute(array $options)
20
	{
21
		$executed = $this->executed_migrations();
22
23
		$up = array();
24
		$down = array();
25
26
		if (isset($options['version']))
27
		{
28
			if (in_array($options['version'], $executed))
29
			{
30
				$down[] = $options['version'];
31
			}
32
		}
33
		else
34
		{
35
			$down = array_slice($executed, 0, $options['steps']);
36
		}
37
38
		if (isset($options['version']))
39
		{
40
			$up[] = $options['version'];
41
		}
42
		else
43
		{
44
			$up = array_reverse($down);
45
		}
46
47
		$this->migrate($up, $down, $options['dry-run'] === NULL);
48
	}
49
}
50