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

[4.5] fix: errors when not updating Config\Feature #8570

Merged
merged 2 commits into from
Mar 26, 2024
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
3 changes: 2 additions & 1 deletion system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,8 @@ public function findColumn(string $columnName)
*/
public function findAll(?int $limit = null, int $offset = 0)
{
if (config(Feature::class)->limitZeroAsAll) {
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
if ($limitZeroAsAll) {
$limit ??= 0;
}

Expand Down
3 changes: 2 additions & 1 deletion system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
if ($routeFilters !== null) {
$filters->enableFilters($routeFilters, 'before');

if (! config(Feature::class)->oldFilterOrder) {
$oldFilterOrder = config(Feature::class)->oldFilterOrder ?? false;
if (! $oldFilterOrder) {
$routeFilters = array_reverse($routeFilters);
}

Expand Down
3 changes: 2 additions & 1 deletion system/Commands/Utilities/Routes/FilterFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public function find(string $uri): array

$this->filters->enableFilters($routeFilters, 'before');

if (! config(Feature::class)->oldFilterOrder) {
$oldFilterOrder = config(Feature::class)->oldFilterOrder ?? false;
if (! $oldFilterOrder) {
$routeFilters = array_reverse($routeFilters);
}

Expand Down
21 changes: 14 additions & 7 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,8 @@ public function orderBy(string $orderBy, string $direction = '', ?bool $escape =
*/
public function limit(?int $value = null, ?int $offset = 0)
{
if (config(Feature::class)->limitZeroAsAll && $value === 0) {
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
if ($limitZeroAsAll && $value === 0) {
$value = null;
}

Expand Down Expand Up @@ -1614,7 +1615,8 @@ protected function compileFinalQuery(string $sql): string
*/
public function get(?int $limit = null, int $offset = 0, bool $reset = true)
{
if (config(Feature::class)->limitZeroAsAll && $limit === 0) {
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
if ($limitZeroAsAll && $limit === 0) {
$limit = null;
}

Expand Down Expand Up @@ -1751,7 +1753,8 @@ public function getWhere($where = null, ?int $limit = null, ?int $offset = 0, bo
$this->where($where);
}

if (config(Feature::class)->limitZeroAsAll && $limit === 0) {
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
if ($limitZeroAsAll && $limit === 0) {
$limit = null;
}

Expand Down Expand Up @@ -2473,7 +2476,8 @@ public function update($set = null, $where = null, ?int $limit = null): bool
$this->where($where);
}

if (config(Feature::class)->limitZeroAsAll && $limit === 0) {
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
if ($limitZeroAsAll && $limit === 0) {
$limit = null;
}

Expand Down Expand Up @@ -2518,7 +2522,8 @@ protected function _update(string $table, array $values): string
$valStr[] = $key . ' = ' . $val;
}

if (config(Feature::class)->limitZeroAsAll) {
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
if ($limitZeroAsAll) {
return 'UPDATE ' . $this->compileIgnore('update') . $table . ' SET ' . implode(', ', $valStr)
. $this->compileWhereHaving('QBWhere')
. $this->compileOrderBy()
Expand Down Expand Up @@ -2794,7 +2799,8 @@ public function delete($where = '', ?int $limit = null, bool $resetData = true)

$sql = $this->_delete($this->removeAlias($table));

if (config(Feature::class)->limitZeroAsAll && $limit === 0) {
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
if ($limitZeroAsAll && $limit === 0) {
$limit = null;
}

Expand Down Expand Up @@ -3064,7 +3070,8 @@ protected function compileSelect($selectOverride = false): string
. $this->compileWhereHaving('QBHaving')
. $this->compileOrderBy();

if (config(Feature::class)->limitZeroAsAll) {
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
if ($limitZeroAsAll) {
if ($this->QBLimit) {
$sql = $this->_limit($sql . "\n");
}
Expand Down
9 changes: 6 additions & 3 deletions system/Database/SQLSRV/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ protected function _limit(string $sql, bool $offsetIgnore = false): string
// DatabaseException:
// [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The number of
// rows provided for a FETCH clause must be greater then zero.
if (! config(Feature::class)->limitZeroAsAll && $this->QBLimit === 0) {
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
if (! $limitZeroAsAll && $this->QBLimit === 0) {
return "SELECT * \nFROM " . $this->_fromTables() . ' WHERE 1=0 ';
}

Expand Down Expand Up @@ -599,7 +600,8 @@ protected function compileSelect($selectOverride = false): string
. $this->compileOrderBy(); // ORDER BY

// LIMIT
if (config(Feature::class)->limitZeroAsAll) {
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
if ($limitZeroAsAll) {
if ($this->QBLimit) {
$sql = $this->_limit($sql . "\n");
}
Expand All @@ -618,7 +620,8 @@ protected function compileSelect($selectOverride = false): string
*/
public function get(?int $limit = null, int $offset = 0, bool $reset = true)
{
if (config(Feature::class)->limitZeroAsAll && $limit === 0) {
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
if ($limitZeroAsAll && $limit === 0) {
$limit = null;
}

Expand Down
15 changes: 10 additions & 5 deletions system/Filters/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ public function initialize(?string $uri = null)
return $this;
}

if (config(Feature::class)->oldFilterOrder) {
$oldFilterOrder = config(Feature::class)->oldFilterOrder ?? false;
if ($oldFilterOrder) {
$this->processGlobals($uri);
$this->processMethods();
$this->processFilters($uri);
Expand Down Expand Up @@ -604,7 +605,8 @@ protected function processGlobals(?string $uri = null)
}

if (isset($filters['before'])) {
if (config(Feature::class)->oldFilterOrder) {
$oldFilterOrder = config(Feature::class)->oldFilterOrder ?? false;
if ($oldFilterOrder) {
$this->filters['before'] = array_merge($this->filters['before'], $filters['before']);
} else {
$this->filters['before'] = array_merge($filters['before'], $this->filters['before']);
Expand Down Expand Up @@ -649,7 +651,8 @@ protected function processMethods()
}

if ($found) {
if (config(Feature::class)->oldFilterOrder) {
$oldFilterOrder = config(Feature::class)->oldFilterOrder ?? false;
if ($oldFilterOrder) {
$this->filters['before'] = array_merge($this->filters['before'], $this->config->methods[$method]);
} else {
$this->filters['before'] = array_merge($this->config->methods[$method], $this->filters['before']);
Expand Down Expand Up @@ -706,16 +709,18 @@ protected function processFilters(?string $uri = null)
}
}

$oldFilterOrder = config(Feature::class)->oldFilterOrder ?? false;

if (isset($filters['before'])) {
if (config(Feature::class)->oldFilterOrder) {
if ($oldFilterOrder) {
$this->filters['before'] = array_merge($this->filters['before'], $filters['before']);
} else {
$this->filters['before'] = array_merge($filters['before'], $this->filters['before']);
}
}

if (isset($filters['after'])) {
if (! config(Feature::class)->oldFilterOrder) {
if (! $oldFilterOrder) {
$filters['after'] = array_reverse($filters['after']);
}

Expand Down
3 changes: 2 additions & 1 deletion system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ protected function doFindColumn(string $columnName)
*/
protected function doFindAll(?int $limit = null, int $offset = 0)
{
if (config(Feature::class)->limitZeroAsAll) {
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
if ($limitZeroAsAll) {
$limit ??= 0;
}

Expand Down
Loading