mirror of
https://github.com/flarum/core.git
synced 2025-10-09 05:56:25 +02:00
- Use contextual namespaces within Flarum\Core - Clean up and docblock everything - Refactor Activity/Notification blueprint stuff - Refactor Formatter stuff - Refactor Search stuff - Upgrade to JSON-API 1.0 - Removed “addedPosts” and “removedPosts” relationships from discussion API. This was used for adding/removing event posts after renaming a discussion etc. Instead we should make an additional request to get all new posts Todo: - Fix Extenders and extensions - Get rid of repository interfaces - Fix other bugs I’ve inevitably introduced
91 lines
2.1 KiB
PHP
91 lines
2.1 KiB
PHP
<?php namespace Flarum\Api\Actions\Discussions;
|
|
|
|
use Flarum\Core\Discussions\Commands\EditDiscussion;
|
|
use Flarum\Core\Discussions\Commands\ReadDiscussion;
|
|
use Flarum\Api\Actions\SerializeResourceAction;
|
|
use Flarum\Api\JsonApiRequest;
|
|
use Illuminate\Contracts\Bus\Dispatcher;
|
|
use Tobscure\JsonApi\Document;
|
|
|
|
class UpdateAction extends SerializeResourceAction
|
|
{
|
|
/**
|
|
* @var Dispatcher
|
|
*/
|
|
protected $bus;
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static $serializer = 'Flarum\Api\Serializers\DiscussionSerializer';
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static $include = [];
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static $link = [];
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static $limitMax = 50;
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static $limit = 20;
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static $sortFields = [];
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static $sort;
|
|
|
|
/**
|
|
* @param Dispatcher $bus
|
|
*/
|
|
public function __construct(Dispatcher $bus)
|
|
{
|
|
$this->bus = $bus;
|
|
}
|
|
|
|
/**
|
|
* Update a discussion according to input from the API request, and return
|
|
* it ready to be serialized and assigned to the JsonApi response.
|
|
*
|
|
* @param JsonApiRequest $request
|
|
* @param Document $document
|
|
* @return \Flarum\Core\Discussions\Discussion
|
|
*/
|
|
protected function data(JsonApiRequest $request, Document $document)
|
|
{
|
|
$actor = $request->actor;
|
|
$discussionId = $request->get('id');
|
|
$data = $request->get('data');
|
|
|
|
$discussion = $this->bus->dispatch(
|
|
new EditDiscussion($discussionId, $actor, $data)
|
|
);
|
|
|
|
// TODO: Refactor the ReadDiscussion (state) command into EditDiscussion?
|
|
// That's what extensions will do anyway.
|
|
if ($readNumber = array_get($data, 'attributes.readNumber')) {
|
|
$state = $this->bus->dispatch(
|
|
new ReadDiscussion($discussionId, $actor, $readNumber)
|
|
);
|
|
|
|
$discussion = $state->discussion;
|
|
}
|
|
|
|
return $discussion;
|
|
}
|
|
}
|