Skip to content

Commit

Permalink
Release v4.2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Oct 6, 2022
1 parent 872c8fb commit 011ce3b
Show file tree
Hide file tree
Showing 85 changed files with 596 additions and 518 deletions.
2 changes: 1 addition & 1 deletion app/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 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
* the bootstrap process and is called during the framework's
* execution.
*
* This can be looked at as a `master helper` file that is
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"psr/log": "^1.1"
},
"require-dev": {
"codeigniter/coding-standard": "^1.1",
"codeigniter/coding-standard": "^1.5",
"fakerphp/faker": "^1.9",
"friendsofphp/php-cs-fixer": "~3.11.0",
"mikey179/vfsstream": "^1.6",
"nexusphp/cs-config": "^3.3",
"nexusphp/cs-config": "^3.6",
"phpunit/phpunit": "^9.1",
"predis/predis": "^1.1 || ^2.0"
},
Expand Down
6 changes: 3 additions & 3 deletions system/API/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected function fail($messages, int $status = 400, ?string $code = null, stri
/**
* Used after successfully creating a new resource.
*
* @param mixed $data
* @param array|string|null $data
*
* @return Response
*/
Expand All @@ -155,7 +155,7 @@ protected function respondCreated($data = null, string $message = '')
/**
* Used after a resource has been successfully deleted.
*
* @param mixed $data
* @param array|string|null $data
*
* @return Response
*/
Expand All @@ -167,7 +167,7 @@ protected function respondDeleted($data = null, string $message = '')
/**
* Used after a resource has been successfully updated.
*
* @param mixed $data
* @param array|string|null $data
*
* @return Response
*/
Expand Down
92 changes: 58 additions & 34 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ abstract class BaseModel

/**
* Whether rules should be removed that do not exist
* in the passed in data. Used between inserts/updates.
* in the passed data. Used in updates.
*
* @var bool
*/
Expand Down Expand Up @@ -326,9 +326,9 @@ abstract protected function doFind(bool $singleton, $id = null);
*
* @param string $columnName Column Name
*
* @throws DataException
*
* @return array|null The resulting row of data, or null if no data found.
*
* @throws DataException
*/
abstract protected function doFindColumn(string $columnName);

Expand Down Expand Up @@ -392,9 +392,9 @@ abstract protected function doUpdate($id = null, $data = null): bool;
* @param int $batchSize The size of the batch to run
* @param bool $returnSQL True means SQL is returned, false will execute the query
*
* @throws DatabaseException
*
* @return mixed Number of rows affected or FALSE on failure
*
* @throws DatabaseException
*/
abstract protected function doUpdateBatch(?array $set = null, ?string $index = null, int $batchSize = 100, bool $returnSQL = false);

Expand All @@ -405,9 +405,9 @@ abstract protected function doUpdateBatch(?array $set = null, ?string $index = n
* @param array|int|string|null $id The rows primary key(s)
* @param bool $purge Allows overriding the soft deletes setting.
*
* @throws DatabaseException
*
* @return bool|string
*
* @throws DatabaseException
*/
abstract protected function doDelete($id = null, bool $purge = false);

Expand Down Expand Up @@ -541,9 +541,9 @@ public function find($id = null)
*
* @param string $columnName Column Name
*
* @throws DataException
*
* @return array|null The resulting row of data, or null if no data found.
*
* @throws DataException
*/
public function findColumn(string $columnName)
{
Expand Down Expand Up @@ -693,21 +693,31 @@ public function getInsertID()
* @param array|object|null $data Data
* @param bool $returnID Whether insert ID should be returned or not.
*
* @throws ReflectionException
*
* @return bool|int|string insert ID or true on success. false on failure.
*
* @throws ReflectionException
*/
public function insert($data = null, bool $returnID = true)
{
$this->insertID = 0;

// Set $cleanValidationRules to false temporary.
$cleanValidationRules = $this->cleanValidationRules;
$this->cleanValidationRules = false;

$data = $this->transformDataToArray($data, 'insert');

// Validate data before saving.
if (! $this->skipValidation && ! $this->cleanRules()->validate($data)) {
if (! $this->skipValidation && ! $this->validate($data)) {
// Restore $cleanValidationRules
$this->cleanValidationRules = $cleanValidationRules;

return false;
}

// Restore $cleanValidationRules
$this->cleanValidationRules = $cleanValidationRules;

// Must be called first so we don't
// strip out created_at values.
$data = $this->doProtectFields($data);
Expand Down Expand Up @@ -767,12 +777,16 @@ public function insert($data = null, bool $returnID = true)
* @param int $batchSize The size of the batch to run
* @param bool $testing True means only number of records is returned, false will execute the query
*
* @throws ReflectionException
*
* @return bool|int Number of rows inserted or FALSE on failure
*
* @throws ReflectionException
*/
public function insertBatch(?array $set = null, ?bool $escape = null, int $batchSize = 100, bool $testing = false)
{
// Set $cleanValidationRules to false temporary.
$cleanValidationRules = $this->cleanValidationRules;
$this->cleanValidationRules = false;

if (is_array($set)) {
foreach ($set as &$row) {
// If $data is using a custom class with public or protected
Expand All @@ -789,8 +803,11 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch
$row = (array) $row;
}

// Validate every row..
if (! $this->skipValidation && ! $this->cleanRules()->validate($row)) {
// Validate every row.
if (! $this->skipValidation && ! $this->validate($row)) {
// Restore $cleanValidationRules
$this->cleanValidationRules = $cleanValidationRules;

return false;
}

Expand All @@ -811,6 +828,9 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch
}
}

// Restore $cleanValidationRules
$this->cleanValidationRules = $cleanValidationRules;

return $this->doInsertBatch($set, $escape, $batchSize, $testing);
}

Expand All @@ -832,7 +852,7 @@ public function update($id = null, $data = null): bool
$data = $this->transformDataToArray($data, 'update');

// Validate data before saving.
if (! $this->skipValidation && ! $this->cleanRules(true)->validate($data)) {
if (! $this->skipValidation && ! $this->validate($data)) {
return false;
}

Expand Down Expand Up @@ -882,10 +902,10 @@ public function update($id = null, $data = null): bool
* @param int $batchSize The size of the batch to run
* @param bool $returnSQL True means SQL is returned, false will execute the query
*
* @return mixed Number of rows affected or FALSE on failure
*
* @throws DatabaseException
* @throws ReflectionException
*
* @return mixed Number of rows affected or FALSE on failure
*/
public function updateBatch(?array $set = null, ?string $index = null, int $batchSize = 100, bool $returnSQL = false)
{
Expand All @@ -906,7 +926,7 @@ public function updateBatch(?array $set = null, ?string $index = null, int $batc
}

// Validate data before saving.
if (! $this->skipValidation && ! $this->cleanRules(true)->validate($row)) {
if (! $this->skipValidation && ! $this->validate($row)) {
return false;
}

Expand Down Expand Up @@ -937,9 +957,9 @@ public function updateBatch(?array $set = null, ?string $index = null, int $batc
* @param array|int|string|null $id The rows primary key(s)
* @param bool $purge Allows overriding the soft deletes setting.
*
* @throws DatabaseException
*
* @return BaseResult|bool
*
* @throws DatabaseException
*/
public function delete($id = null, bool $purge = false)
{
Expand Down Expand Up @@ -1027,7 +1047,7 @@ public function onlyDeleted()
public function replace(?array $data = null, bool $returnSQL = false)
{
// Validate data before saving.
if ($data && ! $this->skipValidation && ! $this->cleanRules(true)->validate($data)) {
if ($data && ! $this->skipValidation && ! $this->validate($data)) {
return false;
}

Expand Down Expand Up @@ -1153,9 +1173,9 @@ protected function doProtectFields(array $data): array
*
* @param int|null $userData An optional PHP timestamp to be converted.
*
* @throws ModelException
*
* @return mixed
*
* @throws ModelException
*/
protected function setDate(?int $userData = null)
{
Expand All @@ -1177,9 +1197,9 @@ protected function setDate(?int $userData = null)
*
* @param int $value value
*
* @throws ModelException
*
* @return int|string
*
* @throws ModelException
*/
protected function intToDate(int $value)
{
Expand Down Expand Up @@ -1440,9 +1460,9 @@ public function allowCallbacks(bool $val = true)
* @param string $event Event
* @param array $eventData Event Data
*
* @throws DataException
*
* @return mixed
*
* @throws DataException
*/
protected function trigger(string $event, array $eventData)
{
Expand Down Expand Up @@ -1501,9 +1521,9 @@ public function asObject(string $class = 'object')
* @param bool $onlyChanged Only Changed Property
* @param bool $recursive If true, inner entities will be casted as array as well
*
* @throws ReflectionException
*
* @return array Array
*
* @throws ReflectionException
*/
protected function objectToArray($data, bool $onlyChanged = true, bool $recursive = false): array
{
Expand Down Expand Up @@ -1531,9 +1551,9 @@ protected function objectToArray($data, bool $onlyChanged = true, bool $recursiv
* @param bool $onlyChanged Only Changed Property
* @param bool $recursive If true, inner entities will be casted as array as well
*
* @throws ReflectionException
*
* @return array|null Array
*
* @throws ReflectionException
*/
protected function objectToRawArray($data, bool $onlyChanged = true, bool $recursive = false): ?array
{
Expand Down Expand Up @@ -1581,7 +1601,11 @@ protected function transformDataToArray($data, string $type): array
// properties representing the collection elements, we need to grab
// them as an array.
if (is_object($data) && ! $data instanceof stdClass) {
$data = $this->objectToArray($data, ($type === 'update'), true);
// If it validates with entire rules, all fields are needed.
$onlyChanged = ($this->skipValidation === false && $this->cleanValidationRules === false)
? false : ($type === 'update');

$data = $this->objectToArray($data, $onlyChanged, true);
}

// If it's still a stdClass, go ahead and convert to
Expand Down
4 changes: 2 additions & 2 deletions system/CLI/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ abstract public function run(array $params);
/**
* Can be used by a command to run other commands.
*
* @throws ReflectionException
*
* @return mixed
*
* @throws ReflectionException
*/
protected function call(string $command, array $params = [])
{
Expand Down
8 changes: 4 additions & 4 deletions system/CLI/CommandRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public function __construct()
* @param string $method
* @param array $params
*
* @throws ReflectionException
*
* @return mixed
*
* @throws ReflectionException
*/
public function _remap($method, $params)
{
Expand All @@ -54,9 +54,9 @@ public function _remap($method, $params)
/**
* Default command.
*
* @throws ReflectionException
*
* @return mixed
*
* @throws ReflectionException
*/
public function index(array $params)
{
Expand Down
4 changes: 2 additions & 2 deletions system/CLI/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public function __construct(CodeIgniter $app)
/**
* Runs the current command discovered on the CLI.
*
* @throws Exception
*
* @return mixed
*
* @throws Exception
*/
public function run(bool $useSafeOutput = false)
{
Expand Down
Loading

0 comments on commit 011ce3b

Please sign in to comment.