@@ -13,57 +13,57 @@ |
||
| 13 | 13 | class DatetimeUpdate extends EntityMutator |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Defines the mutation data modification closure. |
|
| 18 | - * |
|
| 19 | - * @param EEM_Datetime $model |
|
| 20 | - * @param Datetime $type |
|
| 21 | - * @return callable |
|
| 22 | - */ |
|
| 23 | - public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
|
| 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 | - */ |
|
| 33 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
| 34 | - try { |
|
| 35 | - /** @var EE_Datetime $entity */ |
|
| 36 | - $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
| 16 | + /** |
|
| 17 | + * Defines the mutation data modification closure. |
|
| 18 | + * |
|
| 19 | + * @param EEM_Datetime $model |
|
| 20 | + * @param Datetime $type |
|
| 21 | + * @return callable |
|
| 22 | + */ |
|
| 23 | + public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
|
| 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 | + */ |
|
| 33 | + return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
| 34 | + try { |
|
| 35 | + /** @var EE_Datetime $entity */ |
|
| 36 | + $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
| 37 | 37 | |
| 38 | - $tickets = []; |
|
| 39 | - $args = DatetimeMutation::prepareFields($input); |
|
| 38 | + $tickets = []; |
|
| 39 | + $args = DatetimeMutation::prepareFields($input); |
|
| 40 | 40 | |
| 41 | - if (isset($args['tickets'])) { |
|
| 42 | - $tickets = $args['tickets']; |
|
| 43 | - unset($args['tickets']); |
|
| 44 | - } |
|
| 41 | + if (isset($args['tickets'])) { |
|
| 42 | + $tickets = $args['tickets']; |
|
| 43 | + unset($args['tickets']); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - // Update the entity |
|
| 47 | - $entity->save($args); |
|
| 46 | + // Update the entity |
|
| 47 | + $entity->save($args); |
|
| 48 | 48 | |
| 49 | - if (! empty($tickets)) { |
|
| 50 | - DatetimeMutation::setRelatedTickets($entity, $tickets); |
|
| 51 | - } |
|
| 49 | + if (! empty($tickets)) { |
|
| 50 | + DatetimeMutation::setRelatedTickets($entity, $tickets); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_datetime_update', $entity, $input); |
|
| 54 | - } catch (Exception $exception) { |
|
| 55 | - EntityMutator::handleExceptions( |
|
| 56 | - $exception, |
|
| 57 | - esc_html__( |
|
| 58 | - 'The datetime could not be updated because of the following error(s)', |
|
| 59 | - 'event_espresso' |
|
| 60 | - ) |
|
| 61 | - ); |
|
| 62 | - } |
|
| 53 | + do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_datetime_update', $entity, $input); |
|
| 54 | + } catch (Exception $exception) { |
|
| 55 | + EntityMutator::handleExceptions( |
|
| 56 | + $exception, |
|
| 57 | + esc_html__( |
|
| 58 | + 'The datetime could not be updated because of the following error(s)', |
|
| 59 | + 'event_espresso' |
|
| 60 | + ) |
|
| 61 | + ); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return [ |
|
| 65 | - 'id' => $entity->ID(), |
|
| 66 | - ]; |
|
| 67 | - }; |
|
| 68 | - } |
|
| 64 | + return [ |
|
| 65 | + 'id' => $entity->ID(), |
|
| 66 | + ]; |
|
| 67 | + }; |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
| 31 | 31 | * @return array |
| 32 | 32 | */ |
| 33 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
| 33 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
| 34 | 34 | try { |
| 35 | 35 | /** @var EE_Datetime $entity */ |
| 36 | 36 | $entity = EntityMutator::getEntityFromInputData($model, $input); |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | // Update the entity |
| 47 | 47 | $entity->save($args); |
| 48 | 48 | |
| 49 | - if (! empty($tickets)) { |
|
| 49 | + if ( ! empty($tickets)) { |
|
| 50 | 50 | DatetimeMutation::setRelatedTickets($entity, $tickets); |
| 51 | 51 | } |
| 52 | 52 | |
@@ -10,69 +10,69 @@ |
||
| 10 | 10 | class BulkEntityMutator extends EntityMutator |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @var callable $entity_mutator . |
|
| 15 | - */ |
|
| 16 | - protected $entity_mutator; |
|
| 13 | + /** |
|
| 14 | + * @var callable $entity_mutator . |
|
| 15 | + */ |
|
| 16 | + protected $entity_mutator; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * BulkEntityMutator constructor. |
|
| 20 | - * |
|
| 21 | - * @param callable $entity_mutator The mutator for an entity. |
|
| 22 | - */ |
|
| 23 | - public function __construct(callable $entity_mutator) |
|
| 24 | - { |
|
| 25 | - $this->entity_mutator = $entity_mutator; |
|
| 26 | - } |
|
| 27 | - /** |
|
| 28 | - * Bulk updates entities. |
|
| 29 | - * |
|
| 30 | - * @param array $input The input for the mutation |
|
| 31 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
| 32 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
| 33 | - * @return array |
|
| 34 | - */ |
|
| 35 | - public function updateEntities(array $input, AppContext $context, ResolveInfo $info): array |
|
| 36 | - { |
|
| 18 | + /** |
|
| 19 | + * BulkEntityMutator constructor. |
|
| 20 | + * |
|
| 21 | + * @param callable $entity_mutator The mutator for an entity. |
|
| 22 | + */ |
|
| 23 | + public function __construct(callable $entity_mutator) |
|
| 24 | + { |
|
| 25 | + $this->entity_mutator = $entity_mutator; |
|
| 26 | + } |
|
| 27 | + /** |
|
| 28 | + * Bulk updates entities. |
|
| 29 | + * |
|
| 30 | + * @param array $input The input for the mutation |
|
| 31 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
| 32 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
| 33 | + * @return array |
|
| 34 | + */ |
|
| 35 | + public function updateEntities(array $input, AppContext $context, ResolveInfo $info): array |
|
| 36 | + { |
|
| 37 | 37 | |
| 38 | - $updated = []; |
|
| 39 | - $failed = []; |
|
| 40 | - // TODO Add meaningful error messages for every failure. |
|
| 41 | - // $errors = []; |
|
| 38 | + $updated = []; |
|
| 39 | + $failed = []; |
|
| 40 | + // TODO Add meaningful error messages for every failure. |
|
| 41 | + // $errors = []; |
|
| 42 | 42 | |
| 43 | - try { |
|
| 44 | - if (empty($input['uniqueInputs']) || !is_array($input['uniqueInputs'])) { |
|
| 45 | - throw new OutOfBoundsException( |
|
| 46 | - esc_html__('A valid input was not provided.', 'event_espresso') |
|
| 47 | - ); |
|
| 48 | - } |
|
| 43 | + try { |
|
| 44 | + if (empty($input['uniqueInputs']) || !is_array($input['uniqueInputs'])) { |
|
| 45 | + throw new OutOfBoundsException( |
|
| 46 | + esc_html__('A valid input was not provided.', 'event_espresso') |
|
| 47 | + ); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - $sharedInput = ! empty($input['sharedInput']) ? $input['sharedInput'] : []; |
|
| 50 | + $sharedInput = ! empty($input['sharedInput']) ? $input['sharedInput'] : []; |
|
| 51 | 51 | |
| 52 | - foreach ($input['uniqueInputs'] as $uniqueInput) { |
|
| 53 | - try { |
|
| 54 | - // values in $uniqueInput will override those in $sharedInput |
|
| 55 | - $finalInput = array_merge($sharedInput, $uniqueInput); |
|
| 56 | - // mutate the individual entity. |
|
| 57 | - $mutator = $this->entity_mutator; |
|
| 58 | - $mutator($finalInput, $context, $info); |
|
| 59 | - // we are here it means the update was successful. |
|
| 60 | - $updated[] = $uniqueInput['id']; |
|
| 61 | - } catch (Exception $e) { |
|
| 62 | - // sorry mate, couldn't help you :( |
|
| 63 | - $failed[] = $uniqueInput['id']; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } catch (Exception $exception) { |
|
| 67 | - EntityMutator::handleExceptions( |
|
| 68 | - $exception, |
|
| 69 | - esc_html__( |
|
| 70 | - 'Could not perform the update because of the following error(s)', |
|
| 71 | - 'event_espresso' |
|
| 72 | - ) |
|
| 73 | - ); |
|
| 74 | - } |
|
| 52 | + foreach ($input['uniqueInputs'] as $uniqueInput) { |
|
| 53 | + try { |
|
| 54 | + // values in $uniqueInput will override those in $sharedInput |
|
| 55 | + $finalInput = array_merge($sharedInput, $uniqueInput); |
|
| 56 | + // mutate the individual entity. |
|
| 57 | + $mutator = $this->entity_mutator; |
|
| 58 | + $mutator($finalInput, $context, $info); |
|
| 59 | + // we are here it means the update was successful. |
|
| 60 | + $updated[] = $uniqueInput['id']; |
|
| 61 | + } catch (Exception $e) { |
|
| 62 | + // sorry mate, couldn't help you :( |
|
| 63 | + $failed[] = $uniqueInput['id']; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } catch (Exception $exception) { |
|
| 67 | + EntityMutator::handleExceptions( |
|
| 68 | + $exception, |
|
| 69 | + esc_html__( |
|
| 70 | + 'Could not perform the update because of the following error(s)', |
|
| 71 | + 'event_espresso' |
|
| 72 | + ) |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return compact('updated', 'failed'); |
|
| 77 | - } |
|
| 76 | + return compact('updated', 'failed'); |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -21,155 +21,155 @@ |
||
| 21 | 21 | abstract class EntityMutator |
| 22 | 22 | { |
| 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 | - */ |
|
| 32 | - protected static function getEntityFromID(EEM_Base $model, int $ID, $capability = 'ee_edit_events'): EE_Base_Class |
|
| 33 | - { |
|
| 34 | - EntityMutator::checkPermissions($model, $capability); |
|
| 35 | - return EntityMutator::getEntity($model, $ID); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @param EEM_Base $model |
|
| 41 | - * @param array $input |
|
| 42 | - * @param string $capability |
|
| 43 | - * @return EE_Base_Class |
|
| 44 | - * @throws OutOfBoundsException |
|
| 45 | - * @throws UserError |
|
| 46 | - */ |
|
| 47 | - protected static function getEntityFromInputData( |
|
| 48 | - EEM_Base $model, |
|
| 49 | - array $input, |
|
| 50 | - $capability = 'ee_edit_events' |
|
| 51 | - ): EE_Base_Class { |
|
| 52 | - EntityMutator::checkPermissions($model, $capability); |
|
| 53 | - $ID = EntityMutator::getEntityIDFromGlobalId($model, $input); |
|
| 54 | - return EntityMutator::getEntity($model, $ID); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @param EEM_Base $model |
|
| 60 | - * @param string $capability |
|
| 61 | - * @throws UserError |
|
| 62 | - */ |
|
| 63 | - protected static function checkPermissions(EEM_Base $model, $capability = 'ee_edit_events') |
|
| 64 | - { |
|
| 65 | - /** |
|
| 66 | - * Stop now if a user isn't allowed to execute mutation |
|
| 67 | - */ |
|
| 68 | - if (! current_user_can($capability)) { |
|
| 69 | - $model_name = $model->get_this_model_name(); |
|
| 70 | - $message = sprintf( |
|
| 71 | - esc_html_x( |
|
| 72 | - 'We\'re sorry but you do not have the required permissions to execute %1$s mutations!', |
|
| 73 | - 'We\'re sorry but you do not have the required permissions to execute entity(datetime/ticket/etc) mutations!', |
|
| 74 | - 'event_espresso' |
|
| 75 | - ), |
|
| 76 | - strtolower($model_name) |
|
| 77 | - ); |
|
| 78 | - throw new UserError($message); |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @param EEM_Base $model |
|
| 85 | - * @param array $input |
|
| 86 | - * @return int |
|
| 87 | - * @throws OutOfBoundsException |
|
| 88 | - */ |
|
| 89 | - protected static function getEntityIDFromGlobalId(EEM_Base $model, array $input): int |
|
| 90 | - { |
|
| 91 | - $id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null; |
|
| 92 | - $id = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0; |
|
| 93 | - if ($id > 0) { |
|
| 94 | - return $id; |
|
| 95 | - } |
|
| 96 | - // no ID? throw an exception |
|
| 97 | - $model_name = $model->get_this_model_name(); |
|
| 98 | - throw new OutOfBoundsException( |
|
| 99 | - sprintf( |
|
| 100 | - esc_html_x( |
|
| 101 | - 'A missing or invalid %1$s ID was received.', |
|
| 102 | - 'A missing or invalid entity(datetime/ticket/etc) ID was received.', |
|
| 103 | - 'event_espresso' |
|
| 104 | - ), |
|
| 105 | - strtolower($model_name) |
|
| 106 | - ) |
|
| 107 | - ); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @param EEM_Base $model |
|
| 113 | - * @param int $ID |
|
| 114 | - * @return EE_Base_Class |
|
| 115 | - * @throws OutOfBoundsException |
|
| 116 | - */ |
|
| 117 | - protected static function getEntity(EEM_Base $model, $ID = 0): EE_Base_Class |
|
| 118 | - { |
|
| 119 | - $entity = $model->get_one_by_ID($ID); |
|
| 120 | - $model_name = $model->get_this_model_name(); |
|
| 121 | - $class_name = 'EE_' . $model_name; |
|
| 122 | - if ($entity instanceof $class_name) { |
|
| 123 | - return $entity; |
|
| 124 | - } |
|
| 125 | - // OOPS!!! invalid entity |
|
| 126 | - throw new OutOfBoundsException( |
|
| 127 | - sprintf( |
|
| 128 | - esc_html_x( |
|
| 129 | - 'A valid %1$s could not be retrieved from the database.', |
|
| 130 | - 'A valid entity(datetime/ticket/etc) could not be found in the database.', |
|
| 131 | - 'event_espresso' |
|
| 132 | - ), |
|
| 133 | - strtolower($model_name) |
|
| 134 | - ) |
|
| 135 | - ); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param $results |
|
| 141 | - * @param string $message |
|
| 142 | - * @throws RuntimeException |
|
| 143 | - */ |
|
| 144 | - protected static function validateResults($results, $message = '') |
|
| 145 | - { |
|
| 146 | - if (empty($results)) { |
|
| 147 | - $message = $message !== '' |
|
| 148 | - ? $message |
|
| 149 | - : esc_html__( |
|
| 150 | - 'An unknown error occurred. Please check your server\'s error logs for more information', |
|
| 151 | - 'event_espresso' |
|
| 152 | - ); |
|
| 153 | - throw new RuntimeException($message); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @param Exception $exception |
|
| 160 | - * @param string $message_prefix |
|
| 161 | - * @throws RuntimeException |
|
| 162 | - */ |
|
| 163 | - protected static function handleExceptions(Exception $exception, $message_prefix = '') |
|
| 164 | - { |
|
| 165 | - $message_prefix = $message_prefix !== '' |
|
| 166 | - ? $message_prefix |
|
| 167 | - : esc_html__( |
|
| 168 | - 'The mutation could not be executed because of the following error(s)', |
|
| 169 | - 'event_espresso' |
|
| 170 | - ); |
|
| 171 | - throw new RuntimeException( |
|
| 172 | - sprintf('%1$s: %2$s', $message_prefix, $exception->getMessage()) |
|
| 173 | - ); |
|
| 174 | - } |
|
| 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 | + */ |
|
| 32 | + protected static function getEntityFromID(EEM_Base $model, int $ID, $capability = 'ee_edit_events'): EE_Base_Class |
|
| 33 | + { |
|
| 34 | + EntityMutator::checkPermissions($model, $capability); |
|
| 35 | + return EntityMutator::getEntity($model, $ID); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @param EEM_Base $model |
|
| 41 | + * @param array $input |
|
| 42 | + * @param string $capability |
|
| 43 | + * @return EE_Base_Class |
|
| 44 | + * @throws OutOfBoundsException |
|
| 45 | + * @throws UserError |
|
| 46 | + */ |
|
| 47 | + protected static function getEntityFromInputData( |
|
| 48 | + EEM_Base $model, |
|
| 49 | + array $input, |
|
| 50 | + $capability = 'ee_edit_events' |
|
| 51 | + ): EE_Base_Class { |
|
| 52 | + EntityMutator::checkPermissions($model, $capability); |
|
| 53 | + $ID = EntityMutator::getEntityIDFromGlobalId($model, $input); |
|
| 54 | + return EntityMutator::getEntity($model, $ID); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @param EEM_Base $model |
|
| 60 | + * @param string $capability |
|
| 61 | + * @throws UserError |
|
| 62 | + */ |
|
| 63 | + protected static function checkPermissions(EEM_Base $model, $capability = 'ee_edit_events') |
|
| 64 | + { |
|
| 65 | + /** |
|
| 66 | + * Stop now if a user isn't allowed to execute mutation |
|
| 67 | + */ |
|
| 68 | + if (! current_user_can($capability)) { |
|
| 69 | + $model_name = $model->get_this_model_name(); |
|
| 70 | + $message = sprintf( |
|
| 71 | + esc_html_x( |
|
| 72 | + 'We\'re sorry but you do not have the required permissions to execute %1$s mutations!', |
|
| 73 | + 'We\'re sorry but you do not have the required permissions to execute entity(datetime/ticket/etc) mutations!', |
|
| 74 | + 'event_espresso' |
|
| 75 | + ), |
|
| 76 | + strtolower($model_name) |
|
| 77 | + ); |
|
| 78 | + throw new UserError($message); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @param EEM_Base $model |
|
| 85 | + * @param array $input |
|
| 86 | + * @return int |
|
| 87 | + * @throws OutOfBoundsException |
|
| 88 | + */ |
|
| 89 | + protected static function getEntityIDFromGlobalId(EEM_Base $model, array $input): int |
|
| 90 | + { |
|
| 91 | + $id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null; |
|
| 92 | + $id = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0; |
|
| 93 | + if ($id > 0) { |
|
| 94 | + return $id; |
|
| 95 | + } |
|
| 96 | + // no ID? throw an exception |
|
| 97 | + $model_name = $model->get_this_model_name(); |
|
| 98 | + throw new OutOfBoundsException( |
|
| 99 | + sprintf( |
|
| 100 | + esc_html_x( |
|
| 101 | + 'A missing or invalid %1$s ID was received.', |
|
| 102 | + 'A missing or invalid entity(datetime/ticket/etc) ID was received.', |
|
| 103 | + 'event_espresso' |
|
| 104 | + ), |
|
| 105 | + strtolower($model_name) |
|
| 106 | + ) |
|
| 107 | + ); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @param EEM_Base $model |
|
| 113 | + * @param int $ID |
|
| 114 | + * @return EE_Base_Class |
|
| 115 | + * @throws OutOfBoundsException |
|
| 116 | + */ |
|
| 117 | + protected static function getEntity(EEM_Base $model, $ID = 0): EE_Base_Class |
|
| 118 | + { |
|
| 119 | + $entity = $model->get_one_by_ID($ID); |
|
| 120 | + $model_name = $model->get_this_model_name(); |
|
| 121 | + $class_name = 'EE_' . $model_name; |
|
| 122 | + if ($entity instanceof $class_name) { |
|
| 123 | + return $entity; |
|
| 124 | + } |
|
| 125 | + // OOPS!!! invalid entity |
|
| 126 | + throw new OutOfBoundsException( |
|
| 127 | + sprintf( |
|
| 128 | + esc_html_x( |
|
| 129 | + 'A valid %1$s could not be retrieved from the database.', |
|
| 130 | + 'A valid entity(datetime/ticket/etc) could not be found in the database.', |
|
| 131 | + 'event_espresso' |
|
| 132 | + ), |
|
| 133 | + strtolower($model_name) |
|
| 134 | + ) |
|
| 135 | + ); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param $results |
|
| 141 | + * @param string $message |
|
| 142 | + * @throws RuntimeException |
|
| 143 | + */ |
|
| 144 | + protected static function validateResults($results, $message = '') |
|
| 145 | + { |
|
| 146 | + if (empty($results)) { |
|
| 147 | + $message = $message !== '' |
|
| 148 | + ? $message |
|
| 149 | + : esc_html__( |
|
| 150 | + 'An unknown error occurred. Please check your server\'s error logs for more information', |
|
| 151 | + 'event_espresso' |
|
| 152 | + ); |
|
| 153 | + throw new RuntimeException($message); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @param Exception $exception |
|
| 160 | + * @param string $message_prefix |
|
| 161 | + * @throws RuntimeException |
|
| 162 | + */ |
|
| 163 | + protected static function handleExceptions(Exception $exception, $message_prefix = '') |
|
| 164 | + { |
|
| 165 | + $message_prefix = $message_prefix !== '' |
|
| 166 | + ? $message_prefix |
|
| 167 | + : esc_html__( |
|
| 168 | + 'The mutation could not be executed because of the following error(s)', |
|
| 169 | + 'event_espresso' |
|
| 170 | + ); |
|
| 171 | + throw new RuntimeException( |
|
| 172 | + sprintf('%1$s: %2$s', $message_prefix, $exception->getMessage()) |
|
| 173 | + ); |
|
| 174 | + } |
|
| 175 | 175 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | /** |
| 66 | 66 | * Stop now if a user isn't allowed to execute mutation |
| 67 | 67 | */ |
| 68 | - if (! current_user_can($capability)) { |
|
| 68 | + if ( ! current_user_can($capability)) { |
|
| 69 | 69 | $model_name = $model->get_this_model_name(); |
| 70 | 70 | $message = sprintf( |
| 71 | 71 | esc_html_x( |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | { |
| 119 | 119 | $entity = $model->get_one_by_ID($ID); |
| 120 | 120 | $model_name = $model->get_this_model_name(); |
| 121 | - $class_name = 'EE_' . $model_name; |
|
| 121 | + $class_name = 'EE_'.$model_name; |
|
| 122 | 122 | if ($entity instanceof $class_name) { |
| 123 | 123 | return $entity; |
| 124 | 124 | } |
@@ -15,35 +15,35 @@ |
||
| 15 | 15 | class AttendeesConnectionOrderbyEnum extends EnumBase |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * AttendeesConnectionOrderbyEnum constructor. |
|
| 20 | - */ |
|
| 21 | - public function __construct() |
|
| 22 | - { |
|
| 23 | - $this->setName($this->namespace . 'AttendeesConnectionOrderbyEnum'); |
|
| 24 | - $this->setDescription(esc_html__('Field to order the connection by', 'event_espresso')); |
|
| 25 | - parent::__construct(); |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * AttendeesConnectionOrderbyEnum constructor. |
|
| 20 | + */ |
|
| 21 | + public function __construct() |
|
| 22 | + { |
|
| 23 | + $this->setName($this->namespace . 'AttendeesConnectionOrderbyEnum'); |
|
| 24 | + $this->setDescription(esc_html__('Field to order the connection by', 'event_espresso')); |
|
| 25 | + parent::__construct(); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @return array |
|
| 31 | - */ |
|
| 32 | - protected function getValues(): array |
|
| 33 | - { |
|
| 34 | - return [ |
|
| 35 | - 'ID' => [ |
|
| 36 | - 'value' => 'ATT_ID', |
|
| 37 | - 'description' => esc_html__('Order by ID', 'event_espresso'), |
|
| 38 | - ], |
|
| 39 | - 'LAST_NAME' => [ |
|
| 40 | - 'value' => 'ATT_lname', |
|
| 41 | - 'description' => esc_html__('Order by last name', 'event_espresso'), |
|
| 42 | - ], |
|
| 43 | - 'FIRST_NAME' => [ |
|
| 44 | - 'value' => 'ATT_fname', |
|
| 45 | - 'description' => esc_html__('Order by first name', 'event_espresso'), |
|
| 46 | - ], |
|
| 47 | - ]; |
|
| 48 | - } |
|
| 29 | + /** |
|
| 30 | + * @return array |
|
| 31 | + */ |
|
| 32 | + protected function getValues(): array |
|
| 33 | + { |
|
| 34 | + return [ |
|
| 35 | + 'ID' => [ |
|
| 36 | + 'value' => 'ATT_ID', |
|
| 37 | + 'description' => esc_html__('Order by ID', 'event_espresso'), |
|
| 38 | + ], |
|
| 39 | + 'LAST_NAME' => [ |
|
| 40 | + 'value' => 'ATT_lname', |
|
| 41 | + 'description' => esc_html__('Order by last name', 'event_espresso'), |
|
| 42 | + ], |
|
| 43 | + 'FIRST_NAME' => [ |
|
| 44 | + 'value' => 'ATT_fname', |
|
| 45 | + 'description' => esc_html__('Order by first name', 'event_espresso'), |
|
| 46 | + ], |
|
| 47 | + ]; |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -15,31 +15,31 @@ |
||
| 15 | 15 | class DatetimesConnectionOrderbyEnum extends EnumBase |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * DatetimesConnectionOrderbyEnum constructor. |
|
| 20 | - */ |
|
| 21 | - public function __construct() |
|
| 22 | - { |
|
| 23 | - $this->setName($this->namespace . 'DatetimesConnectionOrderbyEnum'); |
|
| 24 | - $this->setDescription(esc_html__('Field to order the connection by', 'event_espresso')); |
|
| 25 | - parent::__construct(); |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * DatetimesConnectionOrderbyEnum constructor. |
|
| 20 | + */ |
|
| 21 | + public function __construct() |
|
| 22 | + { |
|
| 23 | + $this->setName($this->namespace . 'DatetimesConnectionOrderbyEnum'); |
|
| 24 | + $this->setDescription(esc_html__('Field to order the connection by', 'event_espresso')); |
|
| 25 | + parent::__construct(); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @return array |
|
| 31 | - */ |
|
| 32 | - protected function getValues(): array |
|
| 33 | - { |
|
| 34 | - return [ |
|
| 35 | - 'NAME' => [ |
|
| 36 | - 'value' => 'DTT_name', |
|
| 37 | - 'description' => esc_html__('Order by name', 'event_espresso'), |
|
| 38 | - ], |
|
| 39 | - 'START_DATE' => [ |
|
| 40 | - 'value' => 'DTT_EVT_start', |
|
| 41 | - 'description' => esc_html__('Order by start date', 'event_espresso'), |
|
| 42 | - ], |
|
| 43 | - ]; |
|
| 44 | - } |
|
| 29 | + /** |
|
| 30 | + * @return array |
|
| 31 | + */ |
|
| 32 | + protected function getValues(): array |
|
| 33 | + { |
|
| 34 | + return [ |
|
| 35 | + 'NAME' => [ |
|
| 36 | + 'value' => 'DTT_name', |
|
| 37 | + 'description' => esc_html__('Order by name', 'event_espresso'), |
|
| 38 | + ], |
|
| 39 | + 'START_DATE' => [ |
|
| 40 | + 'value' => 'DTT_EVT_start', |
|
| 41 | + 'description' => esc_html__('Order by start date', 'event_espresso'), |
|
| 42 | + ], |
|
| 43 | + ]; |
|
| 44 | + } |
|
| 45 | 45 | } |
@@ -19,33 +19,33 @@ |
||
| 19 | 19 | class ModelNameEnum extends EnumBase |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * ModelNameEnum constructor. |
|
| 24 | - */ |
|
| 25 | - public function __construct() |
|
| 26 | - { |
|
| 27 | - $this->setName($this->namespace . 'ModelNameEnum'); |
|
| 28 | - $this->setDescription(esc_html__('Entity model name', 'event_espresso')); |
|
| 29 | - parent::__construct(); |
|
| 30 | - } |
|
| 22 | + /** |
|
| 23 | + * ModelNameEnum constructor. |
|
| 24 | + */ |
|
| 25 | + public function __construct() |
|
| 26 | + { |
|
| 27 | + $this->setName($this->namespace . 'ModelNameEnum'); |
|
| 28 | + $this->setDescription(esc_html__('Entity model name', 'event_espresso')); |
|
| 29 | + parent::__construct(); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @return array |
|
| 35 | - * @throws EE_Error |
|
| 36 | - */ |
|
| 37 | - protected function getValues(): array |
|
| 38 | - { |
|
| 39 | - return [ |
|
| 40 | - 'DATETIME' => [ |
|
| 41 | - 'value' => EEM_Datetime::instance()->item_name(), |
|
| 42 | - ], |
|
| 43 | - 'TICKET' => [ |
|
| 44 | - 'value' => EEM_Ticket::instance()->item_name(), |
|
| 45 | - ], |
|
| 46 | - 'PRICE' => [ |
|
| 47 | - 'value' => EEM_Price::instance()->item_name(), |
|
| 48 | - ], |
|
| 49 | - ]; |
|
| 50 | - } |
|
| 33 | + /** |
|
| 34 | + * @return array |
|
| 35 | + * @throws EE_Error |
|
| 36 | + */ |
|
| 37 | + protected function getValues(): array |
|
| 38 | + { |
|
| 39 | + return [ |
|
| 40 | + 'DATETIME' => [ |
|
| 41 | + 'value' => EEM_Datetime::instance()->item_name(), |
|
| 42 | + ], |
|
| 43 | + 'TICKET' => [ |
|
| 44 | + 'value' => EEM_Ticket::instance()->item_name(), |
|
| 45 | + ], |
|
| 46 | + 'PRICE' => [ |
|
| 47 | + 'value' => EEM_Price::instance()->item_name(), |
|
| 48 | + ], |
|
| 49 | + ]; |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -16,44 +16,44 @@ |
||
| 16 | 16 | class DatetimeStatusEnum extends EnumBase |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * DatetimeStatusEnum constructor. |
|
| 21 | - */ |
|
| 22 | - public function __construct() |
|
| 23 | - { |
|
| 24 | - $this->setName($this->namespace . 'DatetimeStatusEnum'); |
|
| 25 | - $this->setDescription(esc_html__('Datetime status', 'event_espresso')); |
|
| 26 | - parent::__construct(); |
|
| 27 | - } |
|
| 19 | + /** |
|
| 20 | + * DatetimeStatusEnum constructor. |
|
| 21 | + */ |
|
| 22 | + public function __construct() |
|
| 23 | + { |
|
| 24 | + $this->setName($this->namespace . 'DatetimeStatusEnum'); |
|
| 25 | + $this->setDescription(esc_html__('Datetime status', 'event_espresso')); |
|
| 26 | + parent::__construct(); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @return array |
|
| 32 | - */ |
|
| 33 | - protected function getValues(): array |
|
| 34 | - { |
|
| 35 | - return [ |
|
| 36 | - 'SOLD_OUT' => [ |
|
| 37 | - 'value' => EE_Datetime::sold_out, |
|
| 38 | - ], |
|
| 39 | - 'ACTIVE' => [ |
|
| 40 | - 'value' => EE_Datetime::active, |
|
| 41 | - ], |
|
| 42 | - 'UPCOMING' => [ |
|
| 43 | - 'value' => EE_Datetime::upcoming, |
|
| 44 | - ], |
|
| 45 | - 'POSTPONED' => [ |
|
| 46 | - 'value' => EE_Datetime::postponed, |
|
| 47 | - ], |
|
| 48 | - 'CANCELLED' => [ |
|
| 49 | - 'value' => EE_Datetime::cancelled, |
|
| 50 | - ], |
|
| 51 | - 'EXPIRED' => [ |
|
| 52 | - 'value' => EE_Datetime::expired, |
|
| 53 | - ], |
|
| 54 | - 'INACTIVE' => [ |
|
| 55 | - 'value' => EE_Datetime::inactive, |
|
| 56 | - ], |
|
| 57 | - ]; |
|
| 58 | - } |
|
| 30 | + /** |
|
| 31 | + * @return array |
|
| 32 | + */ |
|
| 33 | + protected function getValues(): array |
|
| 34 | + { |
|
| 35 | + return [ |
|
| 36 | + 'SOLD_OUT' => [ |
|
| 37 | + 'value' => EE_Datetime::sold_out, |
|
| 38 | + ], |
|
| 39 | + 'ACTIVE' => [ |
|
| 40 | + 'value' => EE_Datetime::active, |
|
| 41 | + ], |
|
| 42 | + 'UPCOMING' => [ |
|
| 43 | + 'value' => EE_Datetime::upcoming, |
|
| 44 | + ], |
|
| 45 | + 'POSTPONED' => [ |
|
| 46 | + 'value' => EE_Datetime::postponed, |
|
| 47 | + ], |
|
| 48 | + 'CANCELLED' => [ |
|
| 49 | + 'value' => EE_Datetime::cancelled, |
|
| 50 | + ], |
|
| 51 | + 'EXPIRED' => [ |
|
| 52 | + 'value' => EE_Datetime::expired, |
|
| 53 | + ], |
|
| 54 | + 'INACTIVE' => [ |
|
| 55 | + 'value' => EE_Datetime::inactive, |
|
| 56 | + ], |
|
| 57 | + ]; |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -16,44 +16,44 @@ |
||
| 16 | 16 | class RegistrationStatusEnum extends EnumBase |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * RegistrationStatusEnum constructor. |
|
| 21 | - */ |
|
| 22 | - public function __construct() |
|
| 23 | - { |
|
| 24 | - $this->setName($this->namespace . 'RegistrationStatusEnum'); |
|
| 25 | - $this->setDescription(esc_html__('Registration status', 'event_espresso')); |
|
| 26 | - parent::__construct(); |
|
| 27 | - } |
|
| 19 | + /** |
|
| 20 | + * RegistrationStatusEnum constructor. |
|
| 21 | + */ |
|
| 22 | + public function __construct() |
|
| 23 | + { |
|
| 24 | + $this->setName($this->namespace . 'RegistrationStatusEnum'); |
|
| 25 | + $this->setDescription(esc_html__('Registration status', 'event_espresso')); |
|
| 26 | + parent::__construct(); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @return array |
|
| 32 | - */ |
|
| 33 | - protected function getValues(): array |
|
| 34 | - { |
|
| 35 | - return [ |
|
| 36 | - 'APPROVED' => [ |
|
| 37 | - 'value' => EEM_Registration::status_id_approved, |
|
| 38 | - ], |
|
| 39 | - 'CANCELLED' => [ |
|
| 40 | - 'value' => EEM_Registration::status_id_cancelled, |
|
| 41 | - ], |
|
| 42 | - 'DECLINED' => [ |
|
| 43 | - 'value' => EEM_Registration::status_id_declined, |
|
| 44 | - ], |
|
| 45 | - 'INCOMPLETE' => [ |
|
| 46 | - 'value' => EEM_Registration::status_id_incomplete, |
|
| 47 | - ], |
|
| 48 | - 'PENDING_PAYMENT' => [ |
|
| 49 | - 'value' => EEM_Registration::status_id_pending_payment, |
|
| 50 | - ], |
|
| 51 | - 'UNAPPROVED' => [ |
|
| 52 | - 'value' => EEM_Registration::status_id_not_approved, |
|
| 53 | - ], |
|
| 54 | - 'WAIT_LIST' => [ |
|
| 55 | - 'value' => EEM_Registration::status_id_wait_list, |
|
| 56 | - ], |
|
| 57 | - ]; |
|
| 58 | - } |
|
| 30 | + /** |
|
| 31 | + * @return array |
|
| 32 | + */ |
|
| 33 | + protected function getValues(): array |
|
| 34 | + { |
|
| 35 | + return [ |
|
| 36 | + 'APPROVED' => [ |
|
| 37 | + 'value' => EEM_Registration::status_id_approved, |
|
| 38 | + ], |
|
| 39 | + 'CANCELLED' => [ |
|
| 40 | + 'value' => EEM_Registration::status_id_cancelled, |
|
| 41 | + ], |
|
| 42 | + 'DECLINED' => [ |
|
| 43 | + 'value' => EEM_Registration::status_id_declined, |
|
| 44 | + ], |
|
| 45 | + 'INCOMPLETE' => [ |
|
| 46 | + 'value' => EEM_Registration::status_id_incomplete, |
|
| 47 | + ], |
|
| 48 | + 'PENDING_PAYMENT' => [ |
|
| 49 | + 'value' => EEM_Registration::status_id_pending_payment, |
|
| 50 | + ], |
|
| 51 | + 'UNAPPROVED' => [ |
|
| 52 | + 'value' => EEM_Registration::status_id_not_approved, |
|
| 53 | + ], |
|
| 54 | + 'WAIT_LIST' => [ |
|
| 55 | + 'value' => EEM_Registration::status_id_wait_list, |
|
| 56 | + ], |
|
| 57 | + ]; |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -15,31 +15,31 @@ |
||
| 15 | 15 | class TicketsConnectionOrderbyEnum extends EnumBase |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * TicketsConnectionOrderbyEnum constructor. |
|
| 20 | - */ |
|
| 21 | - public function __construct() |
|
| 22 | - { |
|
| 23 | - $this->setName($this->namespace . 'TicketsConnectionOrderbyEnum'); |
|
| 24 | - $this->setDescription(esc_html__('Field to order the connection by', 'event_espresso')); |
|
| 25 | - parent::__construct(); |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * TicketsConnectionOrderbyEnum constructor. |
|
| 20 | + */ |
|
| 21 | + public function __construct() |
|
| 22 | + { |
|
| 23 | + $this->setName($this->namespace . 'TicketsConnectionOrderbyEnum'); |
|
| 24 | + $this->setDescription(esc_html__('Field to order the connection by', 'event_espresso')); |
|
| 25 | + parent::__construct(); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @return array |
|
| 31 | - */ |
|
| 32 | - protected function getValues(): array |
|
| 33 | - { |
|
| 34 | - return [ |
|
| 35 | - 'NAME' => [ |
|
| 36 | - 'value' => 'TKT_name', |
|
| 37 | - 'description' => esc_html__('Order by name', 'event_espresso'), |
|
| 38 | - ], |
|
| 39 | - 'START_DATE' => [ |
|
| 40 | - 'value' => 'TKT_start_date', |
|
| 41 | - 'description' => esc_html__('Order by start date', 'event_espresso'), |
|
| 42 | - ], |
|
| 43 | - ]; |
|
| 44 | - } |
|
| 29 | + /** |
|
| 30 | + * @return array |
|
| 31 | + */ |
|
| 32 | + protected function getValues(): array |
|
| 33 | + { |
|
| 34 | + return [ |
|
| 35 | + 'NAME' => [ |
|
| 36 | + 'value' => 'TKT_name', |
|
| 37 | + 'description' => esc_html__('Order by name', 'event_espresso'), |
|
| 38 | + ], |
|
| 39 | + 'START_DATE' => [ |
|
| 40 | + 'value' => 'TKT_start_date', |
|
| 41 | + 'description' => esc_html__('Order by start date', 'event_espresso'), |
|
| 42 | + ], |
|
| 43 | + ]; |
|
| 44 | + } |
|
| 45 | 45 | } |