Skip to content

Commit 6f575fc

Browse files
committed
Merge remote-tracking branch 'origin/10.x' into 10.x
2 parents 3259360 + 95ffddc commit 6f575fc

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

src/Illuminate/Cache/CacheManager.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ protected function createArrayDriver(array $config)
144144
*/
145145
protected function createFileDriver(array $config)
146146
{
147-
return $this->repository(new FileStore($this->app['files'], $config['path'], $config['permission'] ?? null));
147+
return $this->repository(
148+
(new FileStore($this->app['files'], $config['path'], $config['permission'] ?? null))
149+
->setLockDirectory($config['lock_path'] ?? null)
150+
);
148151
}
149152

150153
/**

src/Illuminate/Cache/FileStore.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ class FileStore implements Store, LockProvider
2828
*/
2929
protected $directory;
3030

31+
/**
32+
* The file cache lock directory.
33+
*
34+
* @var string|null
35+
*/
36+
protected $lockDirectory;
37+
3138
/**
3239
* Octal representation of the cache file permissions.
3340
*
@@ -210,7 +217,14 @@ public function forever($key, $value)
210217
*/
211218
public function lock($name, $seconds = 0, $owner = null)
212219
{
213-
return new FileLock($this, $name, $seconds, $owner);
220+
$this->ensureCacheDirectoryExists($this->lockDirectory ?? $this->directory);
221+
222+
return new FileLock(
223+
new static($this->files, $this->lockDirectory ?? $this->directory, $this->filePermission),
224+
$name,
225+
$seconds,
226+
$owner
227+
);
214228
}
215229

216230
/**
@@ -364,6 +378,19 @@ public function getDirectory()
364378
return $this->directory;
365379
}
366380

381+
/**
382+
* Set the cache directory where locks should be stored.
383+
*
384+
* @param string|null $lockDirectory
385+
* @return $this
386+
*/
387+
public function setLockDirectory($lockDirectory)
388+
{
389+
$this->lockDirectory = $lockDirectory;
390+
391+
return $this;
392+
}
393+
367394
/**
368395
* Get the cache key prefix.
369396
*

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ public function orWhereMorphRelation($relation, $types, $column, $operator = nul
448448
* Add a morph-to relationship condition to the query.
449449
*
450450
* @param \Illuminate\Database\Eloquent\Relations\MorphTo|string $relation
451-
* @param \Illuminate\Database\Eloquent\Model|string $model
451+
* @param \Illuminate\Database\Eloquent\Model|string|null $model
452452
* @return \Illuminate\Database\Eloquent\Builder|static
453453
*/
454454
public function whereMorphedTo($relation, $model, $boolean = 'and')
@@ -457,6 +457,10 @@ public function whereMorphedTo($relation, $model, $boolean = 'and')
457457
$relation = $this->getRelationWithoutConstraints($relation);
458458
}
459459

460+
if (is_null($model)) {
461+
return $this->whereNull($relation->getMorphType(), $boolean);
462+
}
463+
460464
if (is_string($model)) {
461465
$morphMap = Relation::morphMap();
462466

@@ -506,7 +510,7 @@ public function whereNotMorphedTo($relation, $model, $boolean = 'and')
506510
* Add a morph-to relationship condition to the query with an "or where" clause.
507511
*
508512
* @param \Illuminate\Database\Eloquent\Relations\MorphTo|string $relation
509-
* @param \Illuminate\Database\Eloquent\Model|string $model
513+
* @param \Illuminate\Database\Eloquent\Model|string|null $model
510514
* @return \Illuminate\Database\Eloquent\Builder|static
511515
*/
512516
public function orWhereMorphedTo($relation, $model)

tests/Database/DatabaseEloquentBuilderTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,15 @@ public function testWhereMorphedTo()
16601660
$this->assertEquals([$relatedModel->getMorphClass(), $relatedModel->getKey()], $builder->getBindings());
16611661
}
16621662

1663+
public function testWhereMorphedToNull()
1664+
{
1665+
$model = new EloquentBuilderTestModelParentStub;
1666+
$this->mockConnectionForModel($model, '');
1667+
1668+
$builder = $model->whereMorphedTo('morph', null);
1669+
$this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where "morph_type" is null', $builder->toSql());
1670+
}
1671+
16631672
public function testWhereNotMorphedTo()
16641673
{
16651674
$model = new EloquentBuilderTestModelParentStub;
@@ -1688,6 +1697,17 @@ public function testOrWhereMorphedTo()
16881697
$this->assertEquals(['baz', $relatedModel->getMorphClass(), $relatedModel->getKey()], $builder->getBindings());
16891698
}
16901699

1700+
public function testOrWhereMorphedToNull()
1701+
{
1702+
$model = new EloquentBuilderTestModelParentStub;
1703+
$this->mockConnectionForModel($model, '');
1704+
1705+
$builder = $model->where('bar', 'baz')->orWhereMorphedTo('morph', null);
1706+
1707+
$this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where "bar" = ? or "morph_type" is null', $builder->toSql());
1708+
$this->assertEquals(['baz'], $builder->getBindings());
1709+
}
1710+
16911711
public function testOrWhereNotMorphedTo()
16921712
{
16931713
$model = new EloquentBuilderTestModelParentStub;

0 commit comments

Comments
 (0)