1
0
Fork 0
mirror of https://github.com/Oreolek/kohana-migrations.git synced 2024-06-26 03:40:54 +03:00

refactoring some of the code to prevent some errors (refs #22)

This commit is contained in:
Lorenzo Pisani 2011-06-25 22:55:13 -07:00
parent 2cb4566e96
commit 5d3bf345ba

View file

@ -46,6 +46,14 @@ class Minion_Task_Db_Generate extends Minion_Task
*/
public function execute(array $config)
{
$defaults = array(
'location' => APPPATH,
'description' => '',
'group' => NULL,
);
$config = array_merge($defaults, $config);
if (empty($config['group']))
{
return 'Please provide --group'.PHP_EOL.
@ -54,11 +62,6 @@ class Minion_Task_Db_Generate extends Minion_Task
$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}
@ -115,8 +118,15 @@ class Minion_Task_Db_Generate extends Minion_Task
*/
public function _generate_filename($location, $group, $time, $description)
{
$description = substr(strtolower($description), 0, 100);
return $location.$group.$time.'_'.preg_replace('~[^a-z]+~', '-', $description).EXT;
// Max 100 characters, lowecase filenames.
$label = substr(strtolower($description), 0, 100);
// Only letters
$label = preg_replace('~[^a-z]+~', '-', $label);
// Add the location, group, and time
$filename = $location.$group.$time.'_'.$label;
// If description was empty, trim underscores
$filename = trim($filename, '_');
return $filename.EXT;
}
}