Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,22 @@
"flarum/json-api-server": "^0.1.0",
"franzl/whoops-middleware": "2.0",
"guzzlehttp/guzzle": "*",
"illuminate/bus": "^11.0",
"illuminate/cache": "^11.0",
"illuminate/config": "^11.0",
"illuminate/console": "^11.0",
"illuminate/container": "^11.0",
"illuminate/contracts": "^11.0",
"illuminate/database": "^11.0",
"illuminate/events": "^11.0",
"illuminate/filesystem": "^11.0",
"illuminate/hashing": "^11.0",
"illuminate/mail": "^11.0",
"illuminate/queue": "^11.0",
"illuminate/session": "^11.0",
"illuminate/support": "^11.0",
"illuminate/validation": "^11.0",
"illuminate/view": "^11.0",
"illuminate/bus": "^12.0",
"illuminate/cache": "^12.0",
"illuminate/config": "^12.0",
"illuminate/console": "^12.0",
"illuminate/container": "^12.0",
"illuminate/contracts": "^12.0",
"illuminate/database": "^12.0",
"illuminate/events": "^12.0",
"illuminate/filesystem": "^12.0",
"illuminate/hashing": "^12.0",
"illuminate/mail": "^12.0",
"illuminate/queue": "^12.0",
"illuminate/session": "^12.0",
"illuminate/support": "^12.0",
"illuminate/validation": "^12.0",
"illuminate/view": "^12.0",
"intervention/image": "^3.2",
"jenssegers/agent": "^2.6",
"laminas/laminas-diactoros": "^3.0",
Expand Down Expand Up @@ -176,12 +176,12 @@
"plesk/ratchetphp": "v1.0.4"
},
"require-dev": {
"flarum/testing-tests": "*@dev",
"larastan/larastan": "^3.8",
"mockery/mockery": "^1.5",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^11.0",
"phpstan/phpstan": "^1.10.0",
"larastan/larastan": "2.9.14",
"symfony/var-dumper": "^7.0",
"flarum/testing-tests": "*@dev"
"symfony/var-dumper": "^7.0"
},
"config": {
"sort-packages": true
Expand Down
2 changes: 1 addition & 1 deletion extensions/flags/src/Api/Resource/FlagResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function query(Context $context): object
{
if ($context->listing(self::class)) {
$query = Flag::query()->whenPgSql(
fn (Builder $query) => $query->distinct('post_id')->orderBy('post_id'),
fn (Builder $query) => $query->distinct('post_id')->orderBy('post_id')->orderBy('created_at', 'desc'),
else: fn (Builder $query) => $query->groupBy('post_id')
);

Expand Down
2 changes: 1 addition & 1 deletion extensions/gdpr/src/Http/Controller/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
200,
[
'Content-Type' => 'application/zip',
'Content-Length' => $this->storageManager->getStoredExportSize($export),
'Content-Length' => (string) $this->storageManager->getStoredExportSize($export),
'Content-Disposition' => 'attachment; filename="data-export-'.$export->user->username.'-'.$export->created_at->toIso8601String().'.zip"',
]
);
Expand Down
6 changes: 6 additions & 0 deletions extensions/gdpr/src/Models/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,17 @@ public function user(): BelongsTo
return $this->belongsTo(User::class);
}

/**
* @return BelongsTo<User, $this>
*/
public function actor(): BelongsTo
{
return $this->belongsTo(User::class);
}

/**
* @return \Illuminate\Database\Eloquent\Builder<self>
*/
public static function destroyable(): \Illuminate\Database\Eloquent\Builder
{
return self::query()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function unparsePostMentionTags(string $xml): string
}

return preg_replace(
'/<'.preg_quote($tagName).'\b[^>]*(?=\bdisplayname="(.*)")[^>]*(?=\bid="([0-9]+)")[^>]*>@[^<]+<\/'.preg_quote($tagName).'>/U',
'/<'.preg_quote($tagName, '/').'\b[^>]*(?=\bdisplayname="(.*)")[^>]*(?=\bid="([0-9]+)")[^>]*>@[^<]+<\/'.preg_quote($tagName, '/').'>/U',
'@"$1"#p$2',
$xml
);
Expand Down
2 changes: 1 addition & 1 deletion extensions/mentions/src/Formatter/UnparseTagMentions.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function unparseTagMentionTags(string $xml): string
}

return preg_replace(
'/<'.preg_quote($tagName).'\b[^>]*(?=\bid="([0-9]+)")[^>]*(?=\bslug="(.*)")[^>]*>@[^<]+<\/'.preg_quote($tagName).'>/U',
'/<'.preg_quote($tagName, '/').'\b[^>]*(?=\bid="([0-9]+)")[^>]*(?=\bslug="(.*)")[^>]*>@[^<]+<\/'.preg_quote($tagName, '/').'>/U',
'#$2',
$xml
);
Expand Down
4 changes: 2 additions & 2 deletions extensions/mentions/src/Formatter/UnparseUserMentions.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function updateUserMentionTags(mixed $context, string $xml): string
default => User::query()->find($attributes['id']),
};

$attributes['displayname'] = $user?->display_name ?? $this->translator->trans('core.lib.username.deleted_text');
$attributes['displayname'] = $user->display_name ?? $this->translator->trans('core.lib.username.deleted_text');

if (str_contains($attributes['displayname'], '"#')) {
$attributes['displayname'] = preg_replace('/"#[a-z]{0,3}[0-9]+/', '_', $attributes['displayname']);
Expand All @@ -64,7 +64,7 @@ protected function unparseUserMentionTags(string $xml): string
}

return preg_replace(
'/<'.preg_quote($tagName).'\b[^>]*(?=\bdisplayname="(.*)")[^>]*(?=\bid="([0-9]+)")[^>]*>@[^<]+<\/'.preg_quote($tagName).'>/U',
'/<'.preg_quote($tagName, '/').'\b[^>]*(?=\bdisplayname="(.*)")[^>]*(?=\bid="([0-9]+)")[^>]*>@[^<]+<\/'.preg_quote($tagName, '/').'>/U',
'@"$1"#$2',
$xml
);
Expand Down
3 changes: 3 additions & 0 deletions extensions/messages/src/Dialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class Dialog extends AbstractModel

protected static ?User $stateUser = null;

/**
* @return HasMany<DialogMessage, $this>
*/
public function messages(): HasMany
{
return $this->hasMany(DialogMessage::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ public function __construct(

public function handle(DialogMessage\Event\Created|DialogMessage\Event\Updated $event): void
{
if (! $event->message instanceof DialogMessage) {
return;
}

$content = $event->message->parsed_content;

$this->syncUserMentions(
Expand Down
17 changes: 12 additions & 5 deletions extensions/package-manager/extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,19 @@
&& is_writable($paths->base.'/composer.json')
&& is_writable($paths->base.'/composer.lock');

$document->payload['flarum-extension-manager.using_sync_queue'] = resolve(Queue::class) instanceof SyncQueue;
// Extensions can override the default queue driver
$queue = resolve('flarum.queue.connection');
$document->payload['flarum-extension-manager.using_sync_queue'] = $queue instanceof SyncQueue;

$document->payload['flarum-extension-manager.missing_functions'] = array_values(array_filter(
['proc_open', 'escapeshellarg'],
fn (string $function): bool => ! function_exists($function)
));
// Check if required functions are available (may be disabled in restricted environments)
$requiredFunctions = ['proc_open', 'escapeshellarg'];
$missingFunctions = [];
foreach ($requiredFunctions as $function) {
if (! function_exists($function)) {
$missingFunctions[] = $function;
}
}
$document->payload['flarum-extension-manager.missing_functions'] = $missingFunctions;
}),

new Extend\Locales(__DIR__.'/locale'),
Expand Down
5 changes: 3 additions & 2 deletions extensions/sticky/src/PinStickiedDiscussionsToTop.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __invoke(DatabaseSearchState $state, SearchCriteria $criteria):
// reorder the unread ones up to the top.
$sticky = clone $query;
$sticky->where('is_sticky', true);
unset($sticky->orders);
$sticky->orders = null;

$epochTime = (new DateTime('@0'))->format('Y-m-d H:i:s');

Expand Down Expand Up @@ -84,7 +84,8 @@ public function __invoke(DatabaseSearchState $state, SearchCriteria $criteria):
$query->unionOffset = $query->offset;

$query->limit = $sticky->limit = $query->offset + $query->limit;
unset($query->offset, $sticky->offset);
$query->offset = null;
$sticky->offset = null;
}
}

Expand Down
2 changes: 1 addition & 1 deletion extensions/tags/src/Access/TagPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TagPolicy extends AbstractPolicy
{
public function can(User $actor, string $ability, Tag $tag): string|bool|null
{
if ($tag->parent_id !== null && ! $actor->can($ability, $tag->parent)) {
if ($tag->parent_id && ! $actor->can($ability, $tag->parent)) {
return $this->deny();
}

Expand Down
7 changes: 5 additions & 2 deletions extensions/tags/src/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function parent(): BelongsTo
}

/**
* @return HasMany<self>
* @return HasMany<self, $this>
*/
public function children(): HasMany
{
Expand All @@ -128,7 +128,7 @@ public function lastPostedUser(): BelongsTo
}

/**
* @return BelongsToMany<Discussion>
* @return BelongsToMany<Discussion, $this>
*/
public function discussions(): BelongsToMany
{
Expand All @@ -155,6 +155,9 @@ public function setLastPostedDiscussion(?Discussion $discussion = null): static
return $this;
}

/**
* @return HasOne<TagState, $this>
*/
public function state(): HasOne
{
return $this->hasOne(TagState::class);
Expand Down
32 changes: 16 additions & 16 deletions framework/core/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@
"fakerphp/faker": "^1.9.1",
"franzl/whoops-middleware": "2.0",
"guzzlehttp/guzzle": "^7.7",
"illuminate/bus": "^11.0",
"illuminate/cache": "^11.0",
"illuminate/config": "^11.0",
"illuminate/console": "^11.0",
"illuminate/container": "^11.0",
"illuminate/contracts": "^11.0",
"illuminate/database": "^11.0",
"illuminate/events": "^11.0",
"illuminate/filesystem": "^11.0",
"illuminate/hashing": "^11.0",
"illuminate/mail": "^11.0",
"illuminate/queue": "^11.0",
"illuminate/session": "^11.0",
"illuminate/support": "^11.0",
"illuminate/validation": "^11.0",
"illuminate/view": "^11.0",
"illuminate/bus": "^12.0",
"illuminate/cache": "^12.0",
"illuminate/config": "^12.0",
"illuminate/console": "^12.0",
"illuminate/container": "^12.0",
"illuminate/contracts": "^12.0",
"illuminate/database": "^12.0",
"illuminate/events": "^12.0",
"illuminate/filesystem": "^12.0",
"illuminate/hashing": "^12.0",
"illuminate/mail": "^12.0",
"illuminate/queue": "^12.0",
"illuminate/session": "^12.0",
"illuminate/support": "^12.0",
"illuminate/validation": "^12.0",
"illuminate/view": "^12.0",
"intervention/image": "^3.2",
"jenssegers/agent": "^2.6.4",
"laminas/laminas-diactoros": "^3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Closure;
use Flarum\Api\Resource\AbstractDatabaseResource;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Tobyz\JsonApiServer\Context;

Expand Down Expand Up @@ -95,7 +94,6 @@ protected function loadRelations(Collection $models, Context $context, array $in
}

$included = $this->stringInclude($included);
$models = $models->filter(fn ($model) => $model instanceof Model);

$relations = $this->compileSimpleEagerLoads($context, $included);
$addedRelationWhere = $this->compileWhereEagerLoads($context);
Expand Down
1 change: 0 additions & 1 deletion framework/core/src/Api/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ private function resolveDeferred(): void
while ($this->deferred->count()) {
$deferred = $this->deferred;

/** @var Closure $resolve */
while (($resolve = $deferred->shift()) && is_callable($resolve)) {
$resolve();
}
Expand Down
18 changes: 14 additions & 4 deletions framework/core/src/Database/DatabaseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ protected function registerBuilderMacros(): void
foreach ([QueryBuilder::class, EloquentBuilder::class] as $builder) {
foreach ($drivers as $driver => $macro) {
$builder::macro('when'.$macro, function ($callback, $else) use ($driver) {
/** @var QueryBuilder|EloquentBuilder $this */
if ($this->getConnection()->getDriverName() === $driver) {
// Laravel macros bind $this to the builder at runtime via Closure::call()
// For Eloquent builders, we need to access the connection through the query property
$connection = method_exists($this, 'getConnection')
? $this->getConnection()
: (property_exists($this, 'query') ? $this->query->getConnection() : null);

if ($connection && $connection->getDriverName() === $driver) {
$callback($this);
} else {
$else($this);
Expand All @@ -104,8 +109,13 @@ protected function registerBuilderMacros(): void
});

$builder::macro('unless'.$macro, function ($callback, $else) use ($driver) {
/** @var QueryBuilder|EloquentBuilder $this */
if ($this->getConnection()->getDriverName() !== $driver) {
// Laravel macros bind $this to the builder at runtime via Closure::call()
// For Eloquent builders, we need to access the connection through the query property
$connection = method_exists($this, 'getConnection')
? $this->getConnection()
: (property_exists($this, 'query') ? $this->query->getConnection() : null);

if ($connection && $connection->getDriverName() !== $driver) {
$callback($this);
} else {
$else($this);
Expand Down
6 changes: 3 additions & 3 deletions framework/core/src/Discussion/Discussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function getModifiedPosts(): array
}

/**
* @return HasMany<Post>
* @return HasMany<Post, $this>
*/
public function posts(): HasMany
{
Expand All @@ -270,7 +270,7 @@ public function posts(): HasMany
/**
* The discussion's publicly-visible comments.
*
* @return HasMany<Post>
* @return HasMany<Post, $this>
*/
public function comments(): HasMany
{
Expand Down Expand Up @@ -320,7 +320,7 @@ public function mostRelevantPost(): BelongsTo
}

/**
* @return BelongsToMany<User>
* @return BelongsToMany<User, $this>
*/
public function readers(): BelongsToMany
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function constrain(Builder $query, string|array $rawUsernames, bool $n
$ids = $this->users->getIdsForUsernames($usernames);

// To be able to also use IDs.
$actualIds = array_diff($usernames, array_keys($ids));
$actualIds = array_diff(array_map('strval', $usernames), array_map('strval', array_keys($ids)));

if (! empty($actualIds)) {
$ids = array_merge($ids, $actualIds);
Expand Down
9 changes: 4 additions & 5 deletions framework/core/src/Extension/ExtensionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,18 @@ public function getExtensions(): Collection
$extensions->put($extension->getId(), $extension);
}

/** @var Extension $extension */
foreach ($extensions as $extension) {
$extension->calculateDependencies($installedSet);
}

$needsReset = false;
/** @var Extension[] $enabledExtensions */
$enabledExtensions = [];
foreach ($this->getEnabled() as $enabledKey) {
$extension = $extensions->get($enabledKey);
if (is_null($extension)) {
if ($extensions->has($enabledKey)) {
$enabledExtensions[] = $extensions->get($enabledKey);
} else {
$needsReset = true;
} else { // @phpstan-ignore-line
$enabledExtensions[] = $extension;
}
}

Expand Down
2 changes: 1 addition & 1 deletion framework/core/src/Foundation/ErrorHandling/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private function handleKnownTypes(Throwable $error): ?HandledError
private function handleCustomTypes(Throwable $error): ?HandledError
{
foreach ($this->handlerMap as $class => $handler) {
if ($error instanceof $class) {
if (is_a($error, $class)) {
$handler = new $handler;

return $handler->handle($error);
Expand Down
Loading
Loading