Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 58
0.71.x#662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Merged
0.71.x #662
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
644ed82
Merge pull request #648 from utopia-php/fix-dec-min-0
abnegate 72c2a9c
Revert "Merge pull request #627 from utopia-php/disable-array-index-m…
abnegate 43aaba7
Merge pull request #657 from utopia-php/feat/skipfilters-optional-list
abnegate 7bed756
Invalid argument for invalid value
abnegate 6b1054e
Reapply "Merge pull request #627 from utopia-php/disable-array-index-…
abnegate 85f46c3
Sync
abnegate 20998e2
Align
abnegate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -344,6 +344,11 @@ class Database | ||
| protected bool $filter = true; | ||
| /** | ||
| * @var array<string, bool>|null | ||
| */ | ||
| protected ?array $disabledFilters = []; | ||
| protected bool $validate = true; | ||
| protected bool $preserveDates = false; | ||
| @@ -809,17 +814,35 @@ public function disableFilters(): static | ||
| * | ||
| * @template T | ||
| * @param callable(): T $callback | ||
| * @param array<string>|null $filters | ||
| * @return T | ||
| */ | ||
| public function skipFilters(callable $callback): mixed | ||
| public function skipFilters(callable $callback, ?array $filters = null): mixed | ||
| { | ||
| $initial = $this->filter; | ||
| $this->disableFilters(); | ||
| if (empty($filters)) { | ||
| $initial = $this->filter; | ||
| $this->disableFilters(); | ||
| try { | ||
| return $callback(); | ||
| } finally { | ||
| $this->filter = $initial; | ||
| } | ||
| } | ||
abnegate marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| $previous = $this->filter; | ||
| $previousDisabled = $this->disabledFilters; | ||
| $disabled = []; | ||
| foreach ($filters as $name) { | ||
| $disabled[$name] = true; | ||
| } | ||
| $this->disabledFilters = $disabled; | ||
| try { | ||
| return $callback(); | ||
| } finally { | ||
| $this->filter = $initial; | ||
| $this->filter = $previous; | ||
| $this->disabledFilters = $previousDisabled; | ||
| } | ||
abnegate marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| @@ -5134,7 +5157,7 @@ public function increaseDocumentAttribute( | ||
| int|float|null $max = null | ||
| ): Document { | ||
| if ($value <= 0) { // Can be a float | ||
| throw new DatabaseException('Value must be numeric and greater than 0'); | ||
| throw new \InvalidArgumentException('Value must be numeric and greater than 0'); | ||
| } | ||
abnegate marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| $collection = $this->silent(fn () => $this->getCollection($collection)); | ||
| @@ -5178,7 +5201,7 @@ public function increaseDocumentAttribute( | ||
| } | ||
| } | ||
| if ($max && ($document->getAttribute($attribute) + $value > $max)) { | ||
| if (!\is_null($max) && ($document->getAttribute($attribute) + $value > $max)) { | ||
| throw new LimitException('Attribute value exceeds maximum limit: ' . $max); | ||
| } | ||
| @@ -5231,7 +5254,7 @@ public function decreaseDocumentAttribute( | ||
| int|float|null $min = null | ||
| ): Document { | ||
| if ($value <= 0) { // Can be a float | ||
| throw new DatabaseException('Value must be numeric and greater than 0'); | ||
| throw new \InvalidArgumentException('Value must be numeric and greater than 0'); | ||
| } | ||
| $collection = $this->silent(fn () => $this->getCollection($collection)); | ||
| @@ -5277,7 +5300,7 @@ public function decreaseDocumentAttribute( | ||
| } | ||
| } | ||
| if ($min && ($document->getAttribute($attribute) - $value < $min)) { | ||
| if (!\is_null($min) && ($document->getAttribute($attribute) - $value < $min)) { | ||
| throw new LimitException('Attribute value exceeds minimum limit: ' . $min); | ||
| } | ||
| @@ -6568,6 +6591,10 @@ protected function decodeAttribute(string $filter, mixed $value, Document $docum | ||
| return $value; | ||
| } | ||
| if (!\is_null($this->disabledFilters) && isset($this->disabledFilters[$filter])) { | ||
| return $value; | ||
| } | ||
| if (!array_key_exists($filter, self::$filters) && !array_key_exists($filter, $this->instanceFilters)) { | ||
| throw new NotFoundException("Filter \"{$filter}\" not found for attribute \"{$attribute}\""); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.