fix: beta.1 early bugs
Some checks are pending
Backend Tests / run (push) Waiting to run
Frontend Workflow / run (push) Waiting to run
Static Code Analysis / run (push) Waiting to run

This commit is contained in:
Sami Mazouz 2024-12-12 21:27:57 +01:00
parent 382991648c
commit a81d13e26c
No known key found for this signature in database
3 changed files with 36 additions and 4 deletions

View File

@ -40,7 +40,7 @@ trait HasHooks
return $callable;
}
protected function callBeforeHook(Context $context): void
public function callBeforeHook(Context $context): void
{
foreach ($this->before as $before) {
$before = $this->resolveCallable($before, $context);
@ -48,7 +48,7 @@ trait HasHooks
}
}
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);

View File

@ -54,4 +54,36 @@ class Collection extends BaseCollection
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);
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);
}
}

View File

@ -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
@ -35,7 +35,7 @@ class Console implements ExtenderInterface
/**
* 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: