Skip to content

Commit

Permalink
Merge branch '10.x'
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	composer.json
#	src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
#	src/Illuminate/Foundation/Application.php
#	src/Illuminate/Mail/Transport/SesTransport.php
#	src/Illuminate/Mail/Transport/SesV2Transport.php
  • Loading branch information
driesvints committed Oct 26, 2023
2 parents a3b26b5 + 98ffb75 commit 133e329
Show file tree
Hide file tree
Showing 87 changed files with 3,310 additions and 289 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/facades.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
Illuminate\\Support\\Facades\\Vite
- name: Commit facade docblocks
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Update facade docblocks
file_pattern: src/
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@
"league/flysystem-read-only": "^3.3",
"league/flysystem-sftp-v3": "^3.0",
"mockery/mockery": "^1.5.1",
"nyholm/psr7": "^1.2",
"orchestra/testbench-core": "^9.0",
"pda/pheanstalk": "^4.0",
"phpstan/phpstan": "^1.4.7",
"phpunit/phpunit": "^10.1",
"predis/predis": "^2.0.2",
"symfony/cache": "^7.0",
"symfony/http-client": "^7.0"
"symfony/http-client": "^7.0",
"symfony/psr-http-message-bridge": "^2.0"
},
"provide": {
"psr/container-implementation": "1.1|2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ protected function currentTags($chunkSize = 1000)
yield $tag;
}
} while (((string) $cursor) !== $defaultCursorValue);
})->map(fn (string $tagKey) => Str::match('/^'.preg_quote($prefix).'tag:(.*):entries$/', $tagKey));
})->map(fn (string $tagKey) => Str::match('/^'.preg_quote($prefix, '/').'tag:(.*):entries$/', $tagKey));
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Collections/Traits/EnumeratesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* @property-read HigherOrderCollectionProxy $max
* @property-read HigherOrderCollectionProxy $min
* @property-read HigherOrderCollectionProxy $partition
* @property-read HigherOrderCollectionProxy $percentage
* @property-read HigherOrderCollectionProxy $reject
* @property-read HigherOrderCollectionProxy $skipUntil
* @property-read HigherOrderCollectionProxy $skipWhile
Expand Down Expand Up @@ -82,6 +83,7 @@ trait EnumeratesValues
'max',
'min',
'partition',
'percentage',
'reject',
'skipUntil',
'skipWhile',
Expand Down
9 changes: 6 additions & 3 deletions src/Illuminate/Console/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,12 @@ protected function userProviderModel()
*/
protected function isReservedName($name)
{
$name = strtolower($name);

return in_array($name, $this->reservedNames);
return in_array(
strtolower($name),
collect($this->reservedNames)
->transform(fn ($name) => strtolower($name))
->all()
);
}

/**
Expand Down
35 changes: 34 additions & 1 deletion src/Illuminate/Database/Concerns/BuildsQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,35 @@ public function each(callable $callback, $count = 1000)
* @return bool
*/
public function chunkById($count, callable $callback, $column = null, $alias = null)
{
return $this->orderedChunkById($count, $callback, $column, $alias);
}

/**
* Chunk the results of a query by comparing IDs in descending order.
*
* @param int $count
* @param callable $callback
* @param string|null $column
* @param string|null $alias
* @return bool
*/
public function chunkByIdDesc($count, callable $callback, $column = null, $alias = null)
{
return $this->orderedChunkById($count, $callback, $column, $alias, descending: true);
}

/**
* Chunk the results of a query by comparing IDs in a given order.
*
* @param int $count
* @param callable $callback
* @param string|null $column
* @param string|null $alias
* @param bool $descending
* @return bool
*/
public function orderedChunkById($count, callable $callback, $column = null, $alias = null, $descending = false)
{
$column ??= $this->defaultKeyName();

Expand All @@ -127,7 +156,11 @@ public function chunkById($count, callable $callback, $column = null, $alias = n
// We'll execute the query for the given page and get the results. If there are
// no results we can just break and return from here. When there are results
// we will call the callback with the current chunk of these results here.
$results = $clone->forPageAfterId($count, $lastId, $column)->get();
if ($descending) {
$results = $clone->forPageBeforeId($count, $lastId, $column)->get();
} else {
$results = $clone->forPageAfterId($count, $lastId, $column)->get();
}

$countResults = $results->count();

Expand Down
11 changes: 5 additions & 6 deletions src/Illuminate/Database/Concerns/ManagesTransactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function transaction(Closure $callback, $attempts = 1)
$this->getPdo()->commit();
}

$this->transactions = max(0, $this->transactions - 1);

if ($this->afterCommitCallbacksShouldBeExecuted()) {
$this->transactionsManager?->commit($this->getName());
}
Expand All @@ -56,8 +58,6 @@ public function transaction(Closure $callback, $attempts = 1)
);

continue;
} finally {
$this->transactions = max(0, $this->transactions - 1);
}

$this->fireConnectionEvent('committed');
Expand Down Expand Up @@ -194,12 +194,12 @@ public function commit()
$this->getPdo()->commit();
}

$this->transactions = max(0, $this->transactions - 1);

if ($this->afterCommitCallbacksShouldBeExecuted()) {
$this->transactionsManager?->commit($this->getName());
}

$this->transactions = max(0, $this->transactions - 1);

$this->fireConnectionEvent('committed');
}

Expand All @@ -210,8 +210,7 @@ public function commit()
*/
protected function afterCommitCallbacksShouldBeExecuted()
{
return $this->transactions == 0 ||
$this->transactionsManager?->afterCommitCallbacksShouldBeExecuted($this->transactions);
return $this->transactionsManager?->afterCommitCallbacksShouldBeExecuted($this->transactions) || $this->transactions == 0;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ protected function ensureDependenciesExist()
protected function installDependencies()
{
$command = collect($this->composer->findComposer())
->push('require doctrine/dbal')
->push('require doctrine/dbal:^3.5.1')
->implode(' ');

$process = Process::fromShellCommandline($command, null, null, null, null);
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Console/PruneCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ protected function models()
return $models->reject(function ($model) use ($except) {
return in_array($model, $except);
});
})->filter(function ($model) {
return $this->isPrunable($model);
})->filter(function ($model) {
return class_exists($model);
})->filter(function ($model) {
return $this->isPrunable($model);
})->values();
}

Expand Down
5 changes: 3 additions & 2 deletions src/Illuminate/Database/Console/ShowModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Types\DecimalType;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -158,7 +159,7 @@ protected function getVirtualAttributes($model, $columns)
->reject(
fn (ReflectionMethod $method) => $method->isStatic()
|| $method->isAbstract()
|| $method->getDeclaringClass()->getName() !== get_class($model)
|| $method->getDeclaringClass()->getName() === Model::class
)
->mapWithKeys(function (ReflectionMethod $method) use ($model) {
if (preg_match('/^get(.+)Attribute$/', $method->getName(), $matches) === 1) {
Expand Down Expand Up @@ -198,7 +199,7 @@ protected function getRelations($model)
->reject(
fn (ReflectionMethod $method) => $method->isStatic()
|| $method->isAbstract()
|| $method->getDeclaringClass()->getName() !== get_class($model)
|| $method->getDeclaringClass()->getName() === Model::class
)
->filter(function (ReflectionMethod $method) {
$file = new SplFileObject($method->getFileName());
Expand Down
30 changes: 1 addition & 29 deletions src/Illuminate/Database/DatabaseTransactionsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ class DatabaseTransactionsManager
*/
protected $transactions;

/**
* The database transaction that should be ignored by callbacks.
*
* @var \Illuminate\Database\DatabaseTransactionRecord|null
*/
protected $callbacksShouldIgnore;

/**
* Create a new database transactions manager instance.
*
Expand Down Expand Up @@ -54,10 +47,6 @@ public function rollback($connection, $level)
$this->transactions = $this->transactions->reject(
fn ($transaction) => $transaction->connection == $connection && $transaction->level > $level
)->values();

if ($this->transactions->isEmpty()) {
$this->callbacksShouldIgnore = null;
}
}

/**
Expand All @@ -75,10 +64,6 @@ public function commit($connection)
$this->transactions = $forOtherConnections->values();

$forThisConnection->map->executeCallbacks();

if ($this->transactions->isEmpty()) {
$this->callbacksShouldIgnore = null;
}
}

/**
Expand All @@ -96,19 +81,6 @@ public function addCallback($callback)
$callback();
}

/**
* Specify that callbacks should ignore the given transaction when determining if they should be executed.
*
* @param \Illuminate\Database\DatabaseTransactionRecord $transaction
* @return $this
*/
public function callbacksShouldIgnore(DatabaseTransactionRecord $transaction)
{
$this->callbacksShouldIgnore = $transaction;

return $this;
}

/**
* Get the transactions that are applicable to callbacks.
*
Expand All @@ -127,7 +99,7 @@ public function callbackApplicableTransactions()
*/
public function afterCommitCallbacksShouldBeExecuted($level)
{
return $level === 1;
return $level === 0;
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,11 @@ public function firstOrNew(array $attributes = [], array $values = [])
*/
public function firstOrCreate(array $attributes = [], array $values = [])
{
if (! is_null($instance = $this->where($attributes)->first())) {
if (! is_null($instance = (clone $this)->where($attributes)->first())) {
return $instance;
}

return $this->create(array_merge($attributes, $values));
return $this->createOrFirst($attributes, $values);
}

/**
Expand Down Expand Up @@ -595,8 +595,10 @@ public function createOrFirst(array $attributes = [], array $values = [])
*/
public function updateOrCreate(array $attributes, array $values = [])
{
return tap($this->firstOrNew($attributes), function ($instance) use ($values) {
$instance->fill($values)->save();
return tap($this->firstOrCreate($attributes, $values), function ($instance) use ($values) {
if (! $instance->wasRecentlyCreated) {
$instance->fill($values)->save();
}
});
}

Expand Down
15 changes: 14 additions & 1 deletion src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use ReflectionClass;
use ReflectionMethod;
use ReflectionNamedType;
use RuntimeException;
use ValueError;

trait HasAttributes
Expand Down Expand Up @@ -1362,7 +1363,19 @@ public static function encryptUsing($encrypter)
*/
protected function castAttributeAsHashedString($key, $value)
{
return $value !== null && ! Hash::isHashed($value) ? Hash::make($value) : $value;
if ($value === null) {
return null;
}

if (! Hash::isHashed($value)) {
return Hash::make($value);
}

if (! Hash::verifyConfiguration($value)) {
throw new RuntimeException("Could not verify the hashed value's configuration.");
}

return $value;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,7 @@ public function replicate(array $except = null)
$this->getKeyName(),
$this->getCreatedAtColumn(),
$this->getUpdatedAtColumn(),
...$this->uniqueIds(),
]));

$attributes = Arr::except(
Expand Down
20 changes: 7 additions & 13 deletions src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public function firstOrCreate(array $attributes = [], array $values = [], array
{
if (is_null($instance = (clone $this)->where($attributes)->first())) {
if (is_null($instance = $this->related->where($attributes)->first())) {
$instance = $this->create(array_merge($attributes, $values), $joining, $touch);
$instance = $this->createOrFirst($attributes, $values, $joining, $touch);
} else {
try {
$this->getQuery()->withSavepointIfNeeded(fn () => $this->attach($instance, $joining, $touch));
Expand Down Expand Up @@ -672,19 +672,13 @@ public function createOrFirst(array $attributes = [], array $values = [], array
*/
public function updateOrCreate(array $attributes, array $values = [], array $joining = [], $touch = true)
{
if (is_null($instance = (clone $this)->where($attributes)->first())) {
if (is_null($instance = $this->related->where($attributes)->first())) {
return $this->create(array_merge($attributes, $values), $joining, $touch);
} else {
$this->attach($instance, $joining, $touch);
}
}

$instance->fill($values);
return tap($this->firstOrCreate($attributes, $values, $joining, $touch), function ($instance) use ($values) {
if (! $instance->wasRecentlyCreated) {
$instance->fill($values);

$instance->save(['touch' => false]);

return $instance;
$instance->save(['touch' => false]);
}
});
}

/**
Expand Down
Loading

0 comments on commit 133e329

Please sign in to comment.