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 );
|
||||
}
|
||||
}
|
||||
@@ -10,25 +10,31 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\forums\api\GraphQL\Types\ForumType;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\Node\Api\GraphQL\NodeMutator;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function intval;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark forum read mutation for GraphQL API
|
||||
*/
|
||||
class _MarkForumRead extends \IPS\Node\Api\GraphQL\NodeMutator
|
||||
class MarkForumRead extends NodeMutator
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Mark a forum as read";
|
||||
public static string $description = "Mark a forum as read";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -42,8 +48,10 @@ class _MarkForumRead extends \IPS\Node\Api\GraphQL\NodeMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return ForumType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : ForumType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::forum();
|
||||
}
|
||||
@@ -51,20 +59,19 @@ class _MarkForumRead extends \IPS\Node\Api\GraphQL\NodeMutator
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Forum
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Forum
|
||||
{
|
||||
try
|
||||
{
|
||||
$forum = \IPS\forums\Forum::loadAndCheckPerms( \intval( $args['id'] ) );
|
||||
$forum = Forum::loadAndCheckPerms( intval( $args['id'] ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_NODE', 'GQL/0004/2', 403 );
|
||||
throw new SafeException( 'INVALID_NODE', 'GQL/0004/2', 403 );
|
||||
}
|
||||
|
||||
$this->_markRead( $forum );
|
||||
|
||||
@@ -10,25 +10,30 @@
|
||||
*/
|
||||
|
||||
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\forums\api\GraphQL\Types\TopicType;
|
||||
use IPS\forums\Topic;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark topic read mutation for GraphQL API
|
||||
*/
|
||||
class _MarkTopicRead extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
class MarkTopicRead extends ItemMutator
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Mark a topic as read";
|
||||
public static string $description = "Mark a topic as read";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -42,8 +47,10 @@ class _MarkTopicRead extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @reutrn TopicType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : TopicType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::topic();
|
||||
}
|
||||
@@ -51,25 +58,24 @@ class _MarkTopicRead extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Topic
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Topic
|
||||
{
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( $args['id'] );
|
||||
$topic = Topic::loadAndCheckPerms( $args['id'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_TOPIC', 'GQL/0005/1', 400 );
|
||||
throw new SafeException( 'NO_TOPIC', 'GQL/0005/1', 400 );
|
||||
}
|
||||
|
||||
if( !$topic->can('read') )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_ID', 'GQL/0005/2', 403 );
|
||||
throw new SafeException( 'INVALID_ID', 'GQL/0005/2', 403 );
|
||||
}
|
||||
|
||||
$this->_markRead( $topic );
|
||||
|
||||
@@ -10,25 +10,35 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Db;
|
||||
use IPS\forums\api\GraphQL\Types\TopicType;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\forums\Topic\Post;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Api\GraphQL\NodeMutator;
|
||||
use IPS\Request;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function intval;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark topic solved mutation for GraphQL API
|
||||
*/
|
||||
class _MarkTopicSolved extends \IPS\Node\Api\GraphQL\NodeMutator
|
||||
class MarkTopicSolved extends NodeMutator
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Mark a topic solved";
|
||||
public static string $description = "Mark a topic solved";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -47,8 +57,10 @@ class _MarkTopicSolved extends \IPS\Node\Api\GraphQL\NodeMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return TopicType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : TopicType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::topic();
|
||||
}
|
||||
@@ -56,34 +68,34 @@ class _MarkTopicSolved extends \IPS\Node\Api\GraphQL\NodeMutator
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @return \IPS\forums\Topic
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Topic
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Topic
|
||||
{
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( \intval( $args['id'] ) );
|
||||
$topic = Topic::loadAndCheckPerms( intval( $args['id'] ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_TOPIC', 'GQL', 403 );
|
||||
throw new SafeException( 'NO_TOPIC', 'GQL', 403 );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$post = \IPS\forums\Topic\Post::loadAndCheckPerms( \intval( $args['answer'] ) );
|
||||
$post = Post::loadAndCheckPerms( intval( $args['answer'] ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', 'GQL', 403 );
|
||||
throw new SafeException( 'NO_POST', 'GQL', 403 );
|
||||
}
|
||||
|
||||
/* This is "solved" mode */
|
||||
if ( !$topic->canSolve() )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', 'GQL', 403 );
|
||||
throw new SafeException( 'NO_PERMISSION', 'GQL', 403 );
|
||||
}
|
||||
|
||||
|
||||
@@ -96,12 +108,12 @@ class _MarkTopicSolved extends \IPS\Node\Api\GraphQL\NodeMutator
|
||||
$topic->toggleSolveComment( $post->pid, FALSE );
|
||||
}
|
||||
|
||||
\IPS\Db::i()->insert( 'core_moderator_logs', array(
|
||||
'member_id' => \IPS\Member::loggedIn()->member_id,
|
||||
'member_name' => \IPS\Member::loggedIn()->name,
|
||||
Db::i()->insert( 'core_moderator_logs', array(
|
||||
'member_id' => Member::loggedIn()->member_id,
|
||||
'member_name' => Member::loggedIn()->name,
|
||||
'ctime' => time(),
|
||||
'note' => json_encode( array( $post->pid => $args['solved'] ) ),
|
||||
'ip_address' => \IPS\Request::i()->ipAddress(),
|
||||
'ip_address' => Request::i()->ipAddress(),
|
||||
'appcomponent' => 'forums',
|
||||
'module' => 'forums',
|
||||
'controller' => 'topic',
|
||||
|
||||
@@ -10,30 +10,35 @@
|
||||
*/
|
||||
|
||||
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\CommentMutator;
|
||||
use IPS\forums\api\GraphQL\Types\PostType;
|
||||
use IPS\forums\Topic\Post;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* React to post mutation for GraphQL API
|
||||
*/
|
||||
class _PostReaction extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
class PostReaction extends CommentMutator
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\forums\Topic\Post';
|
||||
protected string $class = 'IPS\forums\Topic\Post';
|
||||
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "React to a post";
|
||||
public static string $description = "React to a post";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -49,30 +54,33 @@ class _PostReaction extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return PostType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : PostType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::post();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves this mutation
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Topic\Post
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return Post
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : Post
|
||||
{
|
||||
/* Get topic */
|
||||
try
|
||||
{
|
||||
$post = \IPS\forums\Topic\Post::loadAndCheckPerms( $args['postID'] );
|
||||
$post = Post::loadAndCheckPerms( $args['postID'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', '1F295/1_graphl', 403 );
|
||||
throw new SafeException( 'NO_POST', '1F295/1_graphl', 403 );
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
|
||||
@@ -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\CommentMutator;
|
||||
use IPS\Content\Comment;
|
||||
use IPS\forums\api\GraphQL\Types\PostType;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\forums\Topic\Post;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reply to topic mutation for GraphQL API
|
||||
*/
|
||||
class _ReplyTopic extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
class ReplyTopic extends CommentMutator
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\forums\Topic\Post';
|
||||
protected string $class = 'IPS\forums\Topic\Post';
|
||||
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Create a new post";
|
||||
public static string $description = "Create a new post";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -50,42 +58,45 @@ class _ReplyTopic extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return PostType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : PostType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::post();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves this mutation
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return Post
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : Comment
|
||||
{
|
||||
/* Get topic */
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( $args['topicID'] );
|
||||
$topic = Topic::loadAndCheckPerms( $args['topicID'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_TOPIC', '1F295/1_graphl', 403 );
|
||||
throw new SafeException( 'NO_TOPIC', '1F295/1_graphl', 403 );
|
||||
}
|
||||
|
||||
/* Get author */
|
||||
if ( !$topic->canComment( \IPS\Member::loggedIn() ) )
|
||||
if ( !$topic->canComment( Member::loggedIn() ) )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', '2F294/A_graphl', 403 );
|
||||
throw new SafeException( 'NO_PERMISSION', '2F294/A_graphl', 403 );
|
||||
}
|
||||
|
||||
/* Check we have a post */
|
||||
if ( !$args['content'] )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', '1F295/3_graphl', 403 );
|
||||
throw new SafeException( 'NO_POST', '1F295/3_graphl', 403 );
|
||||
}
|
||||
|
||||
$originalPost = NULL;
|
||||
@@ -94,9 +105,9 @@ class _ReplyTopic extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
{
|
||||
try
|
||||
{
|
||||
$originalPost = \IPS\forums\Topic\Post::loadAndCheckPerms( $args['replyingTo'] );
|
||||
$originalPost = Post::loadAndCheckPerms( $args['replyingTo'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
// Just ignore it
|
||||
}
|
||||
|
||||
@@ -10,30 +10,36 @@
|
||||
*/
|
||||
|
||||
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\CommentMutator;
|
||||
use IPS\Content\Comment;
|
||||
use IPS\forums\api\GraphQL\Types\PostType;
|
||||
use IPS\forums\Topic\Post;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report post mutation for GraphQL API
|
||||
*/
|
||||
class _ReportPost extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
class ReportPost extends CommentMutator
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\forums\Topic\Post';
|
||||
protected string $class = 'IPS\forums\Topic\Post';
|
||||
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Report a post";
|
||||
public static string $description = "Report a post";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -52,30 +58,33 @@ class _ReportPost extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return PostType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : PostType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::post();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves this mutation
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Topic\Post
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return Post
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : Comment
|
||||
{
|
||||
/* Get post */
|
||||
try
|
||||
{
|
||||
$post = \IPS\forums\Topic\Post::loadAndCheckPerms( $args['id'] );
|
||||
$post = Post::loadAndCheckPerms( $args['id'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', '1F295/1_graphl', 403 );
|
||||
throw new SafeException( 'NO_POST', '1F295/1_graphl', 403 );
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
|
||||
@@ -10,30 +10,36 @@
|
||||
*/
|
||||
|
||||
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\CommentMutator;
|
||||
use IPS\Content\Comment;
|
||||
use IPS\forums\api\GraphQL\Types\PostType;
|
||||
use IPS\forums\Topic\Post;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke post report mutation for GraphQL API
|
||||
*/
|
||||
class _RevokePostReport extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
class RevokePostReport extends CommentMutator
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\forums\Topic\Post';
|
||||
protected string $class = 'IPS\forums\Topic\Post';
|
||||
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Report a post";
|
||||
public static string $description = "Report a post";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -48,30 +54,33 @@ class _RevokePostReport extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return PostType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : PostType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::post();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves this mutation
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Topic\Post
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return Post
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : Comment
|
||||
{
|
||||
/* Get post */
|
||||
try
|
||||
{
|
||||
$post = \IPS\forums\Topic\Post::loadAndCheckPerms( $args['id'] );
|
||||
$post = Post::loadAndCheckPerms( $args['id'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', '1F295/1_graphl', 403 );
|
||||
throw new SafeException( 'NO_POST', '1F295/1_graphl', 403 );
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
|
||||
@@ -10,25 +10,30 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use Exception;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\forums\api\GraphQL\Types\PostType;
|
||||
use IPS\forums\Topic\Post;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a post as best answer mutation for GraphQL API
|
||||
*/
|
||||
class _SetBestAnswer
|
||||
class SetBestAnswer
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Set a post as best answer";
|
||||
public static string $description = "Set a post as best answer";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -42,8 +47,10 @@ class _SetBestAnswer
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return PostType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : PostType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::post();
|
||||
}
|
||||
@@ -51,36 +58,30 @@ class _SetBestAnswer
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Post
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Post
|
||||
{
|
||||
try
|
||||
{
|
||||
$post = \IPS\forums\Topic\Post::loadAndCheckPerms( $args['id'] );
|
||||
$post = Post::loadAndCheckPerms( $args['id'] );
|
||||
$topic = $post->item();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', 'GQL/0010/1', 403 );
|
||||
throw new SafeException( 'NO_POST', 'GQL/0010/1', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->can('read') )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_ID', 'GQL/0010/2', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->isQuestion() )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NON_QUESTION', 'GQL/0010/3', 403 );
|
||||
throw new SafeException( 'INVALID_ID', 'GQL/0010/2', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->canSetBestAnswer() )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', 'GQL/0010/4', 403 );
|
||||
throw new SafeException( 'NO_PERMISSION', 'GQL/0010/4', 403 );
|
||||
}
|
||||
|
||||
// Do we have an existing best answer
|
||||
@@ -88,11 +89,11 @@ class _SetBestAnswer
|
||||
{
|
||||
try
|
||||
{
|
||||
$oldBestAnswer = \IPS\forums\Topic\Post::load( $topic->topic_answered_pid );
|
||||
$oldBestAnswer = Post::load( $topic->topic_answered_pid );
|
||||
$oldBestAnswer->post_bwoptions['best_answer'] = FALSE;
|
||||
$oldBestAnswer->save();
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
catch ( Exception $e ) {}
|
||||
}
|
||||
|
||||
$post->post_bwoptions['best_answer'] = TRUE;
|
||||
|
||||
@@ -10,25 +10,32 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Db;
|
||||
use IPS\forums\api\GraphQL\Types\PostType;
|
||||
use IPS\forums\Topic\Post;
|
||||
use IPS\Member;
|
||||
use OutOfRangeException;
|
||||
use UnderflowException;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vote on an answer mutation for GraphQL API
|
||||
*/
|
||||
class _VoteAnswer
|
||||
class VoteAnswer
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Vote on an answer";
|
||||
public static string $description = "Vote on an answer";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -43,8 +50,10 @@ class _VoteAnswer
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return PostType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : PostType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::post();
|
||||
}
|
||||
@@ -52,36 +61,30 @@ class _VoteAnswer
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Post
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Post
|
||||
{
|
||||
try
|
||||
{
|
||||
$post = \IPS\forums\Topic\Post::loadAndCheckPerms( $args['id'] );
|
||||
$post = Post::loadAndCheckPerms( $args['id'] );
|
||||
$topic = $post->item();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', 'GQL/0009/1', 403 );
|
||||
throw new SafeException( 'NO_POST', 'GQL/0009/1', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->can('read') )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_ID', 'GQL/0009/2', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->isQuestion() )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NON_QUESTION', 'GQL/0009/3', 403 );
|
||||
throw new SafeException( 'INVALID_ID', 'GQL/0009/2', 403 );
|
||||
}
|
||||
|
||||
if( !$post->canVote() )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'CANNOT_VOTE', 'GQL/0009/4', 403 );
|
||||
throw new SafeException( 'CANNOT_VOTE', 'GQL/0009/4', 403 );
|
||||
}
|
||||
|
||||
$rating = $args['vote'] == 'UP' ? 1 : -1;
|
||||
@@ -89,20 +92,19 @@ class _VoteAnswer
|
||||
/* Have we already rated ? */
|
||||
try
|
||||
{
|
||||
\IPS\Db::i()->delete( 'forums_answer_ratings', array( 'topic=? AND post=? AND `member`=?', $topic->tid, $post->pid, \IPS\Member::loggedIn()->member_id ) );
|
||||
Db::i()->delete( 'forums_answer_ratings', array( 'topic=? AND post=? AND `member`=?', $topic->tid, $post->pid, Member::loggedIn()->member_id ) );
|
||||
}
|
||||
catch ( \UnderflowException $e ){}
|
||||
catch ( UnderflowException $e ){}
|
||||
|
||||
\IPS\Db::i()->insert( 'forums_answer_ratings', array(
|
||||
Db::i()->insert( 'forums_answer_ratings', array(
|
||||
'post' => $post->pid,
|
||||
'topic' => $topic->tid,
|
||||
'member' => \IPS\Member::loggedIn()->member_id,
|
||||
'member' => Member::loggedIn()->member_id,
|
||||
'rating' => $rating,
|
||||
'date' => time()
|
||||
), TRUE );
|
||||
|
||||
/* @note SELECT_FROM_WRITE_SERVER race condition */
|
||||
$post->post_field_int = (int) \IPS\Db::i()->select( 'SUM(rating)', 'forums_answer_ratings', array( 'post=?', $post->pid ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$post->post_field_int = (int) Db::i()->select( 'SUM(rating)', 'forums_answer_ratings', array( 'post=?', $post->pid ), NULL, NULL, NULL, NULL, Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$post->save();
|
||||
|
||||
return $post;
|
||||
|
||||
@@ -10,31 +10,36 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\InputObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\forums\api\GraphQL\Types\TopicType;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\Poll\Api\GraphQL\PollMutator;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vote in poll mutation for GraphQL API
|
||||
*/
|
||||
class _VoteInPoll extends \IPS\Poll\Api\GraphQL\PollMutator
|
||||
class VoteInPoll extends PollMutator
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\forums\Topic';
|
||||
protected string $class = 'IPS\forums\Topic';
|
||||
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Vote in a poll in a topic";
|
||||
public static string $description = "Vote in a poll in a topic";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -57,8 +62,10 @@ class _VoteInPoll extends \IPS\Poll\Api\GraphQL\PollMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return TopicType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : TopicType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::topic();
|
||||
}
|
||||
@@ -66,27 +73,26 @@ class _VoteInPoll extends \IPS\Poll\Api\GraphQL\PollMutator
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Topic
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Topic
|
||||
{
|
||||
/* Get topic */
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( $args['itemID'] );
|
||||
$topic = Topic::loadAndCheckPerms( $args['itemID'] );
|
||||
$poll = $topic->getPoll();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_TOPIC', 'GQL/0006/1', 403 );
|
||||
throw new SafeException( 'INVALID_TOPIC', 'GQL/0006/1', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->can('read') || $poll === NULL )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POLL', 'GQL/0006/2', 403 );
|
||||
throw new SafeException( 'NO_POLL', 'GQL/0006/2', 403 );
|
||||
}
|
||||
|
||||
$this->_vote( $poll, $args['poll'] );
|
||||
|
||||
@@ -10,25 +10,31 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Db;
|
||||
use IPS\forums\api\GraphQL\Types\TopicType;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vote on a question mutation for GraphQL API
|
||||
*/
|
||||
class _VoteQuestion
|
||||
class VoteQuestion
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Vote on a question";
|
||||
public static string $description = "Vote on a question";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -43,8 +49,10 @@ class _VoteQuestion
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return TopicType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : TopicType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::topic();
|
||||
}
|
||||
@@ -52,57 +60,50 @@ class _VoteQuestion
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Topic
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Topic
|
||||
{
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( $args['id'] );
|
||||
$topic = Topic::loadAndCheckPerms( $args['id'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_TOPIC', 'GQL/0008/1', 400 );
|
||||
throw new SafeException( 'NO_TOPIC', 'GQL/0008/1', 400 );
|
||||
}
|
||||
|
||||
if( !$topic->can('read') )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_ID', 'GQL/0008/2', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->isQuestion() )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NON_QUESTION', 'GQL/0008/3', 403 );
|
||||
throw new SafeException( 'INVALID_ID', 'GQL/0008/2', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->canVote() )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'CANNOT_VOTE', 'GQL/0008/4', 403 );
|
||||
throw new SafeException( 'CANNOT_VOTE', 'GQL/0008/4', 403 );
|
||||
}
|
||||
|
||||
$rating = $args['vote'] == 'UP' ? 1 : -1;
|
||||
|
||||
// If we have an existing vote, undo that
|
||||
$ratings = $topic->votes();
|
||||
if ( isset( $ratings[ \IPS\Member::loggedIn()->member_id ] ) )
|
||||
if ( isset( $ratings[ Member::loggedIn()->member_id ] ) )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'forums_question_ratings', array( 'topic=? AND member=?', $topic->tid, \IPS\Member::loggedIn()->member_id ) );
|
||||
Db::i()->delete( 'forums_question_ratings', array( 'topic=? AND member=?', $topic->tid, Member::loggedIn()->member_id ) );
|
||||
}
|
||||
|
||||
\IPS\Db::i()->insert( 'forums_question_ratings', array(
|
||||
Db::i()->insert( 'forums_question_ratings', array(
|
||||
'topic' => $topic->tid,
|
||||
'forum' => $topic->forum_id,
|
||||
'member' => \IPS\Member::loggedIn()->member_id,
|
||||
'member' => Member::loggedIn()->member_id,
|
||||
'rating' => $rating,
|
||||
'date' => time()
|
||||
), TRUE );
|
||||
|
||||
/* Rebuild count */
|
||||
/* @note SELECT_FROM_WRITE_SERVER race condition */
|
||||
$topic->question_rating = \IPS\Db::i()->select( 'SUM(rating)', 'forums_question_ratings', array( 'topic=?', $topic->tid ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$topic->question_rating = Db::i()->select( 'SUM(rating)', 'forums_question_ratings', array( 'topic=?', $topic->tid ), NULL, NULL, NULL, NULL, Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$topic->save();
|
||||
|
||||
return $topic;
|
||||
|
||||
Reference in new issue
Block a user