mirror of
https://github.com/flarum/framework.git
synced 2025-02-12 08:29:47 +08:00
fix: beta.1 early bugs
This commit is contained in:
parent
382991648c
commit
a81d13e26c
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user