Task_DB_Structure_Dump::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
nc 1
cc 1
eloc 3
nop 0
1
<?php defined('SYSPATH') OR die('No direct script access.');
2
3
/**
4
 * Dump the current database structure to a file (migrations/schema.sql by default)
5
 *
6
 * options:
7
 *
8
 *  - database: the id of the database to dump from the config/database.php file, 'default' by default, configurable from config
9
 *  - file: file override the schema.sql file location to dump to another file
10
 */
11
class Task_DB_Structure_Dump extends Minion_Database {
12
13
	protected $_options = array(
14
		'database' => 'default',
15
		'file' => FALSE,
16
	);
17
18
    protected function __construct()
19
    {
20
        $this->_options['database'] = Kohana::$config->load("migrations.database");
21
        parent::__construct();
22
    }
23
24
    protected function _execute(array $options)
25
	{
26
		$db = $this->db_params($options['database']);
27
28
		$file = $options['file'] ? $options['file'] : Kohana::$config->load("migrations.path").DIRECTORY_SEPARATOR.'schema.sql';
29
		
30
		$command = strtr("mysqldump -u:username :password -h :hostname --skip-comments --add-drop-database --add-drop-table --no-data :database | sed 's/ AUTO_INCREMENT=[0-9]*\b//' > :file ", array(
31
			':username' => $db['username'],
32
			':password' => $db['password'] ? '-p'.$db['password'] : '',
33
			':database' => $db['database'],
34
			':hostname' => $db['hostname'],
35
			':file'     => $file
36
		));
37
38
		Minion_CLI::write(Minion_CLI::color('Saving structure of database "'.$db['database'].'" to '.Debug::path($file), 'green'));
39
40
		system($command);
41
	}
42
43
}
44