Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into common-docs
  • Loading branch information
MGatner committed Aug 28, 2019
2 parents 2450658 + 960310f commit c43d7d7
Show file tree
Hide file tree
Showing 29 changed files with 703 additions and 605 deletions.
15 changes: 15 additions & 0 deletions app/Common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* The goal of this file is to allow developers a location
* where they can overwrite core procedural functions and
* replace them with their own. This file is loaded during
* the bootstrap process and is called during the frameworks
* execution.
*
* This can be looked at as a `master helper` file that is
* loaded early on, and may also contain additional functions
* that you'd like to use throughout your entire application
*
* @link: https://codeigniter4.github.io/CodeIgniter4/
*/
8 changes: 6 additions & 2 deletions spark
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@ ini_set('display_errors', 1);
// Show basic information before we do anything else.
$console->showHeader();

// fire off the command the main framework.
$console->run();
// fire off the command in the main framework.
$response = $console->run();
if ($response->getStatusCode() >= 300)
{
exit($response->getStatusCode());
}
8 changes: 4 additions & 4 deletions system/Autoloader/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@ public function locateFile(string $file, string $folder = null, string $ext = 'p
$filename = implode('/', $segments);
break;
}

// if no namespaces matched then quit
if (empty($paths))
{
return false;
}

// Check each path in the namespace
foreach ($paths as $path)
{
// Ensure trailing slash
$path = rtrim($path, '/') . '/';

// If we have a folder name, then the calling function
// expects this file to be within that folder, like 'Views',
// or 'libraries'.
Expand All @@ -153,7 +153,7 @@ public function locateFile(string $file, string $folder = null, string $ext = 'p
return $path;
}
}

return false;
}

Expand Down
3 changes: 2 additions & 1 deletion system/CLI/CommandRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class CommandRunner extends Controller
* @param string $method
* @param array ...$params
*
* @return mixed
* @throws \ReflectionException
*/
public function _remap($method, ...$params)
Expand All @@ -81,7 +82,7 @@ public function _remap($method, ...$params)
array_shift($params);
}

$this->index($params);
return $this->index($params);
}

//--------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ protected function handleRequest(RouteCollectionInterface $routes = null, $cache
else
{
$response = $this->response;

// Set response code for CLI command failures
if (is_numeric($returned) || $returned === false)
{
$response->setStatusCode(400);
}
}

if ($response instanceof Response)
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Database/CreateMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function run(array $params = [])

if (! empty($ns))
{
// Get all namespaces form PSR4 paths.
// Get all namespaces from PSR4 paths.
$config = new Autoload();
$namespaces = $config->psr4;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
use Config\Services;

/**
* Creates a new migration file.
* Runs all new migrations.
*
* @package CodeIgniter\Commands
*/
class MigrateLatest extends BaseCommand
class Migrate extends BaseCommand
{
/**
* The group the command is lumped under
Expand All @@ -69,7 +69,7 @@ class MigrateLatest extends BaseCommand
*
* @var string
*/
protected $description = 'Migrates the database to the latest schema.';
protected $description = 'Locates and runs all new migrations against the database.';

/**
* the Command's usage
Expand All @@ -93,7 +93,7 @@ class MigrateLatest extends BaseCommand
protected $options = [
'-n' => 'Set migration namespace',
'-g' => 'Set database group',
'-all' => 'Set latest for all namespace, will ignore (-n) option',
'-all' => 'Set for all namespaces, will ignore (-n) option',
];

/**
Expand All @@ -104,22 +104,31 @@ class MigrateLatest extends BaseCommand
public function run(array $params = [])
{
$runner = Services::migrations();
$runner->clearCliMessages();

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

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

try
{
// Check for 'all' namespaces
if ($this->isAllNamespace($params))
{
$runner->latestAll($group);
$runner->setNamespace(null);
}
else
// Check for a specified namespace
elseif ($namespace)
{
$runner->latest($namespace, $group);
$runner->setNamespace($namespace);
}

if (! $runner->latest($group))
{
CLI::write(lang('Migrations.generalFault'), 'red');
}

$messages = $runner->getCliMessages();
foreach ($messages as $message)
{
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Database/MigrateRefresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class MigrateRefresh extends BaseCommand
*/
public function run(array $params = [])
{
$this->call('migrate:rollback', ['-b' => 1]);
$this->call('migrate:rollback', ['-b' => 0]);
$this->call('migrate');
}

Expand Down
18 changes: 10 additions & 8 deletions system/Commands/Database/MigrateRollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class MigrateRollback extends BaseCommand
*
* @var string
*/
protected $description = 'Runs the down method for all migrations in the last batch.';
protected $description = 'Runs the "down" method for all migrations in the last batch.';

/**
* the Command's usage
Expand All @@ -94,7 +94,7 @@ class MigrateRollback extends BaseCommand
* @var array
*/
protected $options = [
'-b' => 'Specify a batch to roll back to',
'-b' => 'Specify a batch to roll back to; e.g. "3" to return to batch #3 or "-2" to roll back twice',
'-g' => 'Set database group',
];

Expand All @@ -108,8 +108,6 @@ public function run(array $params = [])
{
$runner = Services::migrations();

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

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

if (! is_null($group))
Expand All @@ -119,10 +117,14 @@ public function run(array $params = [])

try
{
$batch = $params['-b'] ?? $runner->getLastBatch();

$runner->version($runner->getBatchStart($batch));

$batch = $params['-b'] ?? CLI::getOption('b') ?? $runner->getLastBatch() - 1;
CLI::write(lang('Migrations.rollingBack') . ' ' . $batch, 'yellow');

if (! $runner->regress($batch))
{
CLI::write(lang('Migrations.generalFault'), 'red');
}

$messages = $runner->getCliMessages();
foreach ($messages as $message)
{
Expand Down
7 changes: 4 additions & 3 deletions system/Commands/Database/MigrateStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,18 @@ public function run(array $params = [])

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

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

if ($runner->getObjectUid($row) !== $uid)
{
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 : '---'));
}
Expand Down
140 changes: 0 additions & 140 deletions system/Commands/Database/MigrateVersion.php

This file was deleted.

Loading

0 comments on commit c43d7d7

Please sign in to comment.