CreateCoupon.php
1 month ago
CreateProduct.php
1 month ago
DeleteCoupon.php
1 month ago
DeleteProduct.php
1 month ago
UpdateCoupon.php
1 month ago
UpdateProduct.php
1 month ago
DeleteProduct.php
94 lines
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | |
| 4 | // THIS FILE IS AUTO-GENERATED. DO NOT EDIT MANUALLY. |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Internal\Api\Autogenerated\GraphQLMutations; |
| 7 | |
| 8 | use Automattic\WooCommerce\Api\Mutations\Products\DeleteProduct as DeleteProductCommand; |
| 9 | use Automattic\WooCommerce\Api\Infrastructure\QueryInfoExtractor; |
| 10 | use Automattic\WooCommerce\Api\Infrastructure\ResolverHelpers; |
| 11 | use Automattic\WooCommerce\Api\Infrastructure\Schema\ResolveInfo; |
| 12 | use Automattic\WooCommerce\Api\Infrastructure\Schema\Type; |
| 13 | |
| 14 | class DeleteProduct { |
| 15 | public static function get_field_definition(): array { |
| 16 | return array( |
| 17 | 'type' => Type::nonNull( |
| 18 | new \Automattic\WooCommerce\Api\Infrastructure\Schema\ObjectType( |
| 19 | array( |
| 20 | 'name' => 'DeleteProductResult', |
| 21 | 'fields' => array( |
| 22 | 'result' => array( 'type' => Type::nonNull( Type::boolean() ) ), |
| 23 | ), |
| 24 | ) |
| 25 | ) |
| 26 | ), |
| 27 | 'description' => __( 'Delete a product.', 'woocommerce' ), |
| 28 | 'authorization' => array( |
| 29 | array( |
| 30 | 'attribute' => 'RequiredCapability', |
| 31 | 'args' => array( |
| 32 | 0 => 'manage_woocommerce', |
| 33 | ), |
| 34 | ), |
| 35 | ), |
| 36 | 'args' => array( |
| 37 | 'id' => array( |
| 38 | 'type' => Type::nonNull( Type::int() ), |
| 39 | 'description' => __( 'The ID of the product to delete.', 'woocommerce' ), |
| 40 | ), |
| 41 | 'force' => array( |
| 42 | 'type' => Type::nonNull( Type::boolean() ), |
| 43 | 'description' => __( 'Whether to permanently delete the product (bypass trash).', 'woocommerce' ), |
| 44 | 'defaultValue' => false, |
| 45 | ), |
| 46 | ), |
| 47 | 'resolve' => array( self::class, 'resolve' ), |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | public static function resolve( mixed $root, array $args, mixed $context, ResolveInfo $info ): mixed { |
| 52 | // Standalone authorization gate: no authorize() method on the command, |
| 53 | // so the autodiscovered authorization attributes are the sole guard. |
| 54 | if ( ! self::compute_preauthorized( $context['principal'] ) ) { |
| 55 | throw ResolverHelpers::build_authorization_error( $context['principal'] ); |
| 56 | } |
| 57 | |
| 58 | // Publish the root query's metadata so downstream field-level |
| 59 | // authorization gates can read it via `$_metadata['query']`. |
| 60 | // $context is an ArrayObject (see GraphQLController::process_request()) |
| 61 | // so the mutation propagates to nested resolvers. |
| 62 | $context['_query_metadata'] = array(); |
| 63 | |
| 64 | $command = \Automattic\WooCommerce\Api\Infrastructure\ClassResolver::resolve_class( DeleteProductCommand::class ); |
| 65 | |
| 66 | $execute_args = array(); |
| 67 | if ( array_key_exists( 'id', $args ) ) { |
| 68 | $execute_args['id'] = $args['id']; |
| 69 | } |
| 70 | if ( array_key_exists( 'force', $args ) ) { |
| 71 | $execute_args['force'] = $args['force']; |
| 72 | } |
| 73 | |
| 74 | $result = ResolverHelpers::execute_command( $command, $execute_args ); |
| 75 | |
| 76 | return array( 'result' => $result ); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Compute the value `_preauthorized` would carry for a given principal — |
| 81 | * the AND of the autodiscovered authorization attributes' authorize() |
| 82 | * outcomes on this command. Single source of truth for both the resolver's |
| 83 | * own gates and external (code-API) callers asking about authorization |
| 84 | * without going through GraphQL execution. |
| 85 | * |
| 86 | * Returns true vacuously when the command has no authorization attributes |
| 87 | * (in that case authorize() on the command is the sole guard, and that |
| 88 | * method should be consulted instead). |
| 89 | */ |
| 90 | public static function compute_preauthorized( \Automattic\WooCommerce\Api\Infrastructure\Principal $principal ): bool { |
| 91 | return ( new \Automattic\WooCommerce\Api\Attributes\RequiredCapability( 'manage_woocommerce' ) )->authorize( $principal ); |
| 92 | } |
| 93 | } |
| 94 |