mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 06:53:47 +08:00
Replace depreciated functions with classfull verions
This commit is contained in:
parent
2237e597d0
commit
bd46db8741
|
@ -13,6 +13,7 @@ use Flarum\Api\Controller\AbstractCreateController;
|
||||||
use Flarum\Tags\Api\Serializer\TagSerializer;
|
use Flarum\Tags\Api\Serializer\TagSerializer;
|
||||||
use Flarum\Tags\Command\CreateTag;
|
use Flarum\Tags\Command\CreateTag;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ class CreateTagController extends AbstractCreateController
|
||||||
protected function data(ServerRequestInterface $request, Document $document)
|
protected function data(ServerRequestInterface $request, Document $document)
|
||||||
{
|
{
|
||||||
return $this->bus->dispatch(
|
return $this->bus->dispatch(
|
||||||
new CreateTag($request->getAttribute('actor'), array_get($request->getParsedBody(), 'data', []))
|
new CreateTag($request->getAttribute('actor'), Arr::get($request->getParsedBody(), 'data', []))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ namespace Flarum\Tags\Api\Controller;
|
||||||
use Flarum\Api\Controller\AbstractDeleteController;
|
use Flarum\Api\Controller\AbstractDeleteController;
|
||||||
use Flarum\Tags\Command\DeleteTag;
|
use Flarum\Tags\Command\DeleteTag;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class DeleteTagController extends AbstractDeleteController
|
class DeleteTagController extends AbstractDeleteController
|
||||||
|
@ -35,7 +36,7 @@ class DeleteTagController extends AbstractDeleteController
|
||||||
protected function delete(ServerRequestInterface $request)
|
protected function delete(ServerRequestInterface $request)
|
||||||
{
|
{
|
||||||
$this->bus->dispatch(
|
$this->bus->dispatch(
|
||||||
new DeleteTag(array_get($request->getQueryParams(), 'id'), $request->getAttribute('actor'))
|
new DeleteTag(Arr::get($request->getQueryParams(), 'id'), $request->getAttribute('actor'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
namespace Flarum\Tags\Api\Controller;
|
namespace Flarum\Tags\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Tags\Tag;
|
use Flarum\Tags\Tag;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Laminas\Diactoros\Response\EmptyResponse;
|
use Laminas\Diactoros\Response\EmptyResponse;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
@ -24,7 +25,7 @@ class OrderTagsController implements RequestHandlerInterface
|
||||||
{
|
{
|
||||||
$request->getAttribute('actor')->assertAdmin();
|
$request->getAttribute('actor')->assertAdmin();
|
||||||
|
|
||||||
$order = array_get($request->getParsedBody(), 'order');
|
$order = Arr::get($request->getParsedBody(), 'order');
|
||||||
|
|
||||||
if ($order === null) {
|
if ($order === null) {
|
||||||
return new EmptyResponse(422);
|
return new EmptyResponse(422);
|
||||||
|
@ -36,7 +37,7 @@ class OrderTagsController implements RequestHandlerInterface
|
||||||
]);
|
]);
|
||||||
|
|
||||||
foreach ($order as $i => $parent) {
|
foreach ($order as $i => $parent) {
|
||||||
$parentId = array_get($parent, 'id');
|
$parentId = Arr::get($parent, 'id');
|
||||||
|
|
||||||
Tag::where('id', $parentId)->update(['position' => $i]);
|
Tag::where('id', $parentId)->update(['position' => $i]);
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ use Flarum\Api\Controller\AbstractShowController;
|
||||||
use Flarum\Tags\Api\Serializer\TagSerializer;
|
use Flarum\Tags\Api\Serializer\TagSerializer;
|
||||||
use Flarum\Tags\Command\EditTag;
|
use Flarum\Tags\Command\EditTag;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
|
@ -41,9 +42,9 @@ class UpdateTagController extends AbstractShowController
|
||||||
*/
|
*/
|
||||||
protected function data(ServerRequestInterface $request, Document $document)
|
protected function data(ServerRequestInterface $request, Document $document)
|
||||||
{
|
{
|
||||||
$id = array_get($request->getQueryParams(), 'id');
|
$id = Arr::get($request->getQueryParams(), 'id');
|
||||||
$actor = $request->getAttribute('actor');
|
$actor = $request->getAttribute('actor');
|
||||||
$data = array_get($request->getParsedBody(), 'data', []);
|
$data = Arr::get($request->getParsedBody(), 'data', []);
|
||||||
|
|
||||||
return $this->bus->dispatch(
|
return $this->bus->dispatch(
|
||||||
new EditTag($id, $actor, $data)
|
new EditTag($id, $actor, $data)
|
||||||
|
|
|
@ -12,6 +12,7 @@ namespace Flarum\Tags\Command;
|
||||||
use Flarum\Tags\Event\Creating;
|
use Flarum\Tags\Event\Creating;
|
||||||
use Flarum\Tags\Tag;
|
use Flarum\Tags\Tag;
|
||||||
use Flarum\Tags\TagValidator;
|
use Flarum\Tags\TagValidator;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
class CreateTagHandler
|
class CreateTagHandler
|
||||||
{
|
{
|
||||||
|
@ -40,15 +41,15 @@ class CreateTagHandler
|
||||||
$actor->assertCan('createTag');
|
$actor->assertCan('createTag');
|
||||||
|
|
||||||
$tag = Tag::build(
|
$tag = Tag::build(
|
||||||
array_get($data, 'attributes.name'),
|
Arr::get($data, 'attributes.name'),
|
||||||
array_get($data, 'attributes.slug'),
|
Arr::get($data, 'attributes.slug'),
|
||||||
array_get($data, 'attributes.description'),
|
Arr::get($data, 'attributes.description'),
|
||||||
array_get($data, 'attributes.color'),
|
Arr::get($data, 'attributes.color'),
|
||||||
array_get($data, 'attributes.icon'),
|
Arr::get($data, 'attributes.icon'),
|
||||||
array_get($data, 'attributes.isHidden')
|
Arr::get($data, 'attributes.isHidden')
|
||||||
);
|
);
|
||||||
|
|
||||||
$parentId = array_get($data, 'relationships.parent.data.id');
|
$parentId = Arr::get($data, 'relationships.parent.data.id');
|
||||||
|
|
||||||
if ($parentId !== null) {
|
if ($parentId !== null) {
|
||||||
$rootTags = Tag::whereNull('parent_id')->whereNotNull('position');
|
$rootTags = Tag::whereNull('parent_id')->whereNotNull('position');
|
||||||
|
|
|
@ -12,6 +12,7 @@ namespace Flarum\Tags\Command;
|
||||||
use Flarum\Tags\Event\TagWillBeSaved;
|
use Flarum\Tags\Event\TagWillBeSaved;
|
||||||
use Flarum\Tags\TagRepository;
|
use Flarum\Tags\TagRepository;
|
||||||
use Flarum\Tags\TagValidator;
|
use Flarum\Tags\TagValidator;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
class EditTagHandler
|
class EditTagHandler
|
||||||
{
|
{
|
||||||
|
@ -49,7 +50,7 @@ class EditTagHandler
|
||||||
|
|
||||||
$actor->assertCan('edit', $tag);
|
$actor->assertCan('edit', $tag);
|
||||||
|
|
||||||
$attributes = array_get($data, 'attributes', []);
|
$attributes = Arr::get($data, 'attributes', []);
|
||||||
|
|
||||||
if (isset($attributes['name'])) {
|
if (isset($attributes['name'])) {
|
||||||
$tag->name = $attributes['name'];
|
$tag->name = $attributes['name'];
|
||||||
|
|
|
@ -13,6 +13,7 @@ use Flarum\Event\ConfigurePostTypes;
|
||||||
use Flarum\Tags\Event\DiscussionWasTagged;
|
use Flarum\Tags\Event\DiscussionWasTagged;
|
||||||
use Flarum\Tags\Post\DiscussionTaggedPost;
|
use Flarum\Tags\Post\DiscussionTaggedPost;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
class CreatePostWhenTagsAreChanged
|
class CreatePostWhenTagsAreChanged
|
||||||
{
|
{
|
||||||
|
@ -41,7 +42,7 @@ class CreatePostWhenTagsAreChanged
|
||||||
$post = DiscussionTaggedPost::reply(
|
$post = DiscussionTaggedPost::reply(
|
||||||
$event->discussion->id,
|
$event->discussion->id,
|
||||||
$event->actor->id,
|
$event->actor->id,
|
||||||
array_pluck($event->oldTags, 'id'),
|
Arr::pluck($event->oldTags, 'id'),
|
||||||
$event->discussion->tags()->pluck('id')->all()
|
$event->discussion->tags()->pluck('id')->all()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace Flarum\Tags\Listener;
|
||||||
|
|
||||||
use Flarum\Event\ConfigurePostsQuery;
|
use Flarum\Event\ConfigurePostsQuery;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
class FilterPostsQueryByTag
|
class FilterPostsQueryByTag
|
||||||
{
|
{
|
||||||
|
@ -27,7 +28,7 @@ class FilterPostsQueryByTag
|
||||||
*/
|
*/
|
||||||
public function filterQuery(ConfigurePostsQuery $event)
|
public function filterQuery(ConfigurePostsQuery $event)
|
||||||
{
|
{
|
||||||
if ($tagId = array_get($event->filter, 'tag')) {
|
if ($tagId = Arr::get($event->filter, 'tag')) {
|
||||||
$event->query
|
$event->query
|
||||||
->join('discussion_tag', 'discussion_tag.discussion_id', '=', 'posts.discussion_id')
|
->join('discussion_tag', 'discussion_tag.discussion_id', '=', 'posts.discussion_id')
|
||||||
->where('discussion_tag.tag_id', $tagId);
|
->where('discussion_tag.tag_id', $tagId);
|
||||||
|
|
|
@ -21,6 +21,7 @@ use Flarum\Post\Event\Restored as PostRestored;
|
||||||
use Flarum\Tags\Event\DiscussionWasTagged;
|
use Flarum\Tags\Event\DiscussionWasTagged;
|
||||||
use Flarum\Tags\Tag;
|
use Flarum\Tags\Tag;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
class UpdateTagMetadata
|
class UpdateTagMetadata
|
||||||
{
|
{
|
||||||
|
@ -54,7 +55,7 @@ class UpdateTagMetadata
|
||||||
*/
|
*/
|
||||||
public function whenDiscussionWasTagged(DiscussionWasTagged $event)
|
public function whenDiscussionWasTagged(DiscussionWasTagged $event)
|
||||||
{
|
{
|
||||||
$oldTags = Tag::whereIn('id', array_pluck($event->oldTags, 'id'))->get();
|
$oldTags = Tag::whereIn('id', Arr::pluck($event->oldTags, 'id'))->get();
|
||||||
|
|
||||||
$this->updateTags($event->discussion, -1, $oldTags);
|
$this->updateTags($event->discussion, -1, $oldTags);
|
||||||
$this->updateTags($event->discussion, 1);
|
$this->updateTags($event->discussion, 1);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user