Skip to content

Commit

Permalink
Release v4.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Aug 29, 2022
1 parent f91bc95 commit 26ebf14
Show file tree
Hide file tree
Showing 42 changed files with 511 additions and 90 deletions.
15 changes: 13 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"ext-intl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"kint-php/kint": "^4.1.1",
"kint-php/kint": "^4.2",
"laminas/laminas-escaper": "^2.9",
"psr/log": "^1.1"
},
Expand All @@ -24,7 +24,18 @@
"predis/predis": "^1.1 || ^2.0"
},
"suggest": {
"ext-fileinfo": "Improves mime type detection for files"
"ext-imagick": "If you use Image class ImageMagickHandler",
"ext-simplexml": "If you format XML",
"ext-mysqli": "If you use MySQL",
"ext-oci8": "If you use Oracle Database",
"ext-pgsql": "If you use PostgreSQL",
"ext-sqlsrv": "If you use SQL Server",
"ext-sqlite3": "If you use SQLite3",
"ext-memcache": "If you use Cache class MemcachedHandler with Memcache",
"ext-memcached": "If you use Cache class MemcachedHandler with Memcached",
"ext-redis": "If you use Cache class RedisHandler",
"ext-fileinfo": "Improves mime type detection for files",
"ext-readline": "Improves CLI::input() usability"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion env
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
# database.default.port = 3306

# database.tests.hostname = localhost
# database.tests.database = ci4
# database.tests.database = ci4_test
# database.tests.username = root
# database.tests.password = root
# database.tests.DBDriver = MySQLi
Expand Down
8 changes: 5 additions & 3 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CodeIgniter
/**
* The current version of CodeIgniter Framework
*/
public const CI_VERSION = '4.2.4';
public const CI_VERSION = '4.2.5';

/**
* App startup time.
Expand Down Expand Up @@ -982,8 +982,10 @@ protected function gatherOutput(?Cache $cacheConfig = null, $returned = null)

if ($returned instanceof DownloadResponse) {
// Turn off output buffering completely, even if php.ini output_buffering is not off
while (ob_get_level() > 0) {
ob_end_clean();
if (ENVIRONMENT !== 'testing') {
while (ob_get_level() > 0) {
ob_end_clean();
}
}

$this->response = $returned;
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Cache/ClearCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ClearCache extends BaseCommand
*
* @var string
*/
protected $usage = 'cache:clear [driver]';
protected $usage = 'cache:clear [<driver>]';

/**
* the Command's Arguments
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Help.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Help extends BaseCommand
*
* @var string
*/
protected $usage = 'help command_name';
protected $usage = 'help [<command_name>]';

/**
* the Command's Arguments
Expand Down
5 changes: 5 additions & 0 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use CodeIgniter\Debug\Timer;
use CodeIgniter\Files\Exceptions\FileNotFoundException;
use CodeIgniter\HTTP\Exceptions\HTTPException;
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
Expand Down Expand Up @@ -487,6 +488,10 @@ function force_https(int $duration = 31_536_000, ?RequestInterface $request = nu
$response = Services::response(null, true);
}

if (! $request instanceof IncomingRequest) {
return;
}

if ((ENVIRONMENT !== 'testing' && (is_cli() || $request->isSecure())) || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'test')) {
// @codeCoverageIgnoreStart
return;
Expand Down
16 changes: 6 additions & 10 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ public function fromSubquery(BaseBuilder $from, string $alias): self
{
$table = $this->buildSubquery($from, true, $alias);

$this->trackAliases($table);
$this->db->addTableAlias($alias);
$this->QBFrom[] = $table;

return $this;
Expand Down Expand Up @@ -2705,8 +2705,7 @@ protected function objectToArray($object)
$array = [];

foreach (get_object_vars($object) as $key => $val) {
// There are some built in keys we need to ignore for this conversion
if (! is_object($val) && ! is_array($val) && $key !== '_parent_name') {
if (! is_object($val) && ! is_array($val)) {
$array[$key] = $val;
}
}
Expand All @@ -2732,13 +2731,10 @@ protected function batchObjectToArray($object)
$fields = array_keys($out);

foreach ($fields as $val) {
// There are some built in keys we need to ignore for this conversion
if ($val !== '_parent_name') {
$i = 0;
$i = 0;

foreach ($out[$val] as $data) {
$array[$i++][$val] = $data;
}
foreach ($out[$val] as $data) {
$array[$i++][$val] = $data;
}
}

Expand Down Expand Up @@ -2952,7 +2948,7 @@ protected function buildSubquery($builder, bool $wrapped = false, string $alias
throw new DatabaseException('The subquery cannot be the same object as the main query object.');
}

$subquery = strtr($builder->getCompiledSelect(), "\n", ' ');
$subquery = strtr($builder->getCompiledSelect(false), "\n", ' ');

if ($wrapped) {
$subquery = '(' . $subquery . ')';
Expand Down
48 changes: 43 additions & 5 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ public function addTableAlias(string $table)
/**
* Executes the query against the database.
*
* @return mixed
* @return bool|object|resource
*/
abstract protected function execute(string $sql);

Expand Down Expand Up @@ -882,7 +882,12 @@ public function table($tableName)
*/
public function newQuery(): BaseBuilder
{
return $this->table(',')->from([], true);
// save table aliases
$tempAliases = $this->aliasedTables;
$builder = $this->table(',')->from([], true);
$this->aliasedTables = $tempAliases;

return $builder;
}

/**
Expand Down Expand Up @@ -1405,10 +1410,41 @@ public function listTables(bool $constrainByPrefix = false)

/**
* Determine if a particular table exists
*
* @param bool $cached Whether to use data cache
*/
public function tableExists(string $tableName): bool
public function tableExists(string $tableName, bool $cached = true): bool
{
return in_array($this->protectIdentifiers($tableName, true, false, false), $this->listTables(), true);
if ($cached === true) {
return in_array($this->protectIdentifiers($tableName, true, false, false), $this->listTables(), true);
}

if (false === ($sql = $this->_listTables(false, $tableName))) {
if ($this->DBDebug) {
throw new DatabaseException('This feature is not available for the database you are using.');
}

return false;
}

$tableExists = $this->query($sql)->getResultArray() !== [];

// if cache has been built already
if (! empty($this->dataCache['table_names'])) {
$key = array_search(
strtolower($tableName),
array_map('strtolower', $this->dataCache['table_names']),
true
);

// table doesn't exist but still in cache - lets reset cache, it can be rebuilt later
// OR if table does exist but is not found in cache
if (($key !== false && ! $tableExists) || ($key === false && $tableExists)) {
$this->resetDataCache();
}
}

return $tableExists;
}

/**
Expand Down Expand Up @@ -1575,9 +1611,11 @@ abstract public function insertID();
/**
* Generates the SQL for listing tables in a platform-dependent manner.
*
* @param string|null $tableName If $tableName is provided will return only this table if exists.
*
* @return false|string
*/
abstract protected function _listTables(bool $constrainByPrefix = false);
abstract protected function _listTables(bool $constrainByPrefix = false, ?string $tableName = null);

/**
* Generates a platform-specific query string so that the column names can be fetched.
Expand Down
4 changes: 2 additions & 2 deletions system/Database/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public function createTable(string $table, bool $ifNotExists = false, array $att
}

// If table exists lets stop here
if ($ifNotExists === true && $this->db->tableExists($table)) {
if ($ifNotExists === true && $this->db->tableExists($table, false)) {
$this->reset();

return true;
Expand Down Expand Up @@ -776,7 +776,7 @@ public function modifyColumn(string $table, $field): bool
}

/**
* @param mixed $fields
* @param array|string $fields
*
* @return false|string|string[]
*/
Expand Down
10 changes: 8 additions & 2 deletions system/Database/MySQLi/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public function getVersion(): string
/**
* Executes the query against the database.
*
* @return mixed
* @return bool|object
*/
protected function execute(string $sql)
{
Expand Down Expand Up @@ -368,11 +368,17 @@ public function escapeLikeStringDirect($str)
/**
* Generates the SQL for listing tables in a platform-dependent manner.
* Uses escapeLikeStringDirect().
*
* @param string|null $tableName If $tableName is provided will return only this table if exists.
*/
protected function _listTables(bool $prefixLimit = false): string
protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string
{
$sql = 'SHOW TABLES FROM ' . $this->escapeIdentifiers($this->database);

if ($tableName !== null) {
return $sql . ' LIKE ' . $this->escape($tableName);
}

if ($prefixLimit !== false && $this->DBPrefix !== '') {
return $sql . " LIKE '" . $this->escapeLikeStringDirect($this->DBPrefix) . "%'";
}
Expand Down
6 changes: 3 additions & 3 deletions system/Database/MySQLi/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ protected function _createTableAttributes(array $attributes): string
/**
* ALTER TABLE
*
* @param string $alterType ALTER type
* @param string $table Table name
* @param mixed $field Column definition
* @param string $alterType ALTER type
* @param string $table Table name
* @param array|string $field Column definition
*
* @return string|string[]
*/
Expand Down
10 changes: 8 additions & 2 deletions system/Database/OCI8/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function getVersion(): string
/**
* Executes the query against the database.
*
* @return false|resource
* @return bool
*/
protected function execute(string $sql)
{
Expand Down Expand Up @@ -242,11 +242,17 @@ public function affectedRows(): int

/**
* Generates the SQL for listing tables in a platform-dependent manner.
*
* @param string|null $tableName If $tableName is provided will return only this table if exists.
*/
protected function _listTables(bool $prefixLimit = false): string
protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string
{
$sql = 'SELECT "TABLE_NAME" FROM "USER_TABLES"';

if ($tableName !== null) {
return $sql . ' WHERE "TABLE_NAME" LIKE ' . $this->escape($tableName);
}

if ($prefixLimit !== false && $this->DBPrefix !== '') {
return $sql . ' WHERE "TABLE_NAME" LIKE \'' . $this->escapeLikeString($this->DBPrefix) . "%' "
. sprintf($this->likeEscapeStr, $this->likeEscapeChar);
Expand Down
6 changes: 3 additions & 3 deletions system/Database/OCI8/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class Forge extends BaseForge
/**
* ALTER TABLE
*
* @param string $alterType ALTER type
* @param string $table Table name
* @param mixed $field Column definition
* @param string $alterType ALTER type
* @param string $table Table name
* @param array|string $field Column definition
*
* @return string|string[]
*/
Expand Down
10 changes: 8 additions & 2 deletions system/Database/Postgre/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function getVersion(): string
/**
* Executes the query against the database.
*
* @return mixed
* @return false|resource
*/
protected function execute(string $sql)
{
Expand Down Expand Up @@ -204,11 +204,17 @@ protected function _escapeString(string $str): string

/**
* Generates the SQL for listing tables in a platform-dependent manner.
*
* @param string|null $tableName If $tableName is provided will return only this table if exists.
*/
protected function _listTables(bool $prefixLimit = false): string
protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string
{
$sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \'' . $this->schema . "'";

if ($tableName !== null) {
return $sql . ' AND "table_name" LIKE ' . $this->escape($tableName);
}

if ($prefixLimit !== false && $this->DBPrefix !== '') {
return $sql . ' AND "table_name" LIKE \''
. $this->escapeLikeString($this->DBPrefix) . "%' "
Expand Down
2 changes: 1 addition & 1 deletion system/Database/Postgre/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function _createTableAttributes(array $attributes): string
}

/**
* @param mixed $field
* @param array|string $field
*
* @return array|bool|string
*/
Expand Down
10 changes: 8 additions & 2 deletions system/Database/SQLSRV/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,20 @@ public function insertID(): int

/**
* Generates the SQL for listing tables in a platform-dependent manner.
*
* @param string|null $tableName If $tableName is provided will return only this table if exists.
*/
protected function _listTables(bool $prefixLimit = false): string
protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string
{
$sql = 'SELECT [TABLE_NAME] AS "name"'
. ' FROM [INFORMATION_SCHEMA].[TABLES] '
. ' WHERE '
. " [TABLE_SCHEMA] = '" . $this->schema . "' ";

if ($tableName !== null) {
return $sql .= ' AND [TABLE_NAME] LIKE ' . $this->escape($tableName);
}

if ($prefixLimit === true && $this->DBPrefix !== '') {
$sql .= " AND [TABLE_NAME] LIKE '" . $this->escapeLikeString($this->DBPrefix) . "%' "
. sprintf($this->likeEscapeStr, $this->likeEscapeChar);
Expand Down Expand Up @@ -445,7 +451,7 @@ public function setDatabase(?string $databaseName = null)
/**
* Executes the query against the database.
*
* @return mixed
* @return false|resource
*/
protected function execute(string $sql)
{
Expand Down
2 changes: 1 addition & 1 deletion system/Database/SQLSRV/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected function _createTableAttributes(array $attributes): string
}

/**
* @param mixed $field
* @param array|string $field
*
* @return false|string|string[]
*/
Expand Down
Loading

0 comments on commit 26ebf14

Please sign in to comment.