Skip to content

Commit b7f64d8

Browse files
committed
Merge remote-tracking branch 'upstream/8.x' into 8.x
2 parents a5f4cfa + 8d16ccc commit b7f64d8

File tree

62 files changed

+925
-120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+925
-120
lines changed

src/Illuminate/Collections/Traits/EnumeratesValues.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ public function tap(callable $callback)
730730
* Reduce the collection to a single value.
731731
*
732732
* @param callable $callback
733-
* @param mixed $initial
733+
* @param mixed $initial
734734
* @return mixed
735735
*/
736736
public function reduce(callable $callback, $initial = null)
@@ -748,7 +748,7 @@ public function reduce(callable $callback, $initial = null)
748748
* Reduce an associative collection to a single value.
749749
*
750750
* @param callable $callback
751-
* @param mixed $initial
751+
* @param mixed $initial
752752
* @return mixed
753753
*/
754754
public function reduceWithKeys(callable $callback, $initial = null)

src/Illuminate/Database/Concerns/ManagesTransactions.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ public function transaction(Closure $callback, $attempts = 1)
4343
try {
4444
if ($this->transactions == 1) {
4545
$this->getPdo()->commit();
46-
47-
optional($this->transactionsManager)->commit($this->getName());
4846
}
4947

5048
$this->transactions = max(0, $this->transactions - 1);
49+
50+
if ($this->transactions == 0) {
51+
optional($this->transactionsManager)->commit($this->getName());
52+
}
5153
} catch (Throwable $e) {
5254
$this->handleCommitTransactionException(
5355
$e, $currentAttempt, $attempts
@@ -187,12 +189,14 @@ public function commit()
187189
{
188190
if ($this->transactions == 1) {
189191
$this->getPdo()->commit();
190-
191-
optional($this->transactionsManager)->commit($this->getName());
192192
}
193193

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

196+
if ($this->transactions == 0) {
197+
optional($this->transactionsManager)->commit($this->getName());
198+
}
199+
196200
$this->fireConnectionEvent('committed');
197201
}
198202

src/Illuminate/Database/DetectsLostConnections.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ protected function causedByLostConnection(Throwable $e)
5252
'Temporary failure in name resolution',
5353
'SSL: Broken pipe',
5454
'SQLSTATE[08S01]: Communication link failure',
55+
'SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host',
56+
'SQLSTATE[HY000]: General error: 7 SSL SYSCALL error: No route to host',
5557
]);
5658
}
5759
}

src/Illuminate/Database/Eloquent/Builder.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,16 @@ protected static function registerMixin($mixin, $replace)
16081608
}
16091609
}
16101610

1611+
/**
1612+
* Clone the Eloquent query builder.
1613+
*
1614+
* @return static
1615+
*/
1616+
public function clone()
1617+
{
1618+
return clone $this;
1619+
}
1620+
16111621
/**
16121622
* Force a clone of the underlying query builder when cloning.
16131623
*

src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ public function setAttribute($key, $value)
695695
{
696696
// First we will check for the presence of a mutator for the set operation
697697
// which simply lets the developers tweak the attribute as it is set on
698-
// the model, such as "json_encoding" an listing of data for storage.
698+
// this model, such as "json_encoding" a listing of data for storage.
699699
if ($this->hasSetMutator($key)) {
700700
return $this->setMutatedAttributeValue($key, $value);
701701
}
@@ -1322,6 +1322,16 @@ public function getAttributes()
13221322
return $this->attributes;
13231323
}
13241324

1325+
/**
1326+
* Get all of the current attributes on the model for an insert operation.
1327+
*
1328+
* @return array
1329+
*/
1330+
protected function getAttributesForInsert()
1331+
{
1332+
return $this->getAttributes();
1333+
}
1334+
13251335
/**
13261336
* Set the array of model attributes. No checking is done.
13271337
*

src/Illuminate/Database/Eloquent/Concerns/HidesAttributes.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ public function makeVisible($attributes)
9494
*/
9595
public function makeVisibleIf($condition, $attributes)
9696
{
97-
$condition = $condition instanceof Closure ? $condition($this) : $condition;
98-
99-
return $condition ? $this->makeVisible($attributes) : $this;
97+
return value($condition, $this) ? $this->makeVisible($attributes) : $this;
10098
}
10199

102100
/**
@@ -123,8 +121,6 @@ public function makeHidden($attributes)
123121
*/
124122
public function makeHiddenIf($condition, $attributes)
125123
{
126-
$condition = $condition instanceof Closure ? $condition($this) : $condition;
127-
128-
return value($condition) ? $this->makeHidden($attributes) : $this;
124+
return value($condition, $this) ? $this->makeHidden($attributes) : $this;
129125
}
130126
}

src/Illuminate/Database/Eloquent/Model.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Illuminate\Database\Eloquent;
44

55
use ArrayAccess;
6-
use Exception;
76
use Illuminate\Contracts\Queue\QueueableCollection;
87
use Illuminate\Contracts\Queue\QueueableEntity;
98
use Illuminate\Contracts\Routing\UrlRoutable;
@@ -20,6 +19,7 @@
2019
use Illuminate\Support\Str;
2120
use Illuminate\Support\Traits\ForwardsCalls;
2221
use JsonSerializable;
22+
use LogicException;
2323

2424
abstract class Model implements Arrayable, ArrayAccess, Jsonable, JsonSerializable, QueueableEntity, UrlRoutable
2525
{
@@ -1011,7 +1011,7 @@ protected function performInsert(Builder $query)
10111011
// If the model has an incrementing key, we can use the "insertGetId" method on
10121012
// the query builder, which will give us back the final inserted ID for this
10131013
// table from the database. Not all tables have to be incrementing though.
1014-
$attributes = $this->getAttributes();
1014+
$attributes = $this->getAttributesForInsert();
10151015

10161016
if ($this->getIncrementing()) {
10171017
$this->insertAndSetId($query, $attributes);
@@ -1097,14 +1097,14 @@ public static function destroy($ids)
10971097
*
10981098
* @return bool|null
10991099
*
1100-
* @throws \Exception
1100+
* @throws \LogicException
11011101
*/
11021102
public function delete()
11031103
{
11041104
$this->mergeAttributesFromClassCasts();
11051105

11061106
if (is_null($this->getKeyName())) {
1107-
throw new Exception('No primary key defined on model.');
1107+
throw new LogicException('No primary key defined on model.');
11081108
}
11091109

11101110
// If the model doesn't exist, there is nothing to delete so we'll just return

src/Illuminate/Database/Events/MigrationEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
abstract class MigrationEvent implements MigrationEventContract
99
{
1010
/**
11-
* An migration instance.
11+
* A migration instance.
1212
*
1313
* @var \Illuminate\Database\Migrations\Migration
1414
*/

src/Illuminate/Database/Migrations/Migrator.php

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Illuminate\Support\Arr;
1414
use Illuminate\Support\Collection;
1515
use Illuminate\Support\Str;
16+
use ReflectionClass;
1617
use Symfony\Component\Console\Output\OutputInterface;
1718

1819
class Migrator
@@ -185,9 +186,9 @@ protected function runUp($file, $batch, $pretend)
185186
// First we will resolve a "real" instance of the migration class from this
186187
// migration file name. Once we have the instances we can run the actual
187188
// command such as "up" or "down", or we can just simulate the action.
188-
$migration = $this->resolve(
189-
$name = $this->getMigrationName($file)
190-
);
189+
$migration = $this->resolvePath($file);
190+
191+
$name = $this->getMigrationName($file);
191192

192193
if ($pretend) {
193194
return $this->pretendToRun($migration, 'up');
@@ -348,9 +349,9 @@ protected function runDown($file, $migration, $pretend)
348349
// First we will get the file name of the migration so we can resolve out an
349350
// instance of the migration. Once we get an instance we can either run a
350351
// pretend execution of the migration or we can run the real migration.
351-
$instance = $this->resolve(
352-
$name = $this->getMigrationName($file)
353-
);
352+
$instance = $this->resolvePath($file);
353+
354+
$name = $this->getMigrationName($file);
354355

355356
$this->note("<comment>Rolling back:</comment> {$name}");
356357

@@ -413,6 +414,12 @@ protected function pretendToRun($migration, $method)
413414
foreach ($this->getQueries($migration, $method) as $query) {
414415
$name = get_class($migration);
415416

417+
$reflectionClass = new ReflectionClass($migration);
418+
419+
if ($reflectionClass->isAnonymous()) {
420+
$name = $this->getMigrationName($reflectionClass->getFileName());
421+
}
422+
416423
$this->note("<info>{$name}:</info> {$query['query']}");
417424
}
418425
}
@@ -448,11 +455,39 @@ protected function getQueries($migration, $method)
448455
*/
449456
public function resolve($file)
450457
{
451-
$class = Str::studly(implode('_', array_slice(explode('_', $file), 4)));
458+
$class = $this->getMigrationClass($file);
452459

453460
return new $class;
454461
}
455462

463+
/**
464+
* Resolve a migration instance from a migration path.
465+
*
466+
* @param string $path
467+
* @return object
468+
*/
469+
protected function resolvePath(string $path)
470+
{
471+
$class = $this->getMigrationClass($this->getMigrationName($path));
472+
473+
if (class_exists($class) && realpath($path) == (new ReflectionClass($class))->getFileName()) {
474+
return new $class;
475+
}
476+
477+
return $this->files->getRequire($path);
478+
}
479+
480+
/**
481+
* Generate a migration class name based on the migration file name.
482+
*
483+
* @param string $migrationName
484+
* @return string
485+
*/
486+
protected function getMigrationClass(string $migrationName): string
487+
{
488+
return Str::studly(implode('_', array_slice(explode('_', $migrationName), 4)));
489+
}
490+
456491
/**
457492
* Get all of the migration files in a given path.
458493
*

src/Illuminate/Database/Query/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public function select($columns = ['*'])
244244
/**
245245
* Add a subselect expression to the query.
246246
*
247-
* @param \Closure|\Illuminate\Database\Query\Builder|string $query
247+
* @param \Closure|\Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder|string $query
248248
* @param string $as
249249
* @return $this
250250
*

0 commit comments

Comments
 (0)