mirror of
https://github.com/Oreolek/kohana-migrations.git
synced 2024-05-18 17:08:18 +03:00
Merge remote branch 'remotes/d4rky/develop' into develop
This commit is contained in:
commit
2cb4566e96
|
@ -35,7 +35,8 @@ class Minion_Task_Db_Generate extends Minion_Task
|
|||
*/
|
||||
protected $_config = array(
|
||||
'group',
|
||||
'description'
|
||||
'description',
|
||||
'location'
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -45,19 +46,25 @@ class Minion_Task_Db_Generate extends Minion_Task
|
|||
*/
|
||||
public function execute(array $config)
|
||||
{
|
||||
if (empty($config['group']) OR empty($config['description']))
|
||||
if (empty($config['group']))
|
||||
{
|
||||
return 'Please provide --group and --description'.PHP_EOL.
|
||||
return 'Please provide --group'.PHP_EOL.
|
||||
'See help for more info'.PHP_EOL;
|
||||
}
|
||||
|
||||
$group = rtrim(realpath($config['group']), '/').'/';
|
||||
$group = $config['group'].'/';
|
||||
$description = $config['description'];
|
||||
|
||||
if (empty($config['location']))
|
||||
{
|
||||
$config['location'] = APPPATH;
|
||||
}
|
||||
$location = rtrim(realpath($config['location']), '/').'/migrations/';
|
||||
|
||||
// {year}{month}{day}{hour}{minute}{second}
|
||||
$time = date('YmdHis');
|
||||
$class = $this->_generate_classname($group, $time);
|
||||
$file = $this->_generate_filename($group, $time, $description);
|
||||
$file = $this->_generate_filename($location, $group, $time, $description);
|
||||
|
||||
|
||||
$data = Kohana::FILE_SECURITY.View::factory('minion/task/db/generate/template')
|
||||
|
@ -65,6 +72,11 @@ class Minion_Task_Db_Generate extends Minion_Task
|
|||
->set('description', $description)
|
||||
->render();
|
||||
|
||||
if ( ! is_dir(dirname($file)))
|
||||
{
|
||||
mkdir(dirname($file), 0775, TRUE);
|
||||
}
|
||||
|
||||
file_put_contents($file, $data);
|
||||
|
||||
return 'Migration generated in '.$file.PHP_EOL;
|
||||
|
@ -79,9 +91,6 @@ class Minion_Task_Db_Generate extends Minion_Task
|
|||
*/
|
||||
protected function _generate_classname($group, $time)
|
||||
{
|
||||
// Chop up everything up until the relative path
|
||||
$group = substr($group, strrpos($group, 'migrations/') + 11);
|
||||
|
||||
$class = ucwords(str_replace('/', ' ', $group));
|
||||
|
||||
// If group is empty then we want to avoid double underscore in the
|
||||
|
@ -104,11 +113,10 @@ class Minion_Task_Db_Generate extends Minion_Task
|
|||
* @param string Description
|
||||
* @return string Filename
|
||||
*/
|
||||
public function _generate_filename($group, $time, $description)
|
||||
public function _generate_filename($location, $group, $time, $description)
|
||||
{
|
||||
$description = substr(strtolower($description), 0, 100);
|
||||
|
||||
return $group.$time.'_'.preg_replace('~[^a-z]+~', '-', $description).EXT;
|
||||
return $location.$group.$time.'_'.preg_replace('~[^a-z]+~', '-', $description).EXT;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ return array(
|
|||
'group_connection' => array(
|
||||
|
||||
),
|
||||
|
||||
/**
|
||||
* This specifies which migration should be the "base", in timestamp form.
|
||||
* This migration will not be run when --migrate-down is called
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
|
||||
<?php if(!empty($description)): ?>
|
||||
/**
|
||||
* <?php echo $description.PHP_EOL; ?>
|
||||
*/
|
||||
<?php endif; ?>
|
||||
class <?php echo $class; ?> extends Minion_Migration_Base {
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue