Skip to content

Commit 8eb88b7

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.8
2 parents 83722be + 9a75151 commit 8eb88b7

36 files changed

Lines changed: 959 additions & 407 deletions

‎composer.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"psr/log": "^3.0"
1818
},
1919
"require-dev": {
20-
"boundwize/structarmed": "0.14.6",
20+
"boundwize/structarmed": "0.14.10",
2121
"codeigniter/phpstan-codeigniter": "^2.1",
2222
"fakerphp/faker": "^1.24",
2323
"kint-php/kint": "^6.1",
@@ -29,7 +29,7 @@
2929
"phpunit/phpcov": "^9.0.2 || ^10.0",
3030
"phpunit/phpunit": "^10.5.16 || ^11.2",
3131
"predis/predis": "^3.0",
32-
"rector/rector": "2.5.2",
32+
"rector/rector": "2.5.3",
3333
"shipmonk/phpstan-baseline-per-identifier": "^2.0"
3434
},
3535
"replace": {

‎rector.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313

1414
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
15+
use Rector\CodeQuality\Rector\BooleanNot\NegatedAndsToPositiveOrsRector;
1516
use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
1617
use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector;
1718
use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
@@ -22,6 +23,7 @@
2223
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
2324
use Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector;
2425
use Rector\Config\RectorConfig;
26+
use Rector\DeadCode\Rector\ClassMethod\RemoveDuplicatedReturnSelfDocblockRector;
2527
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector;
2628
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
2729
use Rector\DeadCode\Rector\MethodCall\RemoveNullArgOnNullDefaultParamRector;
@@ -35,7 +37,6 @@
3537
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
3638
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
3739
use Rector\PHPUnit\CodeQuality\Rector\StmtsAwareInterface\DeclareStrictTypesTestsRector;
38-
use Rector\PostRector\Rector\UnusedImportRemovingPostRector;
3940
use Rector\Privatization\Rector\Class_\FinalizeTestCaseClassRector;
4041
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
4142
use Rector\Renaming\Rector\ConstFetch\RenameConstantRector;
@@ -172,10 +173,9 @@
172173
__DIR__ . '/tests/system/Models',
173174
],
174175

175-
UnusedImportRemovingPostRector::class => [
176-
// buggy on auto import removed
177-
__DIR__ . '/system/HTTP/Response.php',
178-
],
176+
// to be applied in separate PRs to ease review
177+
NegatedAndsToPositiveOrsRector::class,
178+
RemoveDuplicatedReturnSelfDocblockRector::class,
179179
])
180180
// auto import fully qualified class names
181181
->withImportNames()

‎system/CLI/CLI.php‎

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ public static function input(?string $prefix = null): string
196196
* // Do not provide options but requires a valid email
197197
* $email = CLI::prompt('What is your email?', null, 'required|valid_email');
198198
*
199-
* @param string $field Output "field" question
200-
* @param list<int|string>|string $options String to a default value, array to a list of options (the first option will be the default value)
201-
* @param array|string|null $validation Validation rules
199+
* @param string $field Output "field" question
200+
* @param list<int|string>|string $options String to a default value, array to a list of options (the first option will be the default value)
201+
* @param list<string>|string|null $validation Validation rules
202202
*
203203
* @return string The user input
204204
*/
@@ -255,10 +255,10 @@ public static function prompt(string $field, $options = null, $validation = null
255255
/**
256256
* prompt(), but based on the option's key
257257
*
258-
* @param array|string $text Output "field" text or an one or two value array where the first value is the text before listing the options
259-
* and the second value the text before asking to select one option. Provide empty string to omit
260-
* @param array $options A list of options (array(key => description)), the first option will be the default value
261-
* @param array|string|null $validation Validation rules
258+
* @param list<string>|string $text Output "field" text or an one or two value array where the first value is the text before listing the options
259+
* and the second value the text before asking to select one option. Provide empty string to omit
260+
* @param array<int|string, string> $options A list of options (array(key => description)), the first option will be the default value
261+
* @param list<string>|string|null $validation Validation rules
262262
*
263263
* @return string The selected key of $options
264264
*/
@@ -284,11 +284,11 @@ public static function promptByKey($text, array $options, $validation = null): s
284284
/**
285285
* This method is the same as promptByKey(), but this method supports multiple keys, separated by commas.
286286
*
287-
* @param string $text Output "field" text or an one or two value array where the first value is the text before listing the options
288-
* and the second value the text before asking to select one option. Provide empty string to omit
289-
* @param array $options A list of options (array(key => description)), the first option will be the default value
287+
* @param string $text Output "field" text or an one or two value array where the first value is the text before listing the options
288+
* and the second value the text before asking to select one option. Provide empty string to omit
289+
* @param array<int|string, string> $options A list of options (array(key => description)), the first option will be the default value
290290
*
291-
* @return array The selected key(s) and value(s) of $options
291+
* @return array<int|string, string> The selected key(s) and value(s) of $options
292292
*/
293293
public static function promptByMultipleKeys(string $text, array $options): array
294294
{
@@ -357,6 +357,8 @@ public static function promptByMultipleKeys(string $text, array $options): array
357357

358358
/**
359359
* Validation for $options in promptByKey() and promptByMultipleKeys(). Return an error if $options is an empty array.
360+
*
361+
* @param array<int|string, string> $options
360362
*/
361363
private static function isZeroOptions(array $options): void
362364
{
@@ -367,6 +369,8 @@ private static function isZeroOptions(array $options): void
367369

368370
/**
369371
* Print each key and value one by one
372+
*
373+
* @param array<int|string, string> $options
370374
*/
371375
private static function printKeysAndValues(array $options): void
372376
{
@@ -386,9 +390,9 @@ private static function printKeysAndValues(array $options): void
386390
/**
387391
* Validate one prompt "field" at a time
388392
*
389-
* @param string $field Prompt "field" output
390-
* @param string $value Input value
391-
* @param array|string $rules Validation rules
393+
* @param string $field Prompt "field" output
394+
* @param string $value Input value
395+
* @param list<string>|string $rules Validation rules
392396
*/
393397
protected static function validate(string $field, string $value, $rules): bool
394398
{
@@ -1027,8 +1031,8 @@ public static function getOptionString(bool $useLongOpts = false, bool $trim = f
10271031
/**
10281032
* Returns a well formatted table
10291033
*
1030-
* @param array $tbody List of rows
1031-
* @param array $thead List of columns
1034+
* @param list<array<int|string, mixed>> $tbody List of rows
1035+
* @param list<string> $thead List of columns
10321036
*
10331037
* @return void
10341038
*/

‎system/Common.php‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,21 @@ function command(string $command)
169169
// Prepend an application name, as Console expects one.
170170
array_unshift($tokens, 'spark');
171171

172+
$bufferLevel = ob_get_level();
173+
172174
try {
173175
ob_start();
174176
(new Console())->run($tokens);
175177

178+
if (ob_get_level() <= $bufferLevel) {
179+
return false;
180+
}
181+
176182
return ob_get_contents();
177183
} finally {
178-
ob_end_clean();
184+
while (ob_get_level() > $bufferLevel) {
185+
ob_end_clean();
186+
}
179187
}
180188
}
181189
}

‎system/Database/BaseBuilder.php‎

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3332,7 +3332,7 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
33323332
$sql .= 'WHERE ' . implode(
33333333
' AND ',
33343334
array_map(
3335-
static fn ($key, $value) => (
3335+
static fn ($key, $value): RawSql|string => (
33363336
($value instanceof RawSql && is_string($key))
33373337
?
33383338
$table . '.' . $key . ' = ' . $value
@@ -3560,7 +3560,7 @@ protected function _deleteBatch(string $table, array $keys, array $values): stri
35603560
$sql .= 'ON ' . implode(
35613561
' AND ',
35623562
array_map(
3563-
static fn ($key, $value) => (
3563+
static fn ($key, $value): RawSql|string => (
35643564
$value instanceof RawSql ?
35653565
$value :
35663566
(
@@ -3575,11 +3575,7 @@ protected function _deleteBatch(string $table, array $keys, array $values): stri
35753575
);
35763576

35773577
// convert binds in where
3578-
foreach ($this->QBWhere as $key => $where) {
3579-
foreach ($this->binds as $field => $bind) {
3580-
$this->QBWhere[$key]['condition'] = str_replace(':' . $field . ':', $bind[0], $where['condition']);
3581-
}
3582-
}
3578+
$this->convertWhereBindsForBatch();
35833579

35843580
$sql .= ' ' . $this->compileWhereHaving('QBWhere');
35853581

@@ -3605,6 +3601,35 @@ protected function _deleteBatch(string $table, array $keys, array $values): stri
36053601
return str_replace('{:_table_:}', $data, $sql);
36063602
}
36073603

3604+
/**
3605+
* Escapes and substitutes the WHERE binds into the QBWhere conditions
3606+
* for batch delete queries.
3607+
*
3608+
* The bound values respect their escape flag and are escaped the same way
3609+
* as a regular query (see Query::matchNamedBinds()), instead of being
3610+
* injected into the SQL as raw, unescaped values.
3611+
*
3612+
* @used-by _deleteBatch()
3613+
*/
3614+
protected function convertWhereBindsForBatch(): void
3615+
{
3616+
$replacers = [];
3617+
3618+
foreach ($this->binds as $field => $bind) {
3619+
$escapedValue = $bind[1] ? $this->db->escape($bind[0]) : $bind[0];
3620+
3621+
if (is_array($bind[0])) {
3622+
$escapedValue = '(' . implode(',', $escapedValue) . ')';
3623+
}
3624+
3625+
$replacers[':' . $field . ':'] = (string) $escapedValue;
3626+
}
3627+
3628+
foreach ($this->QBWhere as $key => $where) {
3629+
$this->QBWhere[$key]['condition'] = strtr($where['condition'], $replacers);
3630+
}
3631+
}
3632+
36083633
/**
36093634
* Increments a numeric column by the specified value.
36103635
*

‎system/Database/Forge.php‎

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,10 @@ protected function _processIndexes(string $table, bool $asQuery = false): array
11981198
*/
11991199
protected function _processForeignKeys(string $table, bool $asQuery = false): array
12001200
{
1201+
if ($this->foreignKeys === []) {
1202+
return [''];
1203+
}
1204+
12011205
$errorNames = [];
12021206

12031207
foreach ($this->foreignKeys as $fkeyInfo) {
@@ -1214,40 +1218,43 @@ protected function _processForeignKeys(string $table, bool $asQuery = false): ar
12141218
throw new DatabaseException(lang('Database.fieldNotExists', $errorNames));
12151219
}
12161220

1217-
$sqls = [''];
1218-
1219-
foreach ($this->foreignKeys as $index => $fkey) {
1220-
if ($asQuery === false) {
1221-
$index = 0;
1222-
} else {
1223-
$sqls[$index] = '';
1224-
}
1221+
$sqls = [''];
1222+
$isOci8 = $this->db->DBDriver === 'OCI8';
1223+
$dbPrefix = $this->db->DBPrefix;
1224+
$fkSuffix = $isOci8 ? '_fk' : '_foreign';
12251225

1226-
$nameIndex = $fkey['fkName'] !== '' ?
1227-
$fkey['fkName'] :
1228-
$table . '_' . implode('_', $fkey['field']) . ($this->db->DBDriver === 'OCI8' ? '_fk' : '_foreign');
1226+
$prefixSql = $asQuery
1227+
? 'ALTER TABLE ' . $this->db->escapeIdentifiers($dbPrefix . $table) . ' ADD '
1228+
: ",\n\t";
12291229

1230-
$nameIndexFilled = $this->db->escapeIdentifiers($nameIndex);
1231-
$foreignKeyFilled = implode(', ', $this->db->escapeIdentifiers($fkey['field']));
1232-
$referenceTableFilled = $this->db->escapeIdentifiers($this->db->DBPrefix . $fkey['referenceTable']);
1233-
$referenceFieldFilled = implode(', ', $this->db->escapeIdentifiers($fkey['referenceField']));
1230+
foreach ($this->foreignKeys as $index => $fkey) {
1231+
$idx = $asQuery ? $index : 0;
12341232

12351233
if ($asQuery) {
1236-
$sqls[$index] .= 'ALTER TABLE ' . $this->db->escapeIdentifiers($this->db->DBPrefix . $table) . ' ADD ';
1237-
} else {
1238-
$sqls[$index] .= ",\n\t";
1234+
$sqls[$idx] = '';
12391235
}
12401236

1241-
$formatSql = 'CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s(%s)';
1242-
$sqls[$index] .= sprintf($formatSql, $nameIndexFilled, $foreignKeyFilled, $referenceTableFilled, $referenceFieldFilled);
1237+
$nameIndex = $fkey['fkName'] !== ''
1238+
? $fkey['fkName']
1239+
: $table . '_' . implode('_', $fkey['field']) . $fkSuffix;
1240+
1241+
$sql = $prefixSql . sprintf(
1242+
'CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s(%s)',
1243+
$this->db->escapeIdentifiers($nameIndex),
1244+
implode(', ', $this->db->escapeIdentifiers($fkey['field'])),
1245+
$this->db->escapeIdentifiers($dbPrefix . $fkey['referenceTable']),
1246+
implode(', ', $this->db->escapeIdentifiers($fkey['referenceField'])),
1247+
);
12431248

12441249
if ($fkey['onDelete'] !== false && in_array($fkey['onDelete'], $this->fkAllowActions, true)) {
1245-
$sqls[$index] .= ' ON DELETE ' . $fkey['onDelete'];
1250+
$sql .= ' ON DELETE ' . $fkey['onDelete'];
12461251
}
12471252

1248-
if ($this->db->DBDriver !== 'OCI8' && $fkey['onUpdate'] !== false && in_array($fkey['onUpdate'], $this->fkAllowActions, true)) {
1249-
$sqls[$index] .= ' ON UPDATE ' . $fkey['onUpdate'];
1253+
if (! $isOci8 && $fkey['onUpdate'] !== false && in_array($fkey['onUpdate'], $this->fkAllowActions, true)) {
1254+
$sql .= ' ON UPDATE ' . $fkey['onUpdate'];
12501255
}
1256+
1257+
$sqls[$idx] .= $sql;
12511258
}
12521259

12531260
return $sqls;

‎system/Database/MySQLi/Builder.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
124124
$sql .= 'ON ' . implode(
125125
' AND ',
126126
array_map(
127-
static fn ($key, $value) => (
127+
static fn ($key, $value): RawSql|string => (
128128
($value instanceof RawSql && is_string($key))
129129
?
130130
$table . '.' . $key . ' = ' . $value

‎system/Database/OCI8/Builder.php‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
280280
$sql .= 'ON (' . implode(
281281
' AND ',
282282
array_map(
283-
static fn ($key, $value) => (
283+
static fn ($key, $value): RawSql|string => (
284284
($value instanceof RawSql && is_string($key))
285285
?
286286
$table . '.' . $key . ' = ' . $value
@@ -385,7 +385,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
385385
$sql .= implode(
386386
' AND ',
387387
array_map(
388-
static fn ($key, $value) => (
388+
static fn ($key, $value): RawSql|string => (
389389
($value instanceof RawSql && is_string($key))
390390
?
391391
$table . '.' . $key . ' = ' . $value
@@ -474,7 +474,7 @@ protected function _deleteBatch(string $table, array $keys, array $values): stri
474474
$sql .= 'WHERE ' . implode(
475475
' AND ',
476476
array_map(
477-
static fn ($key, $value) => (
477+
static fn ($key, $value): RawSql|string => (
478478
$value instanceof RawSql ?
479479
$value :
480480
(
@@ -489,11 +489,7 @@ protected function _deleteBatch(string $table, array $keys, array $values): stri
489489
);
490490

491491
// convert binds in where
492-
foreach ($this->QBWhere as $key => $where) {
493-
foreach ($this->binds as $field => $bind) {
494-
$this->QBWhere[$key]['condition'] = str_replace(':' . $field . ':', $bind[0], $where['condition']);
495-
}
496-
}
492+
$this->convertWhereBindsForBatch();
497493

498494
$sql .= ' ' . str_replace(
499495
'WHERE ',

‎system/Database/Postgre/Builder.php‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -657,11 +657,7 @@ static function ($key, $value) use ($table, $alias, $that): RawSql|string {
657657
);
658658

659659
// convert binds in where
660-
foreach ($this->QBWhere as $key => $where) {
661-
foreach ($this->binds as $field => $bind) {
662-
$this->QBWhere[$key]['condition'] = str_replace(':' . $field . ':', $bind[0], $where['condition']);
663-
}
664-
}
660+
$this->convertWhereBindsForBatch();
665661

666662
$sql .= ' ' . str_replace(
667663
'WHERE ',

‎system/Database/SQLSRV/Builder.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
810810
$sql .= implode(
811811
' AND ',
812812
array_map(
813-
static fn ($key, $value) => (
813+
static fn ($key, $value): RawSql|string => (
814814
($value instanceof RawSql && is_string($key))
815815
?
816816
$fullTableName . '.' . $key . ' = ' . $value

0 commit comments

Comments
 (0)