| @@ 17-86 (lines=70) @@ | ||
| 14 | use GraphQL\Type\Definition\ResolveInfo;  | 
                                |
| 15 | use WPGraphQL\AppContext;  | 
                                |
| 16 | ||
| 17 | class PriceDelete extends EntityMutator  | 
                                |
| 18 | { | 
                                |
| 19 | ||
| 20 | /**  | 
                                |
| 21 | * Defines the mutation data modification closure.  | 
                                |
| 22 | *  | 
                                |
| 23 | * @param EEM_Price $model  | 
                                |
| 24 | * @param Price $type  | 
                                |
| 25 | * @return callable  | 
                                |
| 26 | */  | 
                                |
| 27 | public static function mutateAndGetPayload(EEM_Price $model, Price $type)  | 
                                |
| 28 |     { | 
                                |
| 29 | /**  | 
                                |
| 30 | * Deletes an entity.  | 
                                |
| 31 | *  | 
                                |
| 32 | * @param array $input The input for the mutation  | 
                                |
| 33 | * @param AppContext $context The AppContext passed down to all resolvers  | 
                                |
| 34 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers  | 
                                |
| 35 | * @return array  | 
                                |
| 36 | */  | 
                                |
| 37 |         return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { | 
                                |
| 38 |             try { | 
                                |
| 39 | /** @var EE_Price $entity */  | 
                                |
| 40 | $entity = EntityMutator::getEntityFromInputData($model, $input);  | 
                                |
| 41 | ||
| 42 | // Delete the entity  | 
                                |
| 43 |                 if (! empty($input['deletePermanently'])) { | 
                                |
| 44 | $result = PriceDelete::deletePriceAndRelations($entity);  | 
                                |
| 45 |                 } else { | 
                                |
| 46 | // trash the price  | 
                                |
| 47 | $result = $entity->delete();  | 
                                |
| 48 | }  | 
                                |
| 49 | EntityMutator::validateResults($result);  | 
                                |
| 50 |             } catch (Exception $exception) { | 
                                |
| 51 | EntityMutator::handleExceptions(  | 
                                |
| 52 | $exception,  | 
                                |
| 53 | esc_html__(  | 
                                |
| 54 | 'The price could not be deleted because of the following error(s)',  | 
                                |
| 55 | 'event_espresso'  | 
                                |
| 56 | )  | 
                                |
| 57 | );  | 
                                |
| 58 | }  | 
                                |
| 59 | ||
| 60 | return [  | 
                                |
| 61 | 'deleted' => $entity,  | 
                                |
| 62 | ];  | 
                                |
| 63 | };  | 
                                |
| 64 | }  | 
                                |
| 65 | ||
| 66 | /**  | 
                                |
| 67 | * Deletes a price permanently along with its relations.  | 
                                |
| 68 | *  | 
                                |
| 69 | * @param EE_Price $entity  | 
                                |
| 70 | * @return bool | int  | 
                                |
| 71 | * @throws ReflectionException  | 
                                |
| 72 | * @throws InvalidArgumentException  | 
                                |
| 73 | * @throws InvalidInterfaceException  | 
                                |
| 74 | * @throws InvalidDataTypeException  | 
                                |
| 75 | * @throws EE_Error  | 
                                |
| 76 | */  | 
                                |
| 77 | public static function deletePriceAndRelations($entity)  | 
                                |
| 78 |     { | 
                                |
| 79 | // Remove relation with ticket  | 
                                |
| 80 |         $entity->_remove_relations('Ticket'); | 
                                |
| 81 | // Now delete the price permanently  | 
                                |
| 82 | $result = $entity->delete_permanently();  | 
                                |
| 83 | ||
| 84 | return $result;  | 
                                |
| 85 | }  | 
                                |
| 86 | }  | 
                                |
| 87 | ||
| @@ 17-88 (lines=72) @@ | ||
| 14 | use GraphQL\Type\Definition\ResolveInfo;  | 
                                |
| 15 | use WPGraphQL\AppContext;  | 
                                |
| 16 | ||
| 17 | class TicketDelete extends EntityMutator  | 
                                |
| 18 | { | 
                                |
| 19 | ||
| 20 | /**  | 
                                |
| 21 | * Defines the mutation data modification closure.  | 
                                |
| 22 | *  | 
                                |
| 23 | * @param EEM_Ticket $model  | 
                                |
| 24 | * @param Ticket $type  | 
                                |
| 25 | * @return callable  | 
                                |
| 26 | */  | 
                                |
| 27 | public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type)  | 
                                |
| 28 |     { | 
                                |
| 29 | /**  | 
                                |
| 30 | * Deletes an entity.  | 
                                |
| 31 | *  | 
                                |
| 32 | * @param array $input The input for the mutation  | 
                                |
| 33 | * @param AppContext $context The AppContext passed down to all resolvers  | 
                                |
| 34 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers  | 
                                |
| 35 | * @return array  | 
                                |
| 36 | */  | 
                                |
| 37 |         return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { | 
                                |
| 38 |             try { | 
                                |
| 39 | /** @var EE_Ticket $entity */  | 
                                |
| 40 | $entity = EntityMutator::getEntityFromInputData($model, $input);  | 
                                |
| 41 | ||
| 42 | // Delete the entity  | 
                                |
| 43 |                 if (! empty($input['deletePermanently'])) { | 
                                |
| 44 | $result = TicketDelete::deleteTicketAndRelations($entity);  | 
                                |
| 45 |                 } else { | 
                                |
| 46 | // trash the ticket  | 
                                |
| 47 | $result = $entity->delete();  | 
                                |
| 48 | }  | 
                                |
| 49 | EntityMutator::validateResults($result);  | 
                                |
| 50 |             } catch (Exception $exception) { | 
                                |
| 51 | EntityMutator::handleExceptions(  | 
                                |
| 52 | $exception,  | 
                                |
| 53 | esc_html__(  | 
                                |
| 54 | 'The ticket could not be deleted because of the following error(s)',  | 
                                |
| 55 | 'event_espresso'  | 
                                |
| 56 | )  | 
                                |
| 57 | );  | 
                                |
| 58 | }  | 
                                |
| 59 | ||
| 60 | return [  | 
                                |
| 61 | 'deleted' => $entity,  | 
                                |
| 62 | ];  | 
                                |
| 63 | };  | 
                                |
| 64 | }  | 
                                |
| 65 | ||
| 66 | /**  | 
                                |
| 67 | * Deletes a ticket permanently along with its relations.  | 
                                |
| 68 | *  | 
                                |
| 69 | * @param EE_Ticket $entity  | 
                                |
| 70 | * @return bool | int  | 
                                |
| 71 | * @throws ReflectionException  | 
                                |
| 72 | * @throws InvalidArgumentException  | 
                                |
| 73 | * @throws InvalidInterfaceException  | 
                                |
| 74 | * @throws InvalidDataTypeException  | 
                                |
| 75 | * @throws EE_Error  | 
                                |
| 76 | */  | 
                                |
| 77 | public static function deleteTicketAndRelations($entity)  | 
                                |
| 78 |     { | 
                                |
| 79 | // Remove related prices for the ticket  | 
                                |
| 80 |         $entity->delete_related_permanently('Price'); | 
                                |
| 81 | // Remove relation with datetimes  | 
                                |
| 82 |         $entity->_remove_relations('Datetime'); | 
                                |
| 83 | // Now delete the ticket permanently  | 
                                |
| 84 | $result = $entity->delete_permanently();  | 
                                |
| 85 | ||
| 86 | return $result;  | 
                                |
| 87 | }  | 
                                |
| 88 | }  | 
                                |
| 89 | ||