Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't call run() method with params from commands migrations. #1431

Merged
merged 2 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions system/Commands/Database/CreateMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ class CreateMigration extends BaseCommand
/**
* Creates a new migration file with the current timestamp.
*
* @todo Have this check the settings and see what type of file it should create (timestamp or sequential)
*
* @param array $params
*/
public function run(array $params = [])
Expand All @@ -117,7 +115,7 @@ public function run(array $params = [])
CLI::error(lang('Migrations.badCreateName'));
return;
}
$ns = CLI::getOption('n');
$ns = $params['-n'] ?? CLI::getOption('n');
$homepath = APPPATH;

if (! empty($ns))
Expand Down
21 changes: 10 additions & 11 deletions system/Commands/Database/MigrateCurrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 3.0.0
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 3.0.0
* @filesource
*/

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use Config\Services;
Expand Down Expand Up @@ -104,7 +105,7 @@ public function run(array $params = [])

CLI::write(lang('Migrations.toVersion'), 'yellow');

$group = CLI::getOption('g');
$group = $params['-g'] ?? CLI::getOption('g');
try
{
$runner->current($group);
Expand All @@ -115,13 +116,11 @@ public function run(array $params = [])
}

CLI::write('Done');

} catch (\Exception $e)
}
catch (\Exception $e)
{
$this->showError($e);
}


}

}
47 changes: 33 additions & 14 deletions system/Commands/Database/MigrateLatest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 3.0.0
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 3.0.0
* @filesource
*/

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use Config\Services;
Expand Down Expand Up @@ -88,9 +89,9 @@ class MigrateLatest extends BaseCommand
* @var array
*/
protected $options = [
'-n' => 'Set migration namespace',
'-g' => 'Set database group',
'-all' => 'Set latest for all namespace, will ignore (-n) option',
'-n' => 'Set migration namespace',
'-g' => 'Set database group',
'-all' => 'Set latest for all namespace, will ignore (-n) option',
];

/**
Expand All @@ -104,12 +105,12 @@ public function run(array $params = [])

CLI::write(lang('Migrations.toLatest'), 'yellow');

$namespace = CLI::getOption('n');
$group = CLI::getOption('g');
$namespace = $params['-n'] ?? CLI::getOption('n');
$group = $params['-g'] ?? CLI::getOption('g');

try
{
if ( ! is_null(CLI::getOption('all')))
if ($this->isAllNamespace($params))
{
$runner->latestAll($group);
}
Expand All @@ -124,13 +125,31 @@ public function run(array $params = [])
}

CLI::write('Done');

} catch (\Exception $e)
}
catch (\Exception $e)
{
$this->showError($e);
}
}

/**
* To migrate all namespaces to the latest migration
*
* Demo:
* 1. command line: php spark migrate:latest -all
* 2. command file: $this->call('migrate:latest', ['-g' => 'test','-all']);
*
* @param array $params
* @return boolean
*/
private function isAllNamespace(array $params)
{
if (array_search('-all', $params) !== false)
{
return true;
}

return ! is_null(CLI::getOption('all'));
}

}
53 changes: 37 additions & 16 deletions system/Commands/Database/MigrateRollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 3.0.0
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 3.0.0
* @filesource
*/

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use Config\Services;
Expand Down Expand Up @@ -91,9 +92,9 @@ class MigrateRollback extends BaseCommand
* @var array
*/
protected $options = [
'-n' => 'Set migration namespace',
'-g' => 'Set database group',
'-all' => 'Set latest for all namespace, will ignore (-n) option',
'-n' => 'Set migration namespace',
'-g' => 'Set database group',
'-all' => 'Set latest for all namespace, will ignore (-n) option',
];

/**
Expand All @@ -107,22 +108,24 @@ public function run(array $params = [])
$runner = Services::migrations();

CLI::write(lang('Migrations.rollingBack'), 'yellow');
$group = CLI::getOption('g');
if ( ! is_null($group))

$group = $params['-g'] ?? CLI::getOption('g');

if (! is_null($group))
{
$runner->setGroup($group);
}
try
{
if (is_null(CLI::getOption('all')))
if (! $this->isAllNamespace())
{
$namespace = CLI::getOption('n');
$namespace = $params['-n'] ?? CLI::getOption('n');
$runner->version(0, $namespace);
}
else
{
// Get all namespaces form PSR4 paths.
$config = new Autoload();
$config = new Autoload();
$namespaces = $config->psr4;
foreach ($namespaces as $namespace => $path)
{
Expand All @@ -142,13 +145,31 @@ public function run(array $params = [])
}

CLI::write('Done');

} catch (\Exception $e)
}
catch (\Exception $e)
{
$this->showError($e);
}
}

/**
* To migrate all namespaces to the latest migration
*
* Demo:
* 1. command line: php spark migrate:latest -all
* 2. command file: $this->call('migrate:latest', ['-g' => 'test','-all']);
*
* @param array $params
* @return boolean
*/
private function isAllNamespace(array $params)
{
if (array_search('-all', $params) !== false)
{
return true;
}

return ! is_null(CLI::getOption('all'));
}

}
36 changes: 19 additions & 17 deletions system/Commands/Database/MigrateStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 3.0.0
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 3.0.0
* @filesource
*/

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use Config\Services;
Expand Down Expand Up @@ -96,7 +97,7 @@ class MigrateStatus extends BaseCommand
protected $ignoredNamespaces = [
'CodeIgniter',
'Config',
'Tests\Support'
'Tests\Support',
];

/**
Expand All @@ -108,13 +109,15 @@ public function run(array $params = [])
{
$runner = Services::migrations();

if ( ! is_null(CLI::getOption('g')))
$group = $params['-g'] ?? CLI::getOption('g');

if (! is_null($group))
{
$runner->setGroup(CLI::getOption('g'));
$runner->setGroup($group);
}

// Get all namespaces form PSR4 paths.
$config = new Autoload();
$config = new Autoload();
$namespaces = $config->psr4;

// Loop for all $namespaces
Expand All @@ -127,7 +130,7 @@ public function run(array $params = [])

$runner->setNamespace($namespace);
$migrations = $runner->findMigrations();
$history = $runner->getHistory();
$history = $runner->getHistory();

CLI::write($namespace);

Expand All @@ -142,28 +145,27 @@ public function run(array $params = [])
$max = 0;
foreach ($migrations as $version => $migration)
{
$file = substr($migration->name, strpos($migration->name, $version . '_'));
$file = substr($migration->name, strpos($migration->name, $version . '_'));
$migrations[$version]->name = $file;

$max = max($max, strlen($file));
}

CLI::write(' '. str_pad(lang('Migrations.filename'), $max + 4) . lang('Migrations.on'), 'yellow');

CLI::write(' ' . str_pad(lang('Migrations.filename'), $max + 4) . lang('Migrations.on'), 'yellow');

foreach ($migrations as $version => $migration)
{
$date = '';
foreach ($history as $row)
{
if ($row['version'] != $version)
if ($row['version'] !== $version)
{
continue;
}

$date = date("Y-m-d H:i:s", $row['time']);
$date = date('Y-m-d H:i:s', $row['time']);
}
CLI::write(str_pad(' '.$migration->name, $max + 6) . ($date ? $date : '---'));
CLI::write(str_pad(' ' . $migration->name, $max + 6) . ($date ? $date : '---'));
}
}
}
Expand Down
23 changes: 12 additions & 11 deletions system/Commands/Database/MigrateVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 3.0.0
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 3.0.0
* @filesource
*/

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use Config\Services;
Expand Down Expand Up @@ -120,18 +121,18 @@ public function run(array $params = [])

CLI::write(sprintf(lang('Migrations.toVersionPH'), $version), 'yellow');

$namespace = CLI::getOption('n');
$group = CLI::getOption('g');
$namespace = $params['-n'] ?? CLI::getOption('n');
$group = $params['-g'] ?? CLI::getOption('g');

try
{
$runner->version($version, $namespace, $group);
CLI::write('Done');
} catch (\Exception $e)
}
catch (\Exception $e)
{
$this->showError($e);
}


}

}
Loading