Skip to content

Commit

Permalink
fix: beta.1 early bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Dec 12, 2024
1 parent 3829916 commit a81d13e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
4 changes: 2 additions & 2 deletions framework/core/src/Api/Endpoint/Concerns/HasHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ protected function resolveCallable(callable|string $callable, Context $context):
return $callable;
}

protected function callBeforeHook(Context $context): void
public function callBeforeHook(Context $context): void
{
foreach ($this->before as $before) {
$before = $this->resolveCallable($before, $context);
$before($context);
}
}

protected function callAfterHook(Context $context, mixed $data): mixed
public function callAfterHook(Context $context, mixed $data): mixed
{
foreach ($this->after as $after) {
$after = $this->resolveCallable($after, $context);
Expand Down
32 changes: 32 additions & 0 deletions framework/core/src/Database/Eloquent/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,36 @@ public function loadAggregate($relations, $column, $function = null): self
return parent::loadAggregate($relations, $column, $function);
});
}

/**
* The original Laravel logic uses ->whereNotNull() which is an abstraction that unnecessarily causes
* attribute mutators to run, so if a mutator relies on an eager loaded relationship, the mutator
* will be executed before the call to ->loadMissing() is over.
*
* We replace it with a simple ->where(fn (mixed $relation) => $relation !== null) to avoid this issue.
*/
protected function loadMissingRelation(BaseCollection $models, array $path): void
{
$relation = array_shift($path);

$name = explode(':', key($relation))[0];

if (is_string(reset($relation))) {
$relation = reset($relation);
}

$models->filter(fn ($model) => ! is_null($model) && ! $model->relationLoaded($name))->load($relation);

Check failure on line 75 in framework/core/src/Database/Eloquent/Collection.php

View workflow job for this annotation

GitHub Actions / run / PHPStan PHP 8.2

Call to function is_null() with TModel of Flarum\Database\AbstractModel will always evaluate to false.

Check failure on line 75 in framework/core/src/Database/Eloquent/Collection.php

View workflow job for this annotation

GitHub Actions / run / PHPStan PHP 8.3

Call to function is_null() with TModel of Flarum\Database\AbstractModel will always evaluate to false.

Check failure on line 75 in framework/core/src/Database/Eloquent/Collection.php

View workflow job for this annotation

GitHub Actions / run / PHPStan PHP 8.4

Call to function is_null() with TModel of Flarum\Database\AbstractModel will always evaluate to false.

if (empty($path)) {
return;
}

$models = $models->pluck($name)->where(fn (mixed $relation) => $relation !== null);

if ($models->first() instanceof \Illuminate\Support\Collection) {
$models = $models->collapse();
}

$this->loadMissingRelation(new static($models), $path);
}
}
4 changes: 2 additions & 2 deletions framework/core/src/Extend/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Console implements ExtenderInterface
/**
* Add a command to the console.
*
* @param class-string<AbstractCommand> $command: ::class attribute of command class, which must extend \Flarum\Console\AbstractCommand.
* @param class-string<AbstractCommand|\Illuminate\Console\Command> $command: ::class attribute of command class, which must extend \Flarum\Console\AbstractCommand.
* @return self
*/
public function command(string $command): self
Expand All @@ -35,7 +35,7 @@ public function command(string $command): self
/**
* Schedule a command to run on an interval.
*
* @param class-string<AbstractCommand> $command: ::class attribute of command class, which must extend Flarum\Console\AbstractCommand.
* @param class-string<AbstractCommand|\Illuminate\Console\Command> $command: ::class attribute of command class, which must extend Flarum\Console\AbstractCommand.
* @param (callable(\Illuminate\Console\Scheduling\Event $event): void)|class-string $callback
*
* The callback can be a closure or invokable class, and should accept:
Expand Down

0 comments on commit a81d13e

Please sign in to comment.