From f6c8c86f971c4bb38cf1309de30a44bbcdbe0136 Mon Sep 17 00:00:00 2001 From: Michael Deck Date: Wed, 24 May 2023 09:32:53 -0400 Subject: [PATCH 01/11] rebase - Fix logic of where method to work with whereNot --- src/Database/Query/FMBaseBuilder.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Database/Query/FMBaseBuilder.php b/src/Database/Query/FMBaseBuilder.php index 9086da2..47500a3 100644 --- a/src/Database/Query/FMBaseBuilder.php +++ b/src/Database/Query/FMBaseBuilder.php @@ -11,6 +11,7 @@ use Illuminate\Pagination\Paginator; use Illuminate\Support\Arr; use Illuminate\Support\Collection; +use Illuminate\Support\Str; use InvalidArgumentException; class FMBaseBuilder extends Builder @@ -145,10 +146,22 @@ class FMBaseBuilder extends Builder */ public function where($column, $operator = null, $value = null, $boolean = 'and'): FMBaseBuilder { + $shouldBeOmit = false; + + if (Str::contains($boolean, 'not')) { + $shouldBeOmit = true; + $boolean = trim(str_replace('not', '', $boolean)); + } + // This is an "orWhere" type query, so add a find request and then work from there if ($boolean === 'or') { $this->addFindRequest(); } + + if ($shouldBeOmit) { + $this->omit(); + } + // If the column is an array, we will assume it is an array of key-value pairs // and can add them each as a where clause. We will maintain the boolean we // received when the method was called and pass it into the nested where. From 29464291d4dc20dd9be98fd3d8219a4153a6fc53 Mon Sep 17 00:00:00 2001 From: Michael Deck Date: Fri, 2 Jun 2023 10:22:45 -0400 Subject: [PATCH 02/11] Rework the way that whereNot is handled --- src/Database/Eloquent/FMEloquentBuilder.php | 41 ++++++++++++++ src/Database/Query/FMBaseBuilder.php | 61 ++++++++++++++------- 2 files changed, 82 insertions(+), 20 deletions(-) diff --git a/src/Database/Eloquent/FMEloquentBuilder.php b/src/Database/Eloquent/FMEloquentBuilder.php index 2904977..8760782 100644 --- a/src/Database/Eloquent/FMEloquentBuilder.php +++ b/src/Database/Eloquent/FMEloquentBuilder.php @@ -7,6 +7,7 @@ use GearboxSolutions\EloquentFileMaker\Exceptions\FileMakerDataApiException; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Scope; use Illuminate\Pagination\Paginator; use Illuminate\Support\Arr; use Illuminate\Support\Collection; @@ -288,4 +289,44 @@ protected function getOnlyModifiedPortalFields($array1, $array2): array return $result; } + + /** + * Apply the given scope on the current builder instance. + * + * @return mixed + */ + protected function callScope(callable $scope, array $parameters = []) + { + array_unshift($parameters, $this); + + $query = $this->getQuery(); + + $result = $this; + + $scopeApplied = false; + + foreach ($query->wheres as $index => $find) { + if (($find['omit'] ?? 'false') === 'true') { + continue; + } + + $query->setFindRequestIndex($index); + + $result = $scope(...$parameters) ?? $this; + + $scopeApplied = true; + } + + if (! $scopeApplied) { + array_unshift($query->wheres, []); + + $query->setFindRequestIndex(0); + + $result = $scope(...$parameters) ?? $this; + } + + $query->unsetFindRequestIndex(); + + return $result; + } } diff --git a/src/Database/Query/FMBaseBuilder.php b/src/Database/Query/FMBaseBuilder.php index 47500a3..ae57b44 100644 --- a/src/Database/Query/FMBaseBuilder.php +++ b/src/Database/Query/FMBaseBuilder.php @@ -103,6 +103,8 @@ class FMBaseBuilder extends Builder */ public array $offsetPortals = []; + protected $currentFindRequestIndex; + public const ASCEND = 'ascend'; public const DESCEND = 'descend'; @@ -154,13 +156,13 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' } // This is an "orWhere" type query, so add a find request and then work from there - if ($boolean === 'or') { + if ($boolean === 'or' || $shouldBeOmit) { $this->addFindRequest(); - } if ($shouldBeOmit) { $this->omit(); } + } // If the column is an array, we will assume it is an array of key-value pairs // and can add them each as a where clause. We will maintain the boolean we @@ -182,20 +184,12 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' $value, $operator, func_num_args() === 2 ); - // we should add this where clause as an AND to the current find request - // This allows us to chain wheres - // Create a new find array if null - $count = count($this->wheres); - if ($count == 0) { - $currentFind = []; - } else { - $currentFind = $this->wheres[count($this->wheres) - 1]; - } + $currentFind = $this->getCurrentFind(); $currentFind[$this->getMappedFieldName($column)] = $operator . $value; // add the where clause KvP to the last item in the array of wheres - $this->wheres[$count > 1 ? $count - 1 : 0] = $currentFind; + $this->updateCurrentFind($currentFind); return $this; } @@ -535,21 +529,36 @@ public function setFieldMapping($fieldMapping): void */ public function omit($boolean = true): FMBaseBuilder { - $count = count($this->wheres); - if ($count == 0) { - $currentFind = []; - $count = 1; - } else { - $currentFind = $this->wheres[count($this->wheres) - 1]; - } + $currentFind = $this->getCurrentFind(); $currentFind['omit'] = $boolean ? 'true' : 'false'; - $this->wheres[$count - 1] = $currentFind; + $this->updateCurrentFind($currentFind); return $this; } + /** + * we should add this where clause as an AND to the current find request + * This allows us to chain wheres + * Create a new find array if null + */ + protected function getCurrentFind() + { + $count = count($this->wheres); + + if ($count === 0) { + $this->addFindRequest(); + } + + return $this->wheres[$this->currentFindRequestIndex ?? count($this->wheres) - 1]; + } + + protected function updateCurrentFind($find) + { + $this->wheres[$this->currentFindRequestIndex ?? count($this->wheres) - 1] = $find; + } + public function whereIn($column, $values, $boolean = 'and', $not = false) { throw_if($boolean === 'or', new \RuntimeException('Eloquent FileMaker does not currently support or within a where in')); @@ -788,6 +797,8 @@ public function whereNull($columns, $boolean = 'and', $not = false) protected function addFindRequest() { array_push($this->wheres, []); + + $this->unsetFindRequestIndex(); } /** @@ -928,4 +939,14 @@ public function whereDate($column, $operator, $value = null, $boolean = 'and') return $this->where($column, $operator, $value, $boolean); } + + public function setFindRequestIndex($index) + { + $this->currentFindRequestIndex = $index; + } + + public function unsetFindRequestIndex() + { + unset($this->currentFindRequestIndex); + } } From 9a566595ce909be6ac6ea13fbc7210326cdaf6fa Mon Sep 17 00:00:00 2001 From: Michael Deck Date: Fri, 2 Jun 2023 10:42:58 -0400 Subject: [PATCH 03/11] Add check to make sure that no empty find requests are passed out as a result of applying the global scopes --- src/Database/Eloquent/FMEloquentBuilder.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Database/Eloquent/FMEloquentBuilder.php b/src/Database/Eloquent/FMEloquentBuilder.php index 8760782..3beaaa5 100644 --- a/src/Database/Eloquent/FMEloquentBuilder.php +++ b/src/Database/Eloquent/FMEloquentBuilder.php @@ -290,6 +290,23 @@ protected function getOnlyModifiedPortalFields($array1, $array2): array return $result; } + public function applyScopes() + { + $builder = parent::applyScopes(); + + $query = $builder->getQuery(); + + foreach ($query->wheres as $index => $find) { + if (! empty($find)) { + continue; + } + + unset($query->wheres[$index]); + } + + return $builder; + } + /** * Apply the given scope on the current builder instance. * From 6e55a5159b4934aba5478c29e857c62cdbb31341 Mon Sep 17 00:00:00 2001 From: Michael Deck Date: Fri, 2 Jun 2023 10:47:12 -0400 Subject: [PATCH 04/11] Fix code style --- src/Database/Query/FMBaseBuilder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Database/Query/FMBaseBuilder.php b/src/Database/Query/FMBaseBuilder.php index ae57b44..bb3082b 100644 --- a/src/Database/Query/FMBaseBuilder.php +++ b/src/Database/Query/FMBaseBuilder.php @@ -159,9 +159,9 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' if ($boolean === 'or' || $shouldBeOmit) { $this->addFindRequest(); - if ($shouldBeOmit) { - $this->omit(); - } + if ($shouldBeOmit) { + $this->omit(); + } } // If the column is an array, we will assume it is an array of key-value pairs From 05a36c07372a8f974b939dd0718314314eedbbce Mon Sep 17 00:00:00 2001 From: Michael Deck Date: Wed, 2 Aug 2023 13:37:20 -0400 Subject: [PATCH 05/11] Update the way whereIns are computed --- src/Database/Eloquent/FMEloquentBuilder.php | 2 +- src/Database/Query/FMBaseBuilder.php | 128 +++++++++++++++----- src/Services/FileMakerConnection.php | 14 ++- 3 files changed, 112 insertions(+), 32 deletions(-) diff --git a/src/Database/Eloquent/FMEloquentBuilder.php b/src/Database/Eloquent/FMEloquentBuilder.php index 3beaaa5..570b337 100644 --- a/src/Database/Eloquent/FMEloquentBuilder.php +++ b/src/Database/Eloquent/FMEloquentBuilder.php @@ -342,7 +342,7 @@ protected function callScope(callable $scope, array $parameters = []) $result = $scope(...$parameters) ?? $this; } - $query->unsetFindRequestIndex(); + $query->resetFindRequestIndex(); return $result; } diff --git a/src/Database/Query/FMBaseBuilder.php b/src/Database/Query/FMBaseBuilder.php index bb3082b..90f2d20 100644 --- a/src/Database/Query/FMBaseBuilder.php +++ b/src/Database/Query/FMBaseBuilder.php @@ -103,7 +103,10 @@ class FMBaseBuilder extends Builder */ public array $offsetPortals = []; - protected $currentFindRequestIndex; + /** + * @var int The index of the current request in the find request array + */ + protected int $currentFindRequestIndex = -1; public const ASCEND = 'ascend'; @@ -141,8 +144,25 @@ class FMBaseBuilder extends Builder public $containerFile; + /** + * Array to track the whereIn clauses because FM processes WhereIns differently than other DB engines + * + * @var array + */ protected $whereIns = []; + /** + * Flag to be used to enforce that FileMaker Data API gives us an empty set instead of erroring or returning unexpected records + * + * @var bool = false + */ + protected $forceHighOffset = false; + + public function isForcingHighOffset() + { + return $this->forceHighOffset; + } + /** * Add a basic where clause to the query. */ @@ -545,33 +565,45 @@ public function omit($boolean = true): FMBaseBuilder */ protected function getCurrentFind() { - $count = count($this->wheres); - - if ($count === 0) { + if ($this->currentFindRequestIndex === -1) { $this->addFindRequest(); } - return $this->wheres[$this->currentFindRequestIndex ?? count($this->wheres) - 1]; + return $this->wheres[$this->currentFindRequestIndex]; } protected function updateCurrentFind($find) { - $this->wheres[$this->currentFindRequestIndex ?? count($this->wheres) - 1] = $find; + $this->wheres[$this->currentFindRequestIndex] = $find; } public function whereIn($column, $values, $boolean = 'and', $not = false) { - throw_if($boolean === 'or', new \RuntimeException('Eloquent FileMaker does not currently support or within a where in')); + dump([$column, $values, $boolean, $not, $this->currentFindRequestIndex]); + if ($boolean === 'or' || $not) { + $this->addFindRequest(); + + if ($not) { + $this->omit(); + } + } + + dump($this->currentFindRequestIndex); if ($values instanceof Arrayable) { $values = $values->toArray(); } + // We don't need the current find request but in the case that 0 finds are already performed, + // this will create the first one. + $this->getCurrentFind(); + $this->whereIns[] = [ 'column' => $this->getMappedFieldName($column), 'values' => $values, 'boolean' => $boolean, 'not' => $not, + 'findRequestIndex' => $this->currentFindRequestIndex, ]; return $this; @@ -584,40 +616,67 @@ protected function computeWhereIns() return; } - $whereIns = array_map(function ($whereIn) { + $whereInRequests = collect($this->whereIns)->mapToGroups(function ($whereIn) { $finds = []; - foreach ($whereIn['values'] as $value) { - $find = [ - $whereIn['column'] => $value, - ]; + // If the list of values in a whereIn clause is empty we want the end query to return an empty set instead of other records. + if (empty($whereIn['values'])) { + $this->forceHighOffset = true; - if ($whereIn['not']) { - $find['omit'] = true; + if ($this->isWheresEmpty()) { + $finds[] = [ + $whereIn['column'] => '=', + ]; } + } else { + foreach ($whereIn['values'] as $value) { + $find = [ + $whereIn['column'] => $value, + ]; + + if ($whereIn['not']) { + $find['omit'] = true; + } - $finds[] = $find; + $finds[] = $find; + } } - return $finds; - }, $this->whereIns); + return [$whereIn['findRequestIndex'] => $finds]; + }); - if (empty($this->wheres)) { - $this->wheres = Arr::flatten($whereIns, 1); + if ($this->isWheresEmpty()) { + $this->wheres = $whereInRequests->flatten(2)->toArray(); return; } - $arr = Arr::crossJoin($this->wheres, ...$whereIns); - $function = function ($conditions) { - return array_merge(...array_values($conditions)); - }; + $newWheres = []; - if (empty($arr)) { - return; + // loop through each where + // If it is an omit, skip it + // If the where in is an omit, skip it + foreach ($this->wheres as $index => $where) { + $whereInValues = $whereInRequests->get($index)?->first() ?? []; + + if (($where['omit'] ?? 'false') === 'true') { + if (count(array_keys($where)) > 1 || (count(array_keys($where)) === 1 && (collect($whereInValues)->value('omit') ?? 'false') === 'false')) { + $newWheres[] = $where; + + continue; + } + } + + if (empty($whereInValues)) { + $newWheres[] = $where; + } else { + foreach ($whereInValues as $whereInValue) { + $newWheres[] = array_merge($where, $whereInValue); + } + } } - $this->wheres = array_map($function, $arr); + $this->wheres = $newWheres; } /** @@ -798,7 +857,7 @@ protected function addFindRequest() { array_push($this->wheres, []); - $this->unsetFindRequestIndex(); + $this->setFindRequestIndex(count($this->wheres) - 1); } /** @@ -940,13 +999,24 @@ public function whereDate($column, $operator, $value = null, $boolean = 'and') return $this->where($column, $operator, $value, $boolean); } + protected function isWheresEmpty() + { + $wheres = collect($this->wheres); + + if ($wheres->isEmpty()) { + return true; + } + + return collect($wheres->first())->keys()->except(['omit'])->isEmpty(); + } + public function setFindRequestIndex($index) { $this->currentFindRequestIndex = $index; } - public function unsetFindRequestIndex() + public function resetFindRequestIndex() { - unset($this->currentFindRequestIndex); + $this->currentFindRequestIndex = -1; } } diff --git a/src/Services/FileMakerConnection.php b/src/Services/FileMakerConnection.php index 3a9738a..4ad1f87 100644 --- a/src/Services/FileMakerConnection.php +++ b/src/Services/FileMakerConnection.php @@ -35,6 +35,12 @@ class FileMakerConnection extends Connection protected $retries = 1; + /** + * Crazy high number of records to return. + * Used to get an empty set when using a whereIn with no values. + */ + public const CRAZY_RECORDS_AMOUNT = 1000000000000000000; + /** * @param string $layout * @return $this @@ -214,14 +220,18 @@ public function performFind(FMBaseBuilder $query) // If limit hasn't been specified we should set it to be very high to bypass FM's default 100-record limit // This more closely matches Laravel's default behavior if (! isset($query->limit)) { - $query->limit = 1000000000000000000; + $query->limit = self::CRAZY_RECORDS_AMOUNT; } // if there are no query parameters we need to do a get all records instead of a find - if (empty($query->wheres)) { + if (empty($query->wheres) && ! $query->isForcingHighOffset()) { return $this->getRecords($query); } + // Update the offset to a crazy high offset when the query is forcing 0 records to be returned + // The records call requires that at least 1 + $query->offset($query->isForcingHighOffset() ? self::CRAZY_RECORDS_AMOUNT : $query->offset); + // There are actually query parameters, so prepare to do our find $this->setLayout($query->from); $url = $this->getLayoutUrl() . '/_find'; From f1abdb335259b61feaa34ed5ee5384ea08234edb Mon Sep 17 00:00:00 2001 From: Michael Deck Date: Wed, 2 Aug 2023 14:28:28 -0400 Subject: [PATCH 06/11] Remove debug statements --- src/Database/Query/FMBaseBuilder.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Database/Query/FMBaseBuilder.php b/src/Database/Query/FMBaseBuilder.php index 90f2d20..4b01dfd 100644 --- a/src/Database/Query/FMBaseBuilder.php +++ b/src/Database/Query/FMBaseBuilder.php @@ -579,7 +579,6 @@ protected function updateCurrentFind($find) public function whereIn($column, $values, $boolean = 'and', $not = false) { - dump([$column, $values, $boolean, $not, $this->currentFindRequestIndex]); if ($boolean === 'or' || $not) { $this->addFindRequest(); @@ -588,8 +587,6 @@ public function whereIn($column, $values, $boolean = 'and', $not = false) } } - dump($this->currentFindRequestIndex); - if ($values instanceof Arrayable) { $values = $values->toArray(); } From f04328af85c05b5a94c6a8475b3b6b1211834177 Mon Sep 17 00:00:00 2001 From: Michael Deck Date: Wed, 16 Aug 2023 11:23:15 -0400 Subject: [PATCH 07/11] Update where not logic and add the addArrayOfWheres method --- src/Database/Query/FMBaseBuilder.php | 78 +++++++++++++++++++++------- src/Services/FileMakerConnection.php | 11 +++- 2 files changed, 68 insertions(+), 21 deletions(-) diff --git a/src/Database/Query/FMBaseBuilder.php b/src/Database/Query/FMBaseBuilder.php index 4b01dfd..2ae05d2 100644 --- a/src/Database/Query/FMBaseBuilder.php +++ b/src/Database/Query/FMBaseBuilder.php @@ -176,13 +176,13 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' } // This is an "orWhere" type query, so add a find request and then work from there - if ($boolean === 'or' || $shouldBeOmit) { + if ($boolean === 'or' || ($shouldBeOmit && ! $this->isCurrentFindAnOmit())) { $this->addFindRequest(); + } if ($shouldBeOmit) { $this->omit(); } - } // If the column is an array, we will assume it is an array of key-value pairs // and can add them each as a where clause. We will maintain the boolean we @@ -190,9 +190,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' // // If the first value is an array it means the second value is an omit for the whole request if (is_array($column)) { - foreach ($column as $eachColumn => $eachValue) { - $this->where($eachColumn, $eachValue); - } + $this->addArrayOfWheres($column, $boolean); return $this; } @@ -214,6 +212,19 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' return $this; } + protected function addArrayOfWheres($column, $boolean, $method = 'where') + { + foreach ($column as $key => $value) { + if (is_numeric($key) && is_array($value)) { + $this->{$method}(...array_values($value)); + } else { + $this->{$method}($key, '', $value, 'and'); + } + } + + return $this; + } + /** * Delete records from the database. * @@ -572,6 +583,15 @@ protected function getCurrentFind() return $this->wheres[$this->currentFindRequestIndex]; } + protected function isCurrentFindAnOmit() + { + if ($this->currentFindRequestIndex === -1) { + return false; + } + + return Arr::get($this->wheres, "{$this->currentFindRequestIndex}.omit", 'false') === 'true'; + } + protected function updateCurrentFind($find) { $this->wheres[$this->currentFindRequestIndex] = $find; @@ -606,11 +626,11 @@ public function whereIn($column, $values, $boolean = 'and', $not = false) return $this; } - protected function computeWhereIns() + public function computeWhereIns() { // If no where in clauses return if (empty($this->whereIns)) { - return; + return $this; } $whereInRequests = collect($this->whereIns)->mapToGroups(function ($whereIn) { @@ -643,37 +663,57 @@ protected function computeWhereIns() }); if ($this->isWheresEmpty()) { - $this->wheres = $whereInRequests->flatten(2)->toArray(); + $this->wheres = $whereInRequests->map(function ($whereInRequest) { + return Arr::crossJoin(...$whereInRequest->values()); + })->map(function ($findRequest) { + return array_map(function ($clauses) { + return array_merge(...$clauses); + }, $findRequest); + })->flatten(1)->toArray(); - return; + return $this; } - $newWheres = []; + $newWheres = collect([]); // loop through each where // If it is an omit, skip it // If the where in is an omit, skip it foreach ($this->wheres as $index => $where) { - $whereInValues = $whereInRequests->get($index)?->first() ?? []; + $whereInRequest = $whereInRequests->get($index) ?? []; if (($where['omit'] ?? 'false') === 'true') { - if (count(array_keys($where)) > 1 || (count(array_keys($where)) === 1 && (collect($whereInValues)->value('omit') ?? 'false') === 'false')) { - $newWheres[] = $where; + if (count(array_keys($where)) > 1 || (count(array_keys($where)) === 1 && (collect($whereInRequest)->value('omit') ?? 'false') === 'false')) { + $newWheres->push($where); continue; } } - if (empty($whereInValues)) { - $newWheres[] = $where; + if (empty($whereInRequest)) { + $newWheres->push($where); } else { - foreach ($whereInValues as $whereInValue) { - $newWheres[] = array_merge($where, $whereInValue); - } + $newWheres = $newWheres->push(...Arr::crossJoin([$where], ...$whereInRequest->values())); } } - $this->wheres = $newWheres; + $this->wheres = $newWheres + ->map(function ($findRequest) { + if (Arr::isAssoc($findRequest)) { + return $findRequest; + } + + return array_merge(...$findRequest); + })->toArray(); + + return $this; + } + + public function getWheres() + { + $this->computeWhereIns(); + + return $this->wheres; } /** diff --git a/src/Services/FileMakerConnection.php b/src/Services/FileMakerConnection.php index 4ad1f87..dfb2361 100644 --- a/src/Services/FileMakerConnection.php +++ b/src/Services/FileMakerConnection.php @@ -11,6 +11,7 @@ use GuzzleHttp\Middleware; use Illuminate\Database\Connection; use Illuminate\Http\Client\PendingRequest; +use Illuminate\Http\UploadedFile; use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; @@ -449,7 +450,7 @@ public function createRecord(FMBaseBuilder $query) return $response; } - protected function buildPostDataFromQuery(FMBaseBuilder $query) + public function buildPostDataFromQuery(FMBaseBuilder $query) { $postData = []; @@ -553,7 +554,7 @@ protected function isContainer($field) } // if it's an array, it could be a file => filename key-value pair. - // it's a conainer if the first object in the array is a file + // it's a container if the first object in the array is a file if (is_array($field) && count($field) === 2 && $this->isFile($field[0])) { return true; } @@ -561,6 +562,12 @@ protected function isContainer($field) return false; } + protected function isFile($object) + { + return is_a($object, \Illuminate\Http\File::class) || + is_a($object, UploadedFile::class); + } + public function executeScript(FMBaseBuilder $query) { $this->setLayout($query->from); From 0e2a99596ad451c20cfc23ae77fd387ae69cf90b Mon Sep 17 00:00:00 2001 From: Michael Deck Date: Wed, 16 Aug 2023 11:29:12 -0400 Subject: [PATCH 08/11] rebase - Fix code style issues --- src/Database/Query/FMBaseBuilder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Database/Query/FMBaseBuilder.php b/src/Database/Query/FMBaseBuilder.php index 2ae05d2..f43ef75 100644 --- a/src/Database/Query/FMBaseBuilder.php +++ b/src/Database/Query/FMBaseBuilder.php @@ -180,9 +180,9 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' $this->addFindRequest(); } - if ($shouldBeOmit) { - $this->omit(); - } + if ($shouldBeOmit) { + $this->omit(); + } // If the column is an array, we will assume it is an array of key-value pairs // and can add them each as a where clause. We will maintain the boolean we From bec531c7870e6f76249903c9fbb316095aeca0aa Mon Sep 17 00:00:00 2001 From: David Nahodyl Date: Wed, 20 Mar 2024 17:25:05 -0400 Subject: [PATCH 09/11] pint formatting --- src/Database/Query/FMBaseBuilder.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Database/Query/FMBaseBuilder.php b/src/Database/Query/FMBaseBuilder.php index f43ef75..d9c6012 100644 --- a/src/Database/Query/FMBaseBuilder.php +++ b/src/Database/Query/FMBaseBuilder.php @@ -256,6 +256,7 @@ public function delete($id = null): int throw $e; } } + // we deleted the record, return modified count of 1 return 1; } @@ -285,6 +286,7 @@ protected function bulkDeleteFromQuery(): int } } } + // Return the count of deleted records return $deleteCount; } @@ -309,6 +311,7 @@ public function deleteByRecordId(int $recordId): int throw $e; } } + // we deleted the record, return modified count of 1 return 1; } @@ -441,7 +444,7 @@ public function scriptPresortParam(string $param): FMBaseBuilder return $this; } - public function scriptPrerequest(string $scriptName, string $param = null): FMBaseBuilder + public function scriptPrerequest(string $scriptName, ?string $param = null): FMBaseBuilder { $this->scriptPrerequest = $scriptName; @@ -527,7 +530,7 @@ protected function getMappedFieldName(string $column) /** * A helper function to map an entire array of fields and data to their FileMaker field names * - * @param $array array An array of columns and their values + * @param $array array An array of columns and their values */ protected function mapFieldNamesForArray(array $array): array { @@ -772,7 +775,7 @@ public function createRecord() /** * Set the field data to be used when creating or editing a record * - * @param $array array + * @param $array array * @return $this */ public function fieldData(array $array) @@ -785,7 +788,7 @@ public function fieldData(array $array) /** * Set the portal data to be used when creating or updating a record * - * @param $array array + * @param $array array * @return $this */ public function portalData(array $array) @@ -796,8 +799,8 @@ public function portalData(array $array) } /** - * @param string $column The name of the container field - * @param File | UploadedFile | array $file The file to be uploaded to the container or a file and filename array ex: [$file, 'MyFile.pdf'] + * @param string $column The name of the container field + * @param File | UploadedFile | array $file The file to be uploaded to the container or a file and filename array ex: [$file, 'MyFile.pdf'] * @return mixed */ public function setContainer($column, $file) From 5325e68f0536d4c02f9cbe844977cd3eea1bfe8f Mon Sep 17 00:00:00 2001 From: David Nahodyl Date: Wed, 20 Mar 2024 17:25:19 -0400 Subject: [PATCH 10/11] pint formatting --- src/Database/Eloquent/FMEloquentBuilder.php | 5 +++-- src/Database/Eloquent/FMModel.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Database/Eloquent/FMEloquentBuilder.php b/src/Database/Eloquent/FMEloquentBuilder.php index 570b337..3fad885 100644 --- a/src/Database/Eloquent/FMEloquentBuilder.php +++ b/src/Database/Eloquent/FMEloquentBuilder.php @@ -74,6 +74,7 @@ public function exists() throw $e; } } + // It didn't error, so we have something return true; } @@ -263,8 +264,8 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', /** * Compares a model's modified portal data and original portal data and returns portal data with only modified fields and recordIds * - * @param $array1 array The modified portal data - * @param $array2 array The model's original portal data + * @param $array1 array The modified portal data + * @param $array2 array The model's original portal data */ protected function getOnlyModifiedPortalFields($array1, $array2): array { diff --git a/src/Database/Eloquent/FMModel.php b/src/Database/Eloquent/FMModel.php index b571846..dc4768b 100644 --- a/src/Database/Eloquent/FMModel.php +++ b/src/Database/Eloquent/FMModel.php @@ -18,9 +18,9 @@ abstract class FMModel extends Model { + use FMGuardsAttributes; use FMHasAttributes; use FMHasRelationships; - use FMGuardsAttributes; /** * Indicates if the model should be timestamped. From d79fb4dcbe284908a7f13593ffe90ac9e0400d95 Mon Sep 17 00:00:00 2001 From: David Nahodyl Date: Wed, 20 Mar 2024 17:27:16 -0400 Subject: [PATCH 11/11] ping formatting --- src/Support/Facades/FM.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Support/Facades/FM.php b/src/Support/Facades/FM.php index cd20eae..e5b11ed 100644 --- a/src/Support/Facades/FM.php +++ b/src/Support/Facades/FM.php @@ -14,13 +14,10 @@ * @method static FMBaseBuilder table($layoutName) * @method static FMBaseBuilder delete($recordId) * @method static FMBaseBuilder deleteByRecordId($recordId) - - * @method static array setGlobalFields(array $globalFields) * @method static FileMakerConnection connection(string $name = null) * @method static FileMakerConnection setRetries(int $retries) * @method static FileMakerConnection getLayoutMetadata($layoutName = null) - * * @see \Illuminate\Database\DatabaseManager * @see FileMakerConnection