Task_DB_Migrate::_execute()   C
last analyzed

Complexity

Conditions 8
Paths 3

Size

Total Lines 34
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 5.3846
c 0
b 0
f 0
nc 3
cc 8
eloc 17
nop 1
1
<?php defined('SYSPATH') OR die('No direct script access.');
2
3
/**
4
 * Execute all unexecuted migrations. Behavior changes when supplied any of the parameters
5
 *
6
 * options:
7
 *  - version: set which version you want to go to. Will execute nessesary migrations to reach this version (up or down)
8
 *  - steps: how many migrations to execute before stopping. works for both up and down.
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 extends Minion_Migration {
12
13
	protected function _execute(array $options)
14
	{
15
		$executed = $this->executed_migrations();
16
		$unexecuted = $this->unexecuted_migrations();
17
		$all = $this->all_migrations();
18
19
		$up = array();
20
		$down = array();
21
22
		if ($options['version'])
23
		{
24
			foreach ($all as $migration)
25
			{
26
				if ( ! in_array($migration, $executed) AND $migration <= $options['version'])
27
				{
28
					$up[] = $migration;
29
				}
30
				if (in_array($migration, $executed) AND $migration > $options['version'])
31
				{
32
					$down[] = $migration;
33
				}
34
			}
35
		}
36
		elseif ($options['steps'])
37
		{
38
			$up = array_slice($unexecuted, 0, $options['steps']);
39
		}
40
		else
41
		{
42
			$up = $unexecuted;
43
		}
44
45
		$this->migrate($up, $down, $options['dry-run'] === NULL);
46
	}
47
}
48