@@ -17,107 +17,107 @@ |
||
17 | 17 | class DatetimeDelete extends EntityMutator |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * Defines the mutation data modification closure. |
|
22 | - * |
|
23 | - * @param EEM_Datetime $model |
|
24 | - * @param Datetime $type |
|
25 | - * @return callable |
|
26 | - */ |
|
27 | - public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $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 (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
38 | - try { |
|
39 | - /** @var EE_Datetime $entity */ |
|
40 | - $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
20 | + /** |
|
21 | + * Defines the mutation data modification closure. |
|
22 | + * |
|
23 | + * @param EEM_Datetime $model |
|
24 | + * @param Datetime $type |
|
25 | + * @return callable |
|
26 | + */ |
|
27 | + public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $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 (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
38 | + try { |
|
39 | + /** @var EE_Datetime $entity */ |
|
40 | + $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
41 | 41 | |
42 | - // Delete the entity |
|
43 | - if (! empty($input['deletePermanently'])) { |
|
44 | - $result = DatetimeDelete::deleteDatetimeAndRelations($entity); |
|
45 | - } else { |
|
46 | - $result = DatetimeDelete::trashDatetimeAndRelations($entity); |
|
47 | - } |
|
48 | - EntityMutator::validateResults($result); |
|
42 | + // Delete the entity |
|
43 | + if (! empty($input['deletePermanently'])) { |
|
44 | + $result = DatetimeDelete::deleteDatetimeAndRelations($entity); |
|
45 | + } else { |
|
46 | + $result = DatetimeDelete::trashDatetimeAndRelations($entity); |
|
47 | + } |
|
48 | + EntityMutator::validateResults($result); |
|
49 | 49 | |
50 | - do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_datetime_delete', $entity, $input); |
|
51 | - } catch (Exception $exception) { |
|
52 | - EntityMutator::handleExceptions( |
|
53 | - $exception, |
|
54 | - esc_html__( |
|
55 | - 'The datetime could not be deleted because of the following error(s)', |
|
56 | - 'event_espresso' |
|
57 | - ) |
|
58 | - ); |
|
59 | - } |
|
50 | + do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_datetime_delete', $entity, $input); |
|
51 | + } catch (Exception $exception) { |
|
52 | + EntityMutator::handleExceptions( |
|
53 | + $exception, |
|
54 | + esc_html__( |
|
55 | + 'The datetime could not be deleted because of the following error(s)', |
|
56 | + 'event_espresso' |
|
57 | + ) |
|
58 | + ); |
|
59 | + } |
|
60 | 60 | |
61 | - return [ |
|
62 | - 'deleted' => $entity, |
|
63 | - ]; |
|
64 | - }; |
|
65 | - } |
|
61 | + return [ |
|
62 | + 'deleted' => $entity, |
|
63 | + ]; |
|
64 | + }; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Deletes a datetime permanently along with its relations. |
|
69 | - * |
|
70 | - * @param EE_Datetime $entity |
|
71 | - * @return bool | int |
|
72 | - * @throws ReflectionException |
|
73 | - * @throws InvalidArgumentException |
|
74 | - * @throws InvalidInterfaceException |
|
75 | - * @throws InvalidDataTypeException |
|
76 | - * @throws EE_Error |
|
77 | - */ |
|
78 | - public static function deleteDatetimeAndRelations(EE_Datetime $entity) |
|
79 | - { |
|
80 | - // all related tickets |
|
81 | - $tickets = $entity->tickets(); |
|
82 | - foreach ($tickets as $ticket) { |
|
83 | - // if the ticket is related to only one datetime |
|
84 | - if ($ticket->count_related('Datetime') === 1) { |
|
85 | - TicketDelete::deleteTicketAndRelations($ticket); |
|
86 | - } |
|
87 | - } |
|
67 | + /** |
|
68 | + * Deletes a datetime permanently along with its relations. |
|
69 | + * |
|
70 | + * @param EE_Datetime $entity |
|
71 | + * @return bool | int |
|
72 | + * @throws ReflectionException |
|
73 | + * @throws InvalidArgumentException |
|
74 | + * @throws InvalidInterfaceException |
|
75 | + * @throws InvalidDataTypeException |
|
76 | + * @throws EE_Error |
|
77 | + */ |
|
78 | + public static function deleteDatetimeAndRelations(EE_Datetime $entity) |
|
79 | + { |
|
80 | + // all related tickets |
|
81 | + $tickets = $entity->tickets(); |
|
82 | + foreach ($tickets as $ticket) { |
|
83 | + // if the ticket is related to only one datetime |
|
84 | + if ($ticket->count_related('Datetime') === 1) { |
|
85 | + TicketDelete::deleteTicketAndRelations($ticket); |
|
86 | + } |
|
87 | + } |
|
88 | 88 | |
89 | - // Remove relations with tickets |
|
90 | - $entity->_remove_relations('Ticket'); |
|
91 | - // Now delete the datetime permanently |
|
92 | - return $entity->delete_permanently(); |
|
93 | - } |
|
89 | + // Remove relations with tickets |
|
90 | + $entity->_remove_relations('Ticket'); |
|
91 | + // Now delete the datetime permanently |
|
92 | + return $entity->delete_permanently(); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Trashes a datetime along with its lone relations. |
|
97 | - * |
|
98 | - * @param EE_Datetime $entity |
|
99 | - * @return bool | int |
|
100 | - * @throws ReflectionException |
|
101 | - * @throws InvalidArgumentException |
|
102 | - * @throws InvalidInterfaceException |
|
103 | - * @throws InvalidDataTypeException |
|
104 | - * @throws EE_Error |
|
105 | - */ |
|
106 | - public static function trashDatetimeAndRelations(EE_Datetime $entity) |
|
107 | - { |
|
108 | - // non trashed related tickets |
|
109 | - $tickets = $entity->tickets([[ |
|
110 | - 'TKT_deleted' => false, |
|
111 | - ]]); |
|
112 | - // loop though all tickets to check if we need to trash any |
|
113 | - foreach ($tickets as $ticket) { |
|
114 | - // if the ticket is related to only one datetime |
|
115 | - if ($ticket->count_related('Datetime') === 1) { |
|
116 | - // trash the ticket |
|
117 | - $ticket->delete(); |
|
118 | - } |
|
119 | - } |
|
120 | - // trash the datetime |
|
121 | - return $entity->delete(); |
|
122 | - } |
|
95 | + /** |
|
96 | + * Trashes a datetime along with its lone relations. |
|
97 | + * |
|
98 | + * @param EE_Datetime $entity |
|
99 | + * @return bool | int |
|
100 | + * @throws ReflectionException |
|
101 | + * @throws InvalidArgumentException |
|
102 | + * @throws InvalidInterfaceException |
|
103 | + * @throws InvalidDataTypeException |
|
104 | + * @throws EE_Error |
|
105 | + */ |
|
106 | + public static function trashDatetimeAndRelations(EE_Datetime $entity) |
|
107 | + { |
|
108 | + // non trashed related tickets |
|
109 | + $tickets = $entity->tickets([[ |
|
110 | + 'TKT_deleted' => false, |
|
111 | + ]]); |
|
112 | + // loop though all tickets to check if we need to trash any |
|
113 | + foreach ($tickets as $ticket) { |
|
114 | + // if the ticket is related to only one datetime |
|
115 | + if ($ticket->count_related('Datetime') === 1) { |
|
116 | + // trash the ticket |
|
117 | + $ticket->delete(); |
|
118 | + } |
|
119 | + } |
|
120 | + // trash the datetime |
|
121 | + return $entity->delete(); |
|
122 | + } |
|
123 | 123 | } |
@@ -34,13 +34,13 @@ |
||
34 | 34 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
35 | 35 | * @return array |
36 | 36 | */ |
37 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
37 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
38 | 38 | try { |
39 | 39 | /** @var EE_Datetime $entity */ |
40 | 40 | $entity = EntityMutator::getEntityFromInputData($model, $input); |
41 | 41 | |
42 | 42 | // Delete the entity |
43 | - if (! empty($input['deletePermanently'])) { |
|
43 | + if ( ! empty($input['deletePermanently'])) { |
|
44 | 44 | $result = DatetimeDelete::deleteDatetimeAndRelations($entity); |
45 | 45 | } else { |
46 | 46 | $result = DatetimeDelete::trashDatetimeAndRelations($entity); |
@@ -17,70 +17,70 @@ |
||
17 | 17 | class PriceDelete extends EntityMutator |
18 | 18 | { |
19 | 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 (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
38 | - try { |
|
39 | - /** @var EE_Price $entity */ |
|
40 | - $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
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 (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
38 | + try { |
|
39 | + /** @var EE_Price $entity */ |
|
40 | + $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
41 | 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); |
|
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 | 50 | |
51 | - do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_price_delete', $entity, $input); |
|
52 | - } catch (Exception $exception) { |
|
53 | - EntityMutator::handleExceptions( |
|
54 | - $exception, |
|
55 | - esc_html__( |
|
56 | - 'The price could not be deleted because of the following error(s)', |
|
57 | - 'event_espresso' |
|
58 | - ) |
|
59 | - ); |
|
60 | - } |
|
51 | + do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_price_delete', $entity, $input); |
|
52 | + } catch (Exception $exception) { |
|
53 | + EntityMutator::handleExceptions( |
|
54 | + $exception, |
|
55 | + esc_html__( |
|
56 | + 'The price could not be deleted because of the following error(s)', |
|
57 | + 'event_espresso' |
|
58 | + ) |
|
59 | + ); |
|
60 | + } |
|
61 | 61 | |
62 | - return [ |
|
63 | - 'deleted' => $entity, |
|
64 | - ]; |
|
65 | - }; |
|
66 | - } |
|
62 | + return [ |
|
63 | + 'deleted' => $entity, |
|
64 | + ]; |
|
65 | + }; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Deletes a price permanently along with its relations. |
|
70 | - * |
|
71 | - * @param EE_Price $entity |
|
72 | - * @return bool | int |
|
73 | - * @throws ReflectionException |
|
74 | - * @throws InvalidArgumentException |
|
75 | - * @throws InvalidInterfaceException |
|
76 | - * @throws InvalidDataTypeException |
|
77 | - * @throws EE_Error |
|
78 | - */ |
|
79 | - public static function deletePriceAndRelations(EE_Price $entity) |
|
80 | - { |
|
81 | - // Remove relation with ticket |
|
82 | - $entity->_remove_relations('Ticket'); |
|
83 | - // Now delete the price permanently |
|
84 | - return $entity->delete_permanently(); |
|
85 | - } |
|
68 | + /** |
|
69 | + * Deletes a price permanently along with its relations. |
|
70 | + * |
|
71 | + * @param EE_Price $entity |
|
72 | + * @return bool | int |
|
73 | + * @throws ReflectionException |
|
74 | + * @throws InvalidArgumentException |
|
75 | + * @throws InvalidInterfaceException |
|
76 | + * @throws InvalidDataTypeException |
|
77 | + * @throws EE_Error |
|
78 | + */ |
|
79 | + public static function deletePriceAndRelations(EE_Price $entity) |
|
80 | + { |
|
81 | + // Remove relation with ticket |
|
82 | + $entity->_remove_relations('Ticket'); |
|
83 | + // Now delete the price permanently |
|
84 | + return $entity->delete_permanently(); |
|
85 | + } |
|
86 | 86 | } |
@@ -34,13 +34,13 @@ |
||
34 | 34 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
35 | 35 | * @return array |
36 | 36 | */ |
37 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
37 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
38 | 38 | try { |
39 | 39 | /** @var EE_Price $entity */ |
40 | 40 | $entity = EntityMutator::getEntityFromInputData($model, $input); |
41 | 41 | |
42 | 42 | // Delete the entity |
43 | - if (! empty($input['deletePermanently'])) { |
|
43 | + if ( ! empty($input['deletePermanently'])) { |
|
44 | 44 | $result = PriceDelete::deletePriceAndRelations($entity); |
45 | 45 | } else { |
46 | 46 | // trash the price |
@@ -34,7 +34,7 @@ |
||
34 | 34 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
35 | 35 | * @return void |
36 | 36 | */ |
37 | - return static function ( |
|
37 | + return static function( |
|
38 | 38 | int $id, |
39 | 39 | array $input, |
40 | 40 | WP_Post_Type $post_type_object, |
@@ -14,63 +14,63 @@ |
||
14 | 14 | class VenueUpdate extends EntityMutator |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Defines the mutation data modification closure. |
|
19 | - * |
|
20 | - * @param EEM_Venue $model |
|
21 | - * @param Venue $type |
|
22 | - * @return callable |
|
23 | - */ |
|
24 | - public static function mutateFields(EEM_Venue $model, Venue $type) |
|
25 | - { |
|
26 | - /** |
|
27 | - * Update additional data related to the entity. |
|
28 | - * |
|
29 | - * @param int $id The ID of the postObject being mutated |
|
30 | - * @param array $input The input for the mutation |
|
31 | - * @param WP_Post_Type $post_type_object The Post Type Object for the type of post being mutated |
|
32 | - * @param string $mutation_name The name of the mutation (ex: create, update, delete) |
|
33 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
34 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
35 | - * @return void |
|
36 | - */ |
|
37 | - return static function ( |
|
38 | - int $id, |
|
39 | - array $input, |
|
40 | - WP_Post_Type $post_type_object, |
|
41 | - string $mutation_name, |
|
42 | - AppContext $context, |
|
43 | - ResolveInfo $info |
|
44 | - ) use ( |
|
45 | - $model, |
|
46 | - $type |
|
47 | - ) { |
|
48 | - try { |
|
49 | - // Make sure we are dealing with the right entity. |
|
50 | - if ( |
|
51 | - ! property_exists($post_type_object, 'graphql_single_name') |
|
52 | - || $post_type_object->graphql_single_name !== $type->name() |
|
53 | - ) { |
|
54 | - return; |
|
55 | - } |
|
17 | + /** |
|
18 | + * Defines the mutation data modification closure. |
|
19 | + * |
|
20 | + * @param EEM_Venue $model |
|
21 | + * @param Venue $type |
|
22 | + * @return callable |
|
23 | + */ |
|
24 | + public static function mutateFields(EEM_Venue $model, Venue $type) |
|
25 | + { |
|
26 | + /** |
|
27 | + * Update additional data related to the entity. |
|
28 | + * |
|
29 | + * @param int $id The ID of the postObject being mutated |
|
30 | + * @param array $input The input for the mutation |
|
31 | + * @param WP_Post_Type $post_type_object The Post Type Object for the type of post being mutated |
|
32 | + * @param string $mutation_name The name of the mutation (ex: create, update, delete) |
|
33 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
34 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
35 | + * @return void |
|
36 | + */ |
|
37 | + return static function ( |
|
38 | + int $id, |
|
39 | + array $input, |
|
40 | + WP_Post_Type $post_type_object, |
|
41 | + string $mutation_name, |
|
42 | + AppContext $context, |
|
43 | + ResolveInfo $info |
|
44 | + ) use ( |
|
45 | + $model, |
|
46 | + $type |
|
47 | + ) { |
|
48 | + try { |
|
49 | + // Make sure we are dealing with the right entity. |
|
50 | + if ( |
|
51 | + ! property_exists($post_type_object, 'graphql_single_name') |
|
52 | + || $post_type_object->graphql_single_name !== $type->name() |
|
53 | + ) { |
|
54 | + return; |
|
55 | + } |
|
56 | 56 | |
57 | - /** @var EE_Venue $entity */ |
|
58 | - $entity = EntityMutator::getEntityFromID($model, $id); |
|
59 | - $args = VenueMutation::prepareFields($input); |
|
57 | + /** @var EE_Venue $entity */ |
|
58 | + $entity = EntityMutator::getEntityFromID($model, $id); |
|
59 | + $args = VenueMutation::prepareFields($input); |
|
60 | 60 | |
61 | - // Update the entity |
|
62 | - $entity->save($args); |
|
61 | + // Update the entity |
|
62 | + $entity->save($args); |
|
63 | 63 | |
64 | - do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_venue_update', $entity, $input); |
|
65 | - } catch (Exception $exception) { |
|
66 | - EntityMutator::handleExceptions( |
|
67 | - $exception, |
|
68 | - esc_html__( |
|
69 | - 'The venue could not be updated because of the following error(s)', |
|
70 | - 'event_espresso' |
|
71 | - ) |
|
72 | - ); |
|
73 | - } |
|
74 | - }; |
|
75 | - } |
|
64 | + do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_venue_update', $entity, $input); |
|
65 | + } catch (Exception $exception) { |
|
66 | + EntityMutator::handleExceptions( |
|
67 | + $exception, |
|
68 | + esc_html__( |
|
69 | + 'The venue could not be updated because of the following error(s)', |
|
70 | + 'event_espresso' |
|
71 | + ) |
|
72 | + ); |
|
73 | + } |
|
74 | + }; |
|
75 | + } |
|
76 | 76 | } |
@@ -34,7 +34,7 @@ |
||
34 | 34 | * @throws EE_Error |
35 | 35 | * @throws ReflectionException |
36 | 36 | */ |
37 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
37 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
38 | 38 | try { |
39 | 39 | /** @var EE_Price $entity */ |
40 | 40 | $entity = EntityMutator::getEntityFromInputData($model, $input); |
@@ -14,49 +14,49 @@ |
||
14 | 14 | |
15 | 15 | class PriceUpdate extends EntityMutator |
16 | 16 | { |
17 | - /** |
|
18 | - * Defines the mutation data modification closure. |
|
19 | - * |
|
20 | - * @param EEM_Price $model |
|
21 | - * @param Price $type |
|
22 | - * @return callable |
|
23 | - */ |
|
24 | - public static function mutateAndGetPayload(EEM_Price $model, Price $type) |
|
25 | - { |
|
26 | - /** |
|
27 | - * Updates an entity. |
|
28 | - * |
|
29 | - * @param array $input The input for the mutation |
|
30 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
31 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
32 | - * @return array |
|
33 | - * @throws EE_Error |
|
34 | - * @throws ReflectionException |
|
35 | - */ |
|
36 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
37 | - try { |
|
38 | - /** @var EE_Price $entity */ |
|
39 | - $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
17 | + /** |
|
18 | + * Defines the mutation data modification closure. |
|
19 | + * |
|
20 | + * @param EEM_Price $model |
|
21 | + * @param Price $type |
|
22 | + * @return callable |
|
23 | + */ |
|
24 | + public static function mutateAndGetPayload(EEM_Price $model, Price $type) |
|
25 | + { |
|
26 | + /** |
|
27 | + * Updates an entity. |
|
28 | + * |
|
29 | + * @param array $input The input for the mutation |
|
30 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
31 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
32 | + * @return array |
|
33 | + * @throws EE_Error |
|
34 | + * @throws ReflectionException |
|
35 | + */ |
|
36 | + return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
37 | + try { |
|
38 | + /** @var EE_Price $entity */ |
|
39 | + $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
40 | 40 | |
41 | - $args = PriceMutation::prepareFields($input); |
|
41 | + $args = PriceMutation::prepareFields($input); |
|
42 | 42 | |
43 | - // Update the entity |
|
44 | - $entity->save($args); |
|
43 | + // Update the entity |
|
44 | + $entity->save($args); |
|
45 | 45 | |
46 | - do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_price_update', $entity, $input); |
|
47 | - } catch (Exception $exception) { |
|
48 | - EntityMutator::handleExceptions( |
|
49 | - $exception, |
|
50 | - esc_html__( |
|
51 | - 'The price could not be updated because of the following error(s)', |
|
52 | - 'event_espresso' |
|
53 | - ) |
|
54 | - ); |
|
55 | - } |
|
46 | + do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_price_update', $entity, $input); |
|
47 | + } catch (Exception $exception) { |
|
48 | + EntityMutator::handleExceptions( |
|
49 | + $exception, |
|
50 | + esc_html__( |
|
51 | + 'The price could not be updated because of the following error(s)', |
|
52 | + 'event_espresso' |
|
53 | + ) |
|
54 | + ); |
|
55 | + } |
|
56 | 56 | |
57 | - return [ |
|
58 | - 'id' => $entity->ID(), |
|
59 | - ]; |
|
60 | - }; |
|
61 | - } |
|
57 | + return [ |
|
58 | + 'id' => $entity->ID(), |
|
59 | + ]; |
|
60 | + }; |
|
61 | + } |
|
62 | 62 | } |
@@ -14,52 +14,52 @@ |
||
14 | 14 | class FormSectionUpdate extends EntityMutator |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Defines the mutation data modification closure. |
|
19 | - * |
|
20 | - * @param EEM_Form_Section $model |
|
21 | - * @return callable |
|
22 | - */ |
|
23 | - public static function mutateAndGetPayload(EEM_Form_Section $model) |
|
24 | - { |
|
25 | - /** |
|
26 | - * Updates an entity. |
|
27 | - * |
|
28 | - * @param array $input The input for the mutation |
|
29 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
30 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
31 | - * @return array |
|
32 | - * @throws EE_Error |
|
33 | - * @throws ReflectionException |
|
34 | - */ |
|
35 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
36 | - try { |
|
37 | - /** @var EE_Form_Section $entity */ |
|
38 | - $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
17 | + /** |
|
18 | + * Defines the mutation data modification closure. |
|
19 | + * |
|
20 | + * @param EEM_Form_Section $model |
|
21 | + * @return callable |
|
22 | + */ |
|
23 | + public static function mutateAndGetPayload(EEM_Form_Section $model) |
|
24 | + { |
|
25 | + /** |
|
26 | + * Updates an entity. |
|
27 | + * |
|
28 | + * @param array $input The input for the mutation |
|
29 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
30 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
31 | + * @return array |
|
32 | + * @throws EE_Error |
|
33 | + * @throws ReflectionException |
|
34 | + */ |
|
35 | + return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
36 | + try { |
|
37 | + /** @var EE_Form_Section $entity */ |
|
38 | + $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
39 | 39 | |
40 | - $args = FormSectionMutation::prepareFields($input); |
|
40 | + $args = FormSectionMutation::prepareFields($input); |
|
41 | 41 | |
42 | - // Update the entity |
|
43 | - $entity->save($args); |
|
42 | + // Update the entity |
|
43 | + $entity->save($args); |
|
44 | 44 | |
45 | - do_action( |
|
46 | - 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_section_update', |
|
47 | - $entity, |
|
48 | - $input |
|
49 | - ); |
|
50 | - } catch (Exception $exception) { |
|
51 | - EntityMutator::handleExceptions( |
|
52 | - $exception, |
|
53 | - esc_html__( |
|
54 | - 'The form section could not be updated because of the following error(s)', |
|
55 | - 'event_espresso' |
|
56 | - ) |
|
57 | - ); |
|
58 | - } |
|
45 | + do_action( |
|
46 | + 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_section_update', |
|
47 | + $entity, |
|
48 | + $input |
|
49 | + ); |
|
50 | + } catch (Exception $exception) { |
|
51 | + EntityMutator::handleExceptions( |
|
52 | + $exception, |
|
53 | + esc_html__( |
|
54 | + 'The form section could not be updated because of the following error(s)', |
|
55 | + 'event_espresso' |
|
56 | + ) |
|
57 | + ); |
|
58 | + } |
|
59 | 59 | |
60 | - return [ |
|
61 | - 'id' => $entity->UUID(), |
|
62 | - ]; |
|
63 | - }; |
|
64 | - } |
|
60 | + return [ |
|
61 | + 'id' => $entity->UUID(), |
|
62 | + ]; |
|
63 | + }; |
|
64 | + } |
|
65 | 65 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | * @throws EE_Error |
33 | 33 | * @throws ReflectionException |
34 | 34 | */ |
35 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
35 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
36 | 36 | try { |
37 | 37 | /** @var EE_Form_Section $entity */ |
38 | 38 | $entity = EntityMutator::getEntityFromInputData($model, $input); |
@@ -17,91 +17,91 @@ |
||
17 | 17 | class TicketDelete extends EntityMutator |
18 | 18 | { |
19 | 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 (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
38 | - try { |
|
39 | - /** @var EE_Ticket $entity */ |
|
40 | - $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
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 (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
38 | + try { |
|
39 | + /** @var EE_Ticket $entity */ |
|
40 | + $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
41 | 41 | |
42 | - // Delete the entity |
|
43 | - if (! empty($input['deletePermanently'])) { |
|
44 | - $result = TicketDelete::deleteTicketAndRelations($entity); |
|
45 | - } else { |
|
46 | - // trash the ticket |
|
47 | - $result = TicketDelete::trashTicket($entity); |
|
48 | - } |
|
49 | - EntityMutator::validateResults($result); |
|
42 | + // Delete the entity |
|
43 | + if (! empty($input['deletePermanently'])) { |
|
44 | + $result = TicketDelete::deleteTicketAndRelations($entity); |
|
45 | + } else { |
|
46 | + // trash the ticket |
|
47 | + $result = TicketDelete::trashTicket($entity); |
|
48 | + } |
|
49 | + EntityMutator::validateResults($result); |
|
50 | 50 | |
51 | - do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_ticket_delete', $entity, $input); |
|
52 | - } catch (Exception $exception) { |
|
53 | - EntityMutator::handleExceptions( |
|
54 | - $exception, |
|
55 | - esc_html__( |
|
56 | - 'The ticket could not be deleted because of the following error(s)', |
|
57 | - 'event_espresso' |
|
58 | - ) |
|
59 | - ); |
|
60 | - } |
|
51 | + do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_ticket_delete', $entity, $input); |
|
52 | + } catch (Exception $exception) { |
|
53 | + EntityMutator::handleExceptions( |
|
54 | + $exception, |
|
55 | + esc_html__( |
|
56 | + 'The ticket could not be deleted because of the following error(s)', |
|
57 | + 'event_espresso' |
|
58 | + ) |
|
59 | + ); |
|
60 | + } |
|
61 | 61 | |
62 | - return [ |
|
63 | - 'deleted' => $entity, |
|
64 | - ]; |
|
65 | - }; |
|
66 | - } |
|
62 | + return [ |
|
63 | + 'deleted' => $entity, |
|
64 | + ]; |
|
65 | + }; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Deletes a ticket permanently along with its relations. |
|
70 | - * |
|
71 | - * @param EE_Ticket $entity |
|
72 | - * @return bool | int |
|
73 | - * @throws ReflectionException |
|
74 | - * @throws InvalidArgumentException |
|
75 | - * @throws InvalidInterfaceException |
|
76 | - * @throws InvalidDataTypeException |
|
77 | - * @throws EE_Error |
|
78 | - */ |
|
79 | - public static function deleteTicketAndRelations(EE_Ticket $entity) |
|
80 | - { |
|
81 | - // Remove related non-default prices for the ticket |
|
82 | - $entity->delete_related_permanently('Price', [['PRC_is_default' => false]]); |
|
83 | - // The ticket still might have relations with default taxes, lets divorce them |
|
84 | - $entity->_remove_relations('Price'); |
|
85 | - // Remove relation with datetimes |
|
86 | - $entity->_remove_relations('Datetime'); |
|
87 | - // Now delete the ticket permanently |
|
88 | - return $entity->delete_permanently(); |
|
89 | - } |
|
68 | + /** |
|
69 | + * Deletes a ticket permanently along with its relations. |
|
70 | + * |
|
71 | + * @param EE_Ticket $entity |
|
72 | + * @return bool | int |
|
73 | + * @throws ReflectionException |
|
74 | + * @throws InvalidArgumentException |
|
75 | + * @throws InvalidInterfaceException |
|
76 | + * @throws InvalidDataTypeException |
|
77 | + * @throws EE_Error |
|
78 | + */ |
|
79 | + public static function deleteTicketAndRelations(EE_Ticket $entity) |
|
80 | + { |
|
81 | + // Remove related non-default prices for the ticket |
|
82 | + $entity->delete_related_permanently('Price', [['PRC_is_default' => false]]); |
|
83 | + // The ticket still might have relations with default taxes, lets divorce them |
|
84 | + $entity->_remove_relations('Price'); |
|
85 | + // Remove relation with datetimes |
|
86 | + $entity->_remove_relations('Datetime'); |
|
87 | + // Now delete the ticket permanently |
|
88 | + return $entity->delete_permanently(); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Trashes a ticket. |
|
93 | - * |
|
94 | - * @param EE_Ticket $entity |
|
95 | - * @return bool | int |
|
96 | - * @throws ReflectionException |
|
97 | - * @throws InvalidArgumentException |
|
98 | - * @throws InvalidInterfaceException |
|
99 | - * @throws InvalidDataTypeException |
|
100 | - * @throws EE_Error |
|
101 | - */ |
|
102 | - public static function trashTicket(EE_Ticket $entity) |
|
103 | - { |
|
104 | - // trash the ticket |
|
105 | - return $entity->delete(); |
|
106 | - } |
|
91 | + /** |
|
92 | + * Trashes a ticket. |
|
93 | + * |
|
94 | + * @param EE_Ticket $entity |
|
95 | + * @return bool | int |
|
96 | + * @throws ReflectionException |
|
97 | + * @throws InvalidArgumentException |
|
98 | + * @throws InvalidInterfaceException |
|
99 | + * @throws InvalidDataTypeException |
|
100 | + * @throws EE_Error |
|
101 | + */ |
|
102 | + public static function trashTicket(EE_Ticket $entity) |
|
103 | + { |
|
104 | + // trash the ticket |
|
105 | + return $entity->delete(); |
|
106 | + } |
|
107 | 107 | } |
@@ -34,13 +34,13 @@ |
||
34 | 34 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
35 | 35 | * @return array |
36 | 36 | */ |
37 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
37 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
38 | 38 | try { |
39 | 39 | /** @var EE_Ticket $entity */ |
40 | 40 | $entity = EntityMutator::getEntityFromInputData($model, $input); |
41 | 41 | |
42 | 42 | // Delete the entity |
43 | - if (! empty($input['deletePermanently'])) { |
|
43 | + if ( ! empty($input['deletePermanently'])) { |
|
44 | 44 | $result = TicketDelete::deleteTicketAndRelations($entity); |
45 | 45 | } else { |
46 | 46 | // trash the ticket |
@@ -29,7 +29,7 @@ |
||
29 | 29 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
30 | 30 | * @return array |
31 | 31 | */ |
32 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
32 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
33 | 33 | $id = null; |
34 | 34 | try { |
35 | 35 | EntityMutator::checkPermissions($model); |
@@ -11,51 +11,51 @@ |
||
11 | 11 | |
12 | 12 | class FormSectionCreate extends EntityMutator |
13 | 13 | { |
14 | - /** |
|
15 | - * Defines the mutation data modification closure. |
|
16 | - * |
|
17 | - * @param EEM_Form_Section $model |
|
18 | - * @return callable |
|
19 | - */ |
|
20 | - public static function mutateAndGetPayload(EEM_Form_Section $model) |
|
21 | - { |
|
22 | - /** |
|
23 | - * Creates an entity. |
|
24 | - * |
|
25 | - * @param array $input The input for the mutation |
|
26 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
27 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
28 | - * @return array |
|
29 | - */ |
|
30 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
31 | - $id = null; |
|
32 | - try { |
|
33 | - EntityMutator::checkPermissions($model); |
|
14 | + /** |
|
15 | + * Defines the mutation data modification closure. |
|
16 | + * |
|
17 | + * @param EEM_Form_Section $model |
|
18 | + * @return callable |
|
19 | + */ |
|
20 | + public static function mutateAndGetPayload(EEM_Form_Section $model) |
|
21 | + { |
|
22 | + /** |
|
23 | + * Creates an entity. |
|
24 | + * |
|
25 | + * @param array $input The input for the mutation |
|
26 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
27 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
28 | + * @return array |
|
29 | + */ |
|
30 | + return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
31 | + $id = null; |
|
32 | + try { |
|
33 | + EntityMutator::checkPermissions($model); |
|
34 | 34 | |
35 | - $args = FormSectionMutation::prepareFields($input); |
|
35 | + $args = FormSectionMutation::prepareFields($input); |
|
36 | 36 | |
37 | - $entity = EE_Form_Section::new_instance($args); |
|
38 | - $id = $entity->save(); |
|
39 | - EntityMutator::validateResults($id); |
|
37 | + $entity = EE_Form_Section::new_instance($args); |
|
38 | + $id = $entity->save(); |
|
39 | + EntityMutator::validateResults($id); |
|
40 | 40 | |
41 | - do_action( |
|
42 | - 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_section_create', |
|
43 | - $entity, |
|
44 | - $input |
|
45 | - ); |
|
46 | - } catch (Exception $exception) { |
|
47 | - EntityMutator::handleExceptions( |
|
48 | - $exception, |
|
49 | - esc_html__( |
|
50 | - 'The form section could not be created because of the following error(s)', |
|
51 | - 'event_espresso' |
|
52 | - ) |
|
53 | - ); |
|
54 | - } |
|
41 | + do_action( |
|
42 | + 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_section_create', |
|
43 | + $entity, |
|
44 | + $input |
|
45 | + ); |
|
46 | + } catch (Exception $exception) { |
|
47 | + EntityMutator::handleExceptions( |
|
48 | + $exception, |
|
49 | + esc_html__( |
|
50 | + 'The form section could not be created because of the following error(s)', |
|
51 | + 'event_espresso' |
|
52 | + ) |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | |
56 | - return [ |
|
57 | - 'id' => $id, |
|
58 | - ]; |
|
59 | - }; |
|
60 | - } |
|
56 | + return [ |
|
57 | + 'id' => $id, |
|
58 | + ]; |
|
59 | + }; |
|
60 | + } |
|
61 | 61 | } |
@@ -14,55 +14,55 @@ |
||
14 | 14 | class PriceCreate extends EntityMutator |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Defines the mutation data modification closure. |
|
19 | - * |
|
20 | - * @param EEM_Price $model |
|
21 | - * @param Price $type |
|
22 | - * @return callable |
|
23 | - */ |
|
24 | - public static function mutateAndGetPayload(EEM_Price $model, Price $type) |
|
25 | - { |
|
26 | - /** |
|
27 | - * Creates an entity. |
|
28 | - * |
|
29 | - * @param array $input The input for the mutation |
|
30 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
31 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
35 | - $id = null; |
|
36 | - try { |
|
37 | - EntityMutator::checkPermissions($model); |
|
17 | + /** |
|
18 | + * Defines the mutation data modification closure. |
|
19 | + * |
|
20 | + * @param EEM_Price $model |
|
21 | + * @param Price $type |
|
22 | + * @return callable |
|
23 | + */ |
|
24 | + public static function mutateAndGetPayload(EEM_Price $model, Price $type) |
|
25 | + { |
|
26 | + /** |
|
27 | + * Creates an entity. |
|
28 | + * |
|
29 | + * @param array $input The input for the mutation |
|
30 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
31 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
35 | + $id = null; |
|
36 | + try { |
|
37 | + EntityMutator::checkPermissions($model); |
|
38 | 38 | |
39 | - $args = PriceMutation::prepareFields($input); |
|
39 | + $args = PriceMutation::prepareFields($input); |
|
40 | 40 | |
41 | - if (empty($args['PRT_ID'])) { |
|
42 | - // translators: the placeholder is the name of the field. |
|
43 | - throw new UserError( |
|
44 | - sprintf(esc_html__('A valid %1$s must be passed.', 'event_espresso'), 'priceType') |
|
45 | - ); |
|
46 | - } |
|
41 | + if (empty($args['PRT_ID'])) { |
|
42 | + // translators: the placeholder is the name of the field. |
|
43 | + throw new UserError( |
|
44 | + sprintf(esc_html__('A valid %1$s must be passed.', 'event_espresso'), 'priceType') |
|
45 | + ); |
|
46 | + } |
|
47 | 47 | |
48 | - $entity = EE_Price::new_instance($args); |
|
49 | - $id = $entity->save(); |
|
50 | - EntityMutator::validateResults($id); |
|
48 | + $entity = EE_Price::new_instance($args); |
|
49 | + $id = $entity->save(); |
|
50 | + EntityMutator::validateResults($id); |
|
51 | 51 | |
52 | - do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_price_create', $entity, $input); |
|
53 | - } catch (Exception $exception) { |
|
54 | - EntityMutator::handleExceptions( |
|
55 | - $exception, |
|
56 | - esc_html__( |
|
57 | - 'The price could not be created because of the following error(s)', |
|
58 | - 'event_espresso' |
|
59 | - ) |
|
60 | - ); |
|
61 | - } |
|
52 | + do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_price_create', $entity, $input); |
|
53 | + } catch (Exception $exception) { |
|
54 | + EntityMutator::handleExceptions( |
|
55 | + $exception, |
|
56 | + esc_html__( |
|
57 | + 'The price could not be created because of the following error(s)', |
|
58 | + 'event_espresso' |
|
59 | + ) |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | |
63 | - return [ |
|
64 | - 'id' => $id, |
|
65 | - ]; |
|
66 | - }; |
|
67 | - } |
|
63 | + return [ |
|
64 | + 'id' => $id, |
|
65 | + ]; |
|
66 | + }; |
|
67 | + } |
|
68 | 68 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
32 | 32 | * @return array |
33 | 33 | */ |
34 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
34 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
35 | 35 | $id = null; |
36 | 36 | try { |
37 | 37 | EntityMutator::checkPermissions($model); |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | $primaryKey = $model->get_primary_key_field()->get_name(); |
61 | 61 | // e.g. "FSC_UUID" will give us "FSC" |
62 | 62 | [$keyPrefix] = explode('_', $primaryKey); |
63 | - $uuid_field = $keyPrefix . '_UUID'; // e.g. "FSC_UUID" |
|
63 | + $uuid_field = $keyPrefix.'_UUID'; // e.g. "FSC_UUID" |
|
64 | 64 | |
65 | 65 | // If the model has UUID field, then we will use that in place of ID. |
66 | 66 | $ID = $model->has_field($uuid_field) ? $input['id'] : EntityMutator::getEntityIDFromGlobalId($model, $input); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | /** |
79 | 79 | * Stop now if a user isn't allowed to execute mutation |
80 | 80 | */ |
81 | - if (! current_user_can($capability)) { |
|
81 | + if ( ! current_user_can($capability)) { |
|
82 | 82 | $model_name = $model->get_this_model_name(); |
83 | 83 | $message = sprintf( |
84 | 84 | esc_html_x( |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | { |
133 | 133 | $entity = $model->get_one_by_ID($ID); |
134 | 134 | $model_name = $model->get_this_model_name(); |
135 | - $class_name = 'EE_' . $model_name; |
|
135 | + $class_name = 'EE_'.$model_name; |
|
136 | 136 | if ($entity instanceof $class_name) { |
137 | 137 | return $entity; |
138 | 138 | } |
@@ -21,168 +21,168 @@ |
||
21 | 21 | */ |
22 | 22 | abstract class EntityMutator |
23 | 23 | { |
24 | - /** |
|
25 | - * @param EEM_Base $model |
|
26 | - * @param integer $ID |
|
27 | - * @param string $capability |
|
28 | - * @return EE_Base_Class |
|
29 | - * @throws OutOfBoundsException |
|
30 | - * @throws UserError |
|
31 | - * @throws EE_Error |
|
32 | - */ |
|
33 | - protected static function getEntityFromID( |
|
34 | - EEM_Base $model, |
|
35 | - int $ID, |
|
36 | - string $capability = 'ee_edit_events' |
|
37 | - ): EE_Base_Class { |
|
38 | - EntityMutator::checkPermissions($model, $capability); |
|
39 | - return EntityMutator::getEntity($model, $ID); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @param EEM_Base $model |
|
45 | - * @param array $input |
|
46 | - * @param string $capability |
|
47 | - * @return EE_Base_Class |
|
48 | - * @throws OutOfBoundsException |
|
49 | - * @throws UserError |
|
50 | - * @throws EE_Error |
|
51 | - */ |
|
52 | - protected static function getEntityFromInputData( |
|
53 | - EEM_Base $model, |
|
54 | - array $input, |
|
55 | - string $capability = 'ee_edit_events' |
|
56 | - ): EE_Base_Class { |
|
57 | - EntityMutator::checkPermissions($model, $capability); |
|
58 | - |
|
59 | - $primaryKey = $model->get_primary_key_field()->get_name(); |
|
60 | - // e.g. "FSC_UUID" will give us "FSC" |
|
61 | - [$keyPrefix] = explode('_', $primaryKey); |
|
62 | - $uuid_field = $keyPrefix . '_UUID'; // e.g. "FSC_UUID" |
|
63 | - |
|
64 | - // If the model has UUID field, then we will use that in place of ID. |
|
65 | - $ID = $model->has_field($uuid_field) ? $input['id'] : EntityMutator::getEntityIDFromGlobalId($model, $input); |
|
66 | - return EntityMutator::getEntity($model, $ID); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @param EEM_Base $model |
|
72 | - * @param string $capability |
|
73 | - * @throws UserError |
|
74 | - */ |
|
75 | - protected static function checkPermissions(EEM_Base $model, string $capability = 'ee_edit_events') |
|
76 | - { |
|
77 | - /** |
|
78 | - * Stop now if a user isn't allowed to execute mutation |
|
79 | - */ |
|
80 | - if (! current_user_can($capability)) { |
|
81 | - $model_name = $model->get_this_model_name(); |
|
82 | - $message = sprintf( |
|
83 | - esc_html_x( |
|
84 | - 'We\'re sorry but you do not have the required permissions to execute %1$s mutations!', |
|
85 | - 'We\'re sorry but you do not have the required permissions to execute entity(datetime/ticket/etc) mutations!', |
|
86 | - 'event_espresso' |
|
87 | - ), |
|
88 | - strtolower($model_name) |
|
89 | - ); |
|
90 | - throw new UserError($message); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @param EEM_Base $model |
|
97 | - * @param array $input |
|
98 | - * @return int |
|
99 | - * @throws OutOfBoundsException |
|
100 | - */ |
|
101 | - protected static function getEntityIDFromGlobalId(EEM_Base $model, array $input): int |
|
102 | - { |
|
103 | - $id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null; |
|
104 | - $id = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0; |
|
105 | - if ($id > 0) { |
|
106 | - return $id; |
|
107 | - } |
|
108 | - // no ID? throw an exception |
|
109 | - $model_name = $model->get_this_model_name(); |
|
110 | - throw new OutOfBoundsException( |
|
111 | - sprintf( |
|
112 | - esc_html_x( |
|
113 | - 'A missing or invalid %1$s ID was received.', |
|
114 | - 'A missing or invalid entity(datetime/ticket/etc) ID was received.', |
|
115 | - 'event_espresso' |
|
116 | - ), |
|
117 | - strtolower($model_name) |
|
118 | - ) |
|
119 | - ); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @param EEM_Base $model |
|
125 | - * @param int|string $ID |
|
126 | - * @return EE_Base_Class |
|
127 | - * @throws OutOfBoundsException |
|
128 | - * @throws EE_Error |
|
129 | - */ |
|
130 | - protected static function getEntity(EEM_Base $model, $ID = 0): EE_Base_Class |
|
131 | - { |
|
132 | - $entity = $model->get_one_by_ID($ID); |
|
133 | - $model_name = $model->get_this_model_name(); |
|
134 | - $class_name = 'EE_' . $model_name; |
|
135 | - if ($entity instanceof $class_name) { |
|
136 | - return $entity; |
|
137 | - } |
|
138 | - // OOPS!!! invalid entity |
|
139 | - throw new OutOfBoundsException( |
|
140 | - sprintf( |
|
141 | - esc_html_x( |
|
142 | - 'A valid %1$s could not be retrieved from the database.', |
|
143 | - 'A valid entity(datetime/ticket/etc) could not be found in the database.', |
|
144 | - 'event_espresso' |
|
145 | - ), |
|
146 | - strtolower($model_name) |
|
147 | - ) |
|
148 | - ); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @param $results |
|
154 | - * @param string $message |
|
155 | - * @throws RuntimeException |
|
156 | - */ |
|
157 | - protected static function validateResults($results, string $message = '') |
|
158 | - { |
|
159 | - if (empty($results)) { |
|
160 | - $message = $message !== '' |
|
161 | - ? $message |
|
162 | - : esc_html__( |
|
163 | - 'An unknown error occurred. Please check your server\'s error logs for more information', |
|
164 | - 'event_espresso' |
|
165 | - ); |
|
166 | - throw new RuntimeException($message); |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param Exception $exception |
|
173 | - * @param string $message_prefix |
|
174 | - * @throws RuntimeException |
|
175 | - */ |
|
176 | - protected static function handleExceptions(Exception $exception, string $message_prefix = '') |
|
177 | - { |
|
178 | - $message_prefix = $message_prefix !== '' |
|
179 | - ? $message_prefix |
|
180 | - : esc_html__( |
|
181 | - 'The mutation could not be executed because of the following error(s)', |
|
182 | - 'event_espresso' |
|
183 | - ); |
|
184 | - throw new RuntimeException( |
|
185 | - sprintf('%1$s: %2$s', $message_prefix, $exception->getMessage()) |
|
186 | - ); |
|
187 | - } |
|
24 | + /** |
|
25 | + * @param EEM_Base $model |
|
26 | + * @param integer $ID |
|
27 | + * @param string $capability |
|
28 | + * @return EE_Base_Class |
|
29 | + * @throws OutOfBoundsException |
|
30 | + * @throws UserError |
|
31 | + * @throws EE_Error |
|
32 | + */ |
|
33 | + protected static function getEntityFromID( |
|
34 | + EEM_Base $model, |
|
35 | + int $ID, |
|
36 | + string $capability = 'ee_edit_events' |
|
37 | + ): EE_Base_Class { |
|
38 | + EntityMutator::checkPermissions($model, $capability); |
|
39 | + return EntityMutator::getEntity($model, $ID); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @param EEM_Base $model |
|
45 | + * @param array $input |
|
46 | + * @param string $capability |
|
47 | + * @return EE_Base_Class |
|
48 | + * @throws OutOfBoundsException |
|
49 | + * @throws UserError |
|
50 | + * @throws EE_Error |
|
51 | + */ |
|
52 | + protected static function getEntityFromInputData( |
|
53 | + EEM_Base $model, |
|
54 | + array $input, |
|
55 | + string $capability = 'ee_edit_events' |
|
56 | + ): EE_Base_Class { |
|
57 | + EntityMutator::checkPermissions($model, $capability); |
|
58 | + |
|
59 | + $primaryKey = $model->get_primary_key_field()->get_name(); |
|
60 | + // e.g. "FSC_UUID" will give us "FSC" |
|
61 | + [$keyPrefix] = explode('_', $primaryKey); |
|
62 | + $uuid_field = $keyPrefix . '_UUID'; // e.g. "FSC_UUID" |
|
63 | + |
|
64 | + // If the model has UUID field, then we will use that in place of ID. |
|
65 | + $ID = $model->has_field($uuid_field) ? $input['id'] : EntityMutator::getEntityIDFromGlobalId($model, $input); |
|
66 | + return EntityMutator::getEntity($model, $ID); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @param EEM_Base $model |
|
72 | + * @param string $capability |
|
73 | + * @throws UserError |
|
74 | + */ |
|
75 | + protected static function checkPermissions(EEM_Base $model, string $capability = 'ee_edit_events') |
|
76 | + { |
|
77 | + /** |
|
78 | + * Stop now if a user isn't allowed to execute mutation |
|
79 | + */ |
|
80 | + if (! current_user_can($capability)) { |
|
81 | + $model_name = $model->get_this_model_name(); |
|
82 | + $message = sprintf( |
|
83 | + esc_html_x( |
|
84 | + 'We\'re sorry but you do not have the required permissions to execute %1$s mutations!', |
|
85 | + 'We\'re sorry but you do not have the required permissions to execute entity(datetime/ticket/etc) mutations!', |
|
86 | + 'event_espresso' |
|
87 | + ), |
|
88 | + strtolower($model_name) |
|
89 | + ); |
|
90 | + throw new UserError($message); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @param EEM_Base $model |
|
97 | + * @param array $input |
|
98 | + * @return int |
|
99 | + * @throws OutOfBoundsException |
|
100 | + */ |
|
101 | + protected static function getEntityIDFromGlobalId(EEM_Base $model, array $input): int |
|
102 | + { |
|
103 | + $id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null; |
|
104 | + $id = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0; |
|
105 | + if ($id > 0) { |
|
106 | + return $id; |
|
107 | + } |
|
108 | + // no ID? throw an exception |
|
109 | + $model_name = $model->get_this_model_name(); |
|
110 | + throw new OutOfBoundsException( |
|
111 | + sprintf( |
|
112 | + esc_html_x( |
|
113 | + 'A missing or invalid %1$s ID was received.', |
|
114 | + 'A missing or invalid entity(datetime/ticket/etc) ID was received.', |
|
115 | + 'event_espresso' |
|
116 | + ), |
|
117 | + strtolower($model_name) |
|
118 | + ) |
|
119 | + ); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @param EEM_Base $model |
|
125 | + * @param int|string $ID |
|
126 | + * @return EE_Base_Class |
|
127 | + * @throws OutOfBoundsException |
|
128 | + * @throws EE_Error |
|
129 | + */ |
|
130 | + protected static function getEntity(EEM_Base $model, $ID = 0): EE_Base_Class |
|
131 | + { |
|
132 | + $entity = $model->get_one_by_ID($ID); |
|
133 | + $model_name = $model->get_this_model_name(); |
|
134 | + $class_name = 'EE_' . $model_name; |
|
135 | + if ($entity instanceof $class_name) { |
|
136 | + return $entity; |
|
137 | + } |
|
138 | + // OOPS!!! invalid entity |
|
139 | + throw new OutOfBoundsException( |
|
140 | + sprintf( |
|
141 | + esc_html_x( |
|
142 | + 'A valid %1$s could not be retrieved from the database.', |
|
143 | + 'A valid entity(datetime/ticket/etc) could not be found in the database.', |
|
144 | + 'event_espresso' |
|
145 | + ), |
|
146 | + strtolower($model_name) |
|
147 | + ) |
|
148 | + ); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @param $results |
|
154 | + * @param string $message |
|
155 | + * @throws RuntimeException |
|
156 | + */ |
|
157 | + protected static function validateResults($results, string $message = '') |
|
158 | + { |
|
159 | + if (empty($results)) { |
|
160 | + $message = $message !== '' |
|
161 | + ? $message |
|
162 | + : esc_html__( |
|
163 | + 'An unknown error occurred. Please check your server\'s error logs for more information', |
|
164 | + 'event_espresso' |
|
165 | + ); |
|
166 | + throw new RuntimeException($message); |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param Exception $exception |
|
173 | + * @param string $message_prefix |
|
174 | + * @throws RuntimeException |
|
175 | + */ |
|
176 | + protected static function handleExceptions(Exception $exception, string $message_prefix = '') |
|
177 | + { |
|
178 | + $message_prefix = $message_prefix !== '' |
|
179 | + ? $message_prefix |
|
180 | + : esc_html__( |
|
181 | + 'The mutation could not be executed because of the following error(s)', |
|
182 | + 'event_espresso' |
|
183 | + ); |
|
184 | + throw new RuntimeException( |
|
185 | + sprintf('%1$s: %2$s', $message_prefix, $exception->getMessage()) |
|
186 | + ); |
|
187 | + } |
|
188 | 188 | } |