From 7aab67d59bb920293bb6c49e60aaa00a30f78673 Mon Sep 17 00:00:00 2001 From: Gaitholabi <24876890+Gaitholabi@users.noreply.github.com> Date: Tue, 18 Apr 2023 21:18:06 +0300 Subject: [PATCH 1/2] [10.x] Allow separate directory for locks on filestore (#46811) * allow separate directory for locks on filestore * fix style * fix method signature * Update src/Illuminate/Cache/FileStore.php Co-authored-by: Dries Vints * apply styleci * formatting --------- Co-authored-by: Dries Vints Co-authored-by: Taylor Otwell --- src/Illuminate/Cache/CacheManager.php | 5 ++++- src/Illuminate/Cache/FileStore.php | 29 ++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Cache/CacheManager.php b/src/Illuminate/Cache/CacheManager.php index 98babebf91fb..a821f9261e13 100755 --- a/src/Illuminate/Cache/CacheManager.php +++ b/src/Illuminate/Cache/CacheManager.php @@ -144,7 +144,10 @@ protected function createArrayDriver(array $config) */ protected function createFileDriver(array $config) { - return $this->repository(new FileStore($this->app['files'], $config['path'], $config['permission'] ?? null)); + return $this->repository( + (new FileStore($this->app['files'], $config['path'], $config['permission'] ?? null)) + ->setLockDirectory($config['lock_path'] ?? null) + ); } /** diff --git a/src/Illuminate/Cache/FileStore.php b/src/Illuminate/Cache/FileStore.php index 7202ee63bc6a..424ca63d43c6 100755 --- a/src/Illuminate/Cache/FileStore.php +++ b/src/Illuminate/Cache/FileStore.php @@ -28,6 +28,13 @@ class FileStore implements Store, LockProvider */ protected $directory; + /** + * The file cache lock directory. + * + * @var string|null + */ + protected $lockDirectory; + /** * Octal representation of the cache file permissions. * @@ -210,7 +217,14 @@ public function forever($key, $value) */ public function lock($name, $seconds = 0, $owner = null) { - return new FileLock($this, $name, $seconds, $owner); + $this->ensureCacheDirectoryExists($this->lockDirectory ?? $this->directory); + + return new FileLock( + new static($this->files, $this->lockDirectory ?? $this->directory, $this->filePermission), + $name, + $seconds, + $owner + ); } /** @@ -364,6 +378,19 @@ public function getDirectory() return $this->directory; } + /** + * Set the cache directory where locks should be stored. + * + * @param string|null $lockDirectory + * @return $this + */ + public function setLockDirectory($lockDirectory) + { + $this->lockDirectory = $lockDirectory; + + return $this; + } + /** * Get the cache key prefix. * From 95ffddc3e4240d230284ef4ccfb73d968d7ca5a4 Mon Sep 17 00:00:00 2001 From: masoud derakhshi <59544612+mderakhshi@users.noreply.github.com> Date: Tue, 18 Apr 2023 22:00:04 +0330 Subject: [PATCH 2/2] [10.x] whereMorphedTo null (#46821) * Update QueriesRelationships.php * Update DatabaseEloquentBuilderTest.php * Update DatabaseEloquentBuilderTest.php * Update DatabaseEloquentBuilderTest.php --- .../Concerns/QueriesRelationships.php | 8 ++++++-- .../Database/DatabaseEloquentBuilderTest.php | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php b/src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php index 2412bc68fd03..5933f192ebb9 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php +++ b/src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php @@ -448,7 +448,7 @@ public function orWhereMorphRelation($relation, $types, $column, $operator = nul * Add a morph-to relationship condition to the query. * * @param \Illuminate\Database\Eloquent\Relations\MorphTo|string $relation - * @param \Illuminate\Database\Eloquent\Model|string $model + * @param \Illuminate\Database\Eloquent\Model|string|null $model * @return \Illuminate\Database\Eloquent\Builder|static */ public function whereMorphedTo($relation, $model, $boolean = 'and') @@ -457,6 +457,10 @@ public function whereMorphedTo($relation, $model, $boolean = 'and') $relation = $this->getRelationWithoutConstraints($relation); } + if (is_null($model)) { + return $this->whereNull($relation->getMorphType(), $boolean); + } + if (is_string($model)) { $morphMap = Relation::morphMap(); @@ -506,7 +510,7 @@ public function whereNotMorphedTo($relation, $model, $boolean = 'and') * Add a morph-to relationship condition to the query with an "or where" clause. * * @param \Illuminate\Database\Eloquent\Relations\MorphTo|string $relation - * @param \Illuminate\Database\Eloquent\Model|string $model + * @param \Illuminate\Database\Eloquent\Model|string|null $model * @return \Illuminate\Database\Eloquent\Builder|static */ public function orWhereMorphedTo($relation, $model) diff --git a/tests/Database/DatabaseEloquentBuilderTest.php b/tests/Database/DatabaseEloquentBuilderTest.php index 2d73e8a7dba6..0584af163d82 100755 --- a/tests/Database/DatabaseEloquentBuilderTest.php +++ b/tests/Database/DatabaseEloquentBuilderTest.php @@ -1660,6 +1660,15 @@ public function testWhereMorphedTo() $this->assertEquals([$relatedModel->getMorphClass(), $relatedModel->getKey()], $builder->getBindings()); } + public function testWhereMorphedToNull() + { + $model = new EloquentBuilderTestModelParentStub; + $this->mockConnectionForModel($model, ''); + + $builder = $model->whereMorphedTo('morph', null); + $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where "morph_type" is null', $builder->toSql()); + } + public function testWhereNotMorphedTo() { $model = new EloquentBuilderTestModelParentStub; @@ -1688,6 +1697,17 @@ public function testOrWhereMorphedTo() $this->assertEquals(['baz', $relatedModel->getMorphClass(), $relatedModel->getKey()], $builder->getBindings()); } + public function testOrWhereMorphedToNull() + { + $model = new EloquentBuilderTestModelParentStub; + $this->mockConnectionForModel($model, ''); + + $builder = $model->where('bar', 'baz')->orWhereMorphedTo('morph', null); + + $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where "bar" = ? or "morph_type" is null', $builder->toSql()); + $this->assertEquals(['baz'], $builder->getBindings()); + } + public function testOrWhereNotMorphedTo() { $model = new EloquentBuilderTestModelParentStub;