Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -10,30 +10,38 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Content\Api\GraphQL\ItemMutator;
|
||||
use IPS\Content\Item;
|
||||
use IPS\forums\api\GraphQL\Types\TopicType;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\Member;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create topic mutation for GraphQL API
|
||||
*/
|
||||
class _CreateTopic extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
class CreateTopic extends ItemMutator
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\forums\Topic';
|
||||
protected string $class = 'IPS\forums\Topic';
|
||||
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Create a new topic";
|
||||
public static string $description = "Create a new topic";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -52,51 +60,52 @@ class _CreateTopic extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return TopicType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : TopicType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::topic();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves this mutation
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Topic
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return Topic
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : Item
|
||||
{
|
||||
/* Get forum */
|
||||
try
|
||||
{
|
||||
$forum = \IPS\forums\Forum::loadAndCheckPerms( $args['forumID'] );
|
||||
$forum = Forum::loadAndCheckPerms( $args['forumID'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_FORUM', '1F294/2_graphl', 400 );
|
||||
throw new SafeException( 'NO_FORUM', '1F294/2_graphl', 400 );
|
||||
}
|
||||
|
||||
/* Check permission */
|
||||
if ( !$forum->can( 'add', \IPS\Member::loggedIn() ) )
|
||||
if ( !$forum->can( 'add', Member::loggedIn() ) )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', '2F294/9_graphl', 403 );
|
||||
throw new SafeException( 'NO_PERMISSION', '2F294/9_graphl', 403 );
|
||||
}
|
||||
|
||||
/* Check we have a title and a post */
|
||||
if ( !$args['title'] )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_TITLE', '1F294/5_graphl', 400 );
|
||||
throw new SafeException( 'NO_TITLE', '1F294/5_graphl', 400 );
|
||||
}
|
||||
if ( !$args['content'] )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', '1F294/4_graphl', 400 );
|
||||
throw new SafeException( 'NO_POST', '1F294/4_graphl', 400 );
|
||||
}
|
||||
|
||||
|
||||
$item = $this->_create( $args, $forum, $args['postKey'] ?? NULL );
|
||||
|
||||
return $item;
|
||||
return $this->_create( $args, $forum, $args['postKey'] ?? NULL );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user