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,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;
|
||||
|
||||
Reference in new issue
Block a user