Skip to content

Commit c43d7d7

Browse files
committed
Merge branch 'develop' of https://github.com/codeigniter4/CodeIgniter4 into common-docs
2 parents 2450658 + 960310f commit c43d7d7

29 files changed

Lines changed: 703 additions & 605 deletions

app/Common.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
/**
4+
* The goal of this file is to allow developers a location
5+
* where they can overwrite core procedural functions and
6+
* replace them with their own. This file is loaded during
7+
* the bootstrap process and is called during the frameworks
8+
* execution.
9+
*
10+
* This can be looked at as a `master helper` file that is
11+
* loaded early on, and may also contain additional functions
12+
* that you'd like to use throughout your entire application
13+
*
14+
* @link: https://codeigniter4.github.io/CodeIgniter4/
15+
*/

spark

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,9 @@ ini_set('display_errors', 1);
5353
// Show basic information before we do anything else.
5454
$console->showHeader();
5555

56-
// fire off the command the main framework.
57-
$console->run();
56+
// fire off the command in the main framework.
57+
$response = $console->run();
58+
if ($response->getStatusCode() >= 300)
59+
{
60+
exit($response->getStatusCode());
61+
}

system/Autoloader/FileLocator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,19 @@ public function locateFile(string $file, string $folder = null, string $ext = 'p
126126
$filename = implode('/', $segments);
127127
break;
128128
}
129-
129+
130130
// if no namespaces matched then quit
131131
if (empty($paths))
132132
{
133133
return false;
134134
}
135-
135+
136136
// Check each path in the namespace
137137
foreach ($paths as $path)
138138
{
139139
// Ensure trailing slash
140140
$path = rtrim($path, '/') . '/';
141-
141+
142142
// If we have a folder name, then the calling function
143143
// expects this file to be within that folder, like 'Views',
144144
// or 'libraries'.
@@ -153,7 +153,7 @@ public function locateFile(string $file, string $folder = null, string $ext = 'p
153153
return $path;
154154
}
155155
}
156-
156+
157157
return false;
158158
}
159159

system/CLI/CommandRunner.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class CommandRunner extends Controller
7171
* @param string $method
7272
* @param array ...$params
7373
*
74+
* @return mixed
7475
* @throws \ReflectionException
7576
*/
7677
public function _remap($method, ...$params)
@@ -81,7 +82,7 @@ public function _remap($method, ...$params)
8182
array_shift($params);
8283
}
8384

84-
$this->index($params);
85+
return $this->index($params);
8586
}
8687

8788
//--------------------------------------------------------------------

system/CodeIgniter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@ protected function handleRequest(RouteCollectionInterface $routes = null, $cache
355355
else
356356
{
357357
$response = $this->response;
358+
359+
// Set response code for CLI command failures
360+
if (is_numeric($returned) || $returned === false)
361+
{
362+
$response->setStatusCode(400);
363+
}
358364
}
359365

360366
if ($response instanceof Response)

system/Commands/Database/CreateMigration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function run(array $params = [])
123123

124124
if (! empty($ns))
125125
{
126-
// Get all namespaces form PSR4 paths.
126+
// Get all namespaces from PSR4 paths.
127127
$config = new Autoload();
128128
$namespaces = $config->psr4;
129129

system/Commands/Database/MigrateLatest.php renamed to system/Commands/Database/Migrate.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@
4343
use Config\Services;
4444

4545
/**
46-
* Creates a new migration file.
46+
* Runs all new migrations.
4747
*
4848
* @package CodeIgniter\Commands
4949
*/
50-
class MigrateLatest extends BaseCommand
50+
class Migrate extends BaseCommand
5151
{
5252
/**
5353
* The group the command is lumped under
@@ -69,7 +69,7 @@ class MigrateLatest extends BaseCommand
6969
*
7070
* @var string
7171
*/
72-
protected $description = 'Migrates the database to the latest schema.';
72+
protected $description = 'Locates and runs all new migrations against the database.';
7373

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

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

108-
CLI::write(lang('Migrations.toLatest'), 'yellow');
109+
CLI::write(lang('Migrations.latest'), 'yellow');
109110

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

113114
try
114115
{
116+
// Check for 'all' namespaces
115117
if ($this->isAllNamespace($params))
116118
{
117-
$runner->latestAll($group);
119+
$runner->setNamespace(null);
118120
}
119-
else
121+
// Check for a specified namespace
122+
elseif ($namespace)
120123
{
121-
$runner->latest($namespace, $group);
124+
$runner->setNamespace($namespace);
122125
}
126+
127+
if (! $runner->latest($group))
128+
{
129+
CLI::write(lang('Migrations.generalFault'), 'red');
130+
}
131+
123132
$messages = $runner->getCliMessages();
124133
foreach ($messages as $message)
125134
{

system/Commands/Database/MigrateRefresh.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class MigrateRefresh extends BaseCommand
104104
*/
105105
public function run(array $params = [])
106106
{
107-
$this->call('migrate:rollback', ['-b' => 1]);
107+
$this->call('migrate:rollback', ['-b' => 0]);
108108
$this->call('migrate');
109109
}
110110

system/Commands/Database/MigrateRollback.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class MigrateRollback extends BaseCommand
7272
*
7373
* @var string
7474
*/
75-
protected $description = 'Runs the down method for all migrations in the last batch.';
75+
protected $description = 'Runs the "down" method for all migrations in the last batch.';
7676

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

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

111-
CLI::write(lang('Migrations.rollingBack'), 'yellow');
112-
113111
$group = $params['-g'] ?? CLI::getOption('g');
114112

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

120118
try
121119
{
122-
$batch = $params['-b'] ?? $runner->getLastBatch();
123-
124-
$runner->version($runner->getBatchStart($batch));
125-
120+
$batch = $params['-b'] ?? CLI::getOption('b') ?? $runner->getLastBatch() - 1;
121+
CLI::write(lang('Migrations.rollingBack') . ' ' . $batch, 'yellow');
122+
123+
if (! $runner->regress($batch))
124+
{
125+
CLI::write(lang('Migrations.generalFault'), 'red');
126+
}
127+
126128
$messages = $runner->getCliMessages();
127129
foreach ($messages as $message)
128130
{

system/Commands/Database/MigrateStatus.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,18 @@ public function run(array $params = [])
160160

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

163-
foreach ($migrations as $version => $migration)
163+
foreach ($migrations as $uid => $migration)
164164
{
165165
$date = '';
166166
foreach ($history as $row)
167167
{
168-
if ($row['version'] !== $version)
168+
169+
if ($runner->getObjectUid($row) !== $uid)
169170
{
170171
continue;
171172
}
172173

173-
$date = date('Y-m-d H:i:s', $row['time']);
174+
$date = date('Y-m-d H:i:s', $row->time);
174175
}
175176
CLI::write(str_pad(' ' . $migration->name, $max + 6) . ($date ? $date : '---'));
176177
}

0 commit comments

Comments
 (0)