mirror of
https://github.com/flarum/core.git
synced 2025-08-08 09:26:34 +02:00
chore(phpstan): enable phpstan in bundled extensions (#3667)
* feat(phpstan): pick up extended model relations typings * feat(phpstan): pick up extended model date attributes * feat(core): introduce `castAttribute` extender Stops using `dates` as it's deprecated in laravel 8 * feat(phpstan): pick up extended model attributes through casts * fix: extenders not resolved when declared namespace * fix(phpstan): new model attributes are always nullable * chore(phpstan): add helpful cache clearing command * Apply fixes from StyleCI * chore: improve extend files provider logic * chore: rename `castAttribute` to just `cast` * chore: update phpstan package to detect `cast` method * chore: enable phpstan in bundled extensions * chore: rebasing conflicts * chore: rebasing conflicts * chore: typings for latest 1.7 changes Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
use Flarum\Api\Controller\ListDiscussionsController;
|
||||
use Flarum\Api\Serializer\DiscussionSerializer;
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Discussion\Event\Saving;
|
||||
use Flarum\Discussion\Filter\DiscussionFilterer;
|
||||
use Flarum\Discussion\Search\DiscussionSearcher;
|
||||
@@ -26,6 +27,9 @@ return [
|
||||
->js(__DIR__.'/js/dist/forum.js')
|
||||
->css(__DIR__.'/less/forum.less'),
|
||||
|
||||
(new Extend\Model(Discussion::class))
|
||||
->cast('is_sticky', 'bool'),
|
||||
|
||||
(new Extend\Post())
|
||||
->type(DiscussionStickiedPost::class),
|
||||
|
||||
|
@@ -43,12 +43,12 @@ class PinStickiedDiscussionsToTop
|
||||
// reorder the unread ones up to the top.
|
||||
$sticky = clone $query;
|
||||
$sticky->where('is_sticky', true);
|
||||
$sticky->orders = null;
|
||||
unset($sticky->orders);
|
||||
|
||||
$query->union($sticky);
|
||||
|
||||
$read = $query->newQuery()
|
||||
->selectRaw(1)
|
||||
->selectRaw('1')
|
||||
->from('discussion_user as sticky')
|
||||
->whereColumn('sticky.discussion_id', 'id')
|
||||
->where('sticky.user_id', '=', $filterState->getActor()->id)
|
||||
@@ -58,14 +58,14 @@ class PinStickiedDiscussionsToTop
|
||||
// argument in orderByRaw) for now due to a bug in Laravel which
|
||||
// would add the bindings in the wrong order.
|
||||
$query->orderByRaw('is_sticky and not exists ('.$read->toSql().') and last_posted_at > ? desc')
|
||||
->addBinding(array_merge($read->getBindings(), [$filterState->getActor()->read_time ?: 0]), 'union');
|
||||
->addBinding(array_merge($read->getBindings(), [$filterState->getActor()->marked_all_as_read_at ?: 0]), 'union');
|
||||
|
||||
$query->unionOrders = array_merge($query->unionOrders, $query->orders);
|
||||
$query->unionLimit = $query->limit;
|
||||
$query->unionOffset = $query->offset;
|
||||
|
||||
$query->limit = $sticky->limit = $query->offset + $query->limit;
|
||||
$query->offset = $sticky->offset = null;
|
||||
unset($query->offset, $sticky->offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Flarum\Sticky\Post;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Post\AbstractEventPost;
|
||||
use Flarum\Post\MergeableInterface;
|
||||
use Flarum\Post\Post;
|
||||
@@ -59,7 +60,7 @@ class DiscussionStickiedPost extends AbstractEventPost implements MergeableInter
|
||||
$post = new static;
|
||||
|
||||
$post->content = static::buildContent($isSticky);
|
||||
$post->created_at = time();
|
||||
$post->created_at = Carbon::now();
|
||||
$post->discussion_id = $discussionId;
|
||||
$post->user_id = $userId;
|
||||
|
||||
|
Reference in New Issue
Block a user