Completed
Branch EDTR/master (632803)
by
unknown
17:09 queued 08:45
created
core/domain/services/graphql/mutators/BulkEntityDelete.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,6 @@
 block discarded – undo
10 10
 use ReflectionException;
11 11
 use EventEspresso\core\exceptions\InvalidDataTypeException;
12 12
 use EventEspresso\core\exceptions\InvalidInterfaceException;
13
-
14 13
 use GraphQL\Type\Definition\ResolveInfo;
15 14
 use WPGraphQL\AppContext;
16 15
 use GraphQL\Error\UserError;
Please login to merge, or discard this patch.
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -17,74 +17,74 @@
 block discarded – undo
17 17
 
18 18
 class BulkEntityDelete extends EntityMutator
19 19
 {
20
-    /**
21
-     * Defines the mutation data modification closure.
22
-     *
23
-     * @return callable
24
-     */
25
-    public static function mutateAndGetPayload()
26
-    {
27
-        /**
28
-         * Updates an entity.
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
-         * @throws UserError
35
-         * @throws ReflectionException
36
-         * @throws InvalidArgumentException
37
-         * @throws InvalidInterfaceException
38
-         * @throws InvalidDataTypeException
39
-         * @throws EE_Error
40
-         */
41
-        return static function ($input, AppContext $context, ResolveInfo $info) {
42
-            /**
43
-             * Stop now if a user isn't allowed to delete.
44
-             */
45
-            if (! current_user_can('ee_delete_events')) {
46
-                throw new UserError(
47
-                    esc_html__('Sorry, you do not have the required permissions to delete entities', 'event_espresso')
48
-                );
49
-            }
20
+	/**
21
+	 * Defines the mutation data modification closure.
22
+	 *
23
+	 * @return callable
24
+	 */
25
+	public static function mutateAndGetPayload()
26
+	{
27
+		/**
28
+		 * Updates an entity.
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
+		 * @throws UserError
35
+		 * @throws ReflectionException
36
+		 * @throws InvalidArgumentException
37
+		 * @throws InvalidInterfaceException
38
+		 * @throws InvalidDataTypeException
39
+		 * @throws EE_Error
40
+		 */
41
+		return static function ($input, AppContext $context, ResolveInfo $info) {
42
+			/**
43
+			 * Stop now if a user isn't allowed to delete.
44
+			 */
45
+			if (! current_user_can('ee_delete_events')) {
46
+				throw new UserError(
47
+					esc_html__('Sorry, you do not have the required permissions to delete entities', 'event_espresso')
48
+				);
49
+			}
50 50
 
51
-            $details = EntityReorder::prepareEntityDetailsFromInput($input);
51
+			$details = EntityReorder::prepareEntityDetailsFromInput($input);
52 52
 
53
-            $deletePermanently = ! empty($input['deletePermanently']);
53
+			$deletePermanently = ! empty($input['deletePermanently']);
54 54
 
55
-            $deletionMethod = __NAMESPACE__;
56
-            // if it's for datetimes.
57
-            if ($details['entityType'] === EEM_Datetime::instance()->item_name()) {
58
-                $deletionMethod .= '\DatetimeDelete::' . ($deletePermanently ? 'deleteDatetimeAndRelations' : 'trashDatetimeAndRelations');
59
-            } elseif ($details['entityType'] === EEM_Ticket::instance()->item_name()) {
60
-                $deletionMethod .= '\TicketDelete::' . ($deletePermanently ? 'deleteTicketAndRelations' : 'trashTicket');
61
-            } else {
62
-                throw new UserError(
63
-                    esc_html__(
64
-                        'A valid data model could not be obtained. Did you supply a valid entity type?',
65
-                        'event_espresso'
66
-                    )
67
-                );
68
-            }
55
+			$deletionMethod = __NAMESPACE__;
56
+			// if it's for datetimes.
57
+			if ($details['entityType'] === EEM_Datetime::instance()->item_name()) {
58
+				$deletionMethod .= '\DatetimeDelete::' . ($deletePermanently ? 'deleteDatetimeAndRelations' : 'trashDatetimeAndRelations');
59
+			} elseif ($details['entityType'] === EEM_Ticket::instance()->item_name()) {
60
+				$deletionMethod .= '\TicketDelete::' . ($deletePermanently ? 'deleteTicketAndRelations' : 'trashTicket');
61
+			} else {
62
+				throw new UserError(
63
+					esc_html__(
64
+						'A valid data model could not be obtained. Did you supply a valid entity type?',
65
+						'event_espresso'
66
+					)
67
+				);
68
+			}
69 69
 
70
-            $deleted = [];
71
-            $failed  = [];
70
+			$deleted = [];
71
+			$failed  = [];
72 72
 
73
-            foreach ($details['entityDbids'] as $key => $entityDbid) {
74
-                $guid = $details['entityGuids'][ $key ];
75
-                $entity = $details['entities'][ $entityDbid ];
76
-                try {
77
-                    $result = $deletionMethod($entity);
78
-                    EntityMutator::validateResults($result);
79
-                    // we are here it means the deletion was successful.
80
-                    $deleted[] = $guid;
81
-                } catch (Exception $e) {
82
-                    // sorry mate, couldn't help you :(
83
-                    $failed[] = $guid;
84
-                }
85
-            }
73
+			foreach ($details['entityDbids'] as $key => $entityDbid) {
74
+				$guid = $details['entityGuids'][ $key ];
75
+				$entity = $details['entities'][ $entityDbid ];
76
+				try {
77
+					$result = $deletionMethod($entity);
78
+					EntityMutator::validateResults($result);
79
+					// we are here it means the deletion was successful.
80
+					$deleted[] = $guid;
81
+				} catch (Exception $e) {
82
+					// sorry mate, couldn't help you :(
83
+					$failed[] = $guid;
84
+				}
85
+			}
86 86
 
87
-            return compact('deleted', 'failed');
88
-        };
89
-    }
87
+			return compact('deleted', 'failed');
88
+		};
89
+	}
90 90
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -38,11 +38,11 @@  discard block
 block discarded – undo
38 38
          * @throws InvalidDataTypeException
39 39
          * @throws EE_Error
40 40
          */
41
-        return static function ($input, AppContext $context, ResolveInfo $info) {
41
+        return static function($input, AppContext $context, ResolveInfo $info) {
42 42
             /**
43 43
              * Stop now if a user isn't allowed to delete.
44 44
              */
45
-            if (! current_user_can('ee_delete_events')) {
45
+            if ( ! current_user_can('ee_delete_events')) {
46 46
                 throw new UserError(
47 47
                     esc_html__('Sorry, you do not have the required permissions to delete entities', 'event_espresso')
48 48
                 );
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
             $deletionMethod = __NAMESPACE__;
56 56
             // if it's for datetimes.
57 57
             if ($details['entityType'] === EEM_Datetime::instance()->item_name()) {
58
-                $deletionMethod .= '\DatetimeDelete::' . ($deletePermanently ? 'deleteDatetimeAndRelations' : 'trashDatetimeAndRelations');
58
+                $deletionMethod .= '\DatetimeDelete::'.($deletePermanently ? 'deleteDatetimeAndRelations' : 'trashDatetimeAndRelations');
59 59
             } elseif ($details['entityType'] === EEM_Ticket::instance()->item_name()) {
60
-                $deletionMethod .= '\TicketDelete::' . ($deletePermanently ? 'deleteTicketAndRelations' : 'trashTicket');
60
+                $deletionMethod .= '\TicketDelete::'.($deletePermanently ? 'deleteTicketAndRelations' : 'trashTicket');
61 61
             } else {
62 62
                 throw new UserError(
63 63
                     esc_html__(
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
             $failed  = [];
72 72
 
73 73
             foreach ($details['entityDbids'] as $key => $entityDbid) {
74
-                $guid = $details['entityGuids'][ $key ];
75
-                $entity = $details['entities'][ $entityDbid ];
74
+                $guid = $details['entityGuids'][$key];
75
+                $entity = $details['entities'][$entityDbid];
76 76
                 try {
77 77
                     $result = $deletionMethod($entity);
78 78
                     EntityMutator::validateResults($result);
Please login to merge, or discard this patch.
core/domain/services/graphql/mutators/TicketDelete.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -17,89 +17,89 @@
 block discarded – undo
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 ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
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 ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
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);
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
-            }
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
+			} 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 59
 
60
-            return [
61
-                'deleted' => $entity,
62
-            ];
63
-        };
64
-    }
60
+			return [
61
+				'deleted' => $entity,
62
+			];
63
+		};
64
+	}
65 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();
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 85
 
86
-        return $result;
87
-    }
86
+		return $result;
87
+	}
88 88
 
89
-    /**
90
-     * Trashes a ticket.
91
-     *
92
-     * @param EE_Ticket $entity
93
-     * @return bool | int
94
-     * @throws ReflectionException
95
-     * @throws InvalidArgumentException
96
-     * @throws InvalidInterfaceException
97
-     * @throws InvalidDataTypeException
98
-     * @throws EE_Error
99
-     */
100
-    public static function trashTicket($entity)
101
-    {
102
-        // trash the ticket
103
-        return $entity->delete();
104
-    }
89
+	/**
90
+	 * Trashes a ticket.
91
+	 *
92
+	 * @param EE_Ticket $entity
93
+	 * @return bool | int
94
+	 * @throws ReflectionException
95
+	 * @throws InvalidArgumentException
96
+	 * @throws InvalidInterfaceException
97
+	 * @throws InvalidDataTypeException
98
+	 * @throws EE_Error
99
+	 */
100
+	public static function trashTicket($entity)
101
+	{
102
+		// trash the ticket
103
+		return $entity->delete();
104
+	}
105 105
 }
Please login to merge, or discard this patch.
core/domain/services/graphql/mutators/EntityReorder.php 2 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -22,148 +22,148 @@
 block discarded – undo
22 22
 
23 23
 class EntityReorder
24 24
 {
25
-    /**
26
-     * Defines the mutation data modification closure.
27
-     *
28
-     * @return callable
29
-     */
30
-    public static function mutateAndGetPayload()
31
-    {
32
-        /**
33
-         * Updates an entity.
34
-         *
35
-         * @param array       $input   The input for the mutation
36
-         * @param AppContext  $context The AppContext passed down to all resolvers
37
-         * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
38
-         * @return array
39
-         * @throws UserError
40
-         * @throws ReflectionException
41
-         * @throws InvalidArgumentException
42
-         * @throws InvalidInterfaceException
43
-         * @throws InvalidDataTypeException
44
-         * @throws EE_Error
45
-         */
46
-        return static function ($input, AppContext $context, ResolveInfo $info) {
47
-            /**
48
-             * Stop now if a user isn't allowed to reorder.
49
-             */
50
-            if (! current_user_can('ee_edit_events')) {
51
-                throw new UserError(
52
-                    esc_html__('Sorry, you do not have the required permissions to reorder entities', 'event_espresso')
53
-                );
54
-            }
55
-
56
-            $details = EntityReorder::prepareEntityDetailsFromInput($input);
57
-
58
-            $orderKey  = $details['keyPrefix'] . '_order'; // e.g. "TKT_order"
59
-
60
-            $ok = false;
61
-
62
-            // We do not want to continue reorder if one fails.
63
-            // Thus wrap whole loop in try-catch
64
-            try {
65
-                foreach ($details['entityDbids'] as $order => $entityDbid) {
66
-                    $args = [
67
-                        $orderKey => $order + 1,
68
-                    ];
69
-                    $details['entities'][ $entityDbid ]->save($args);
70
-                }
71
-                $ok = true;
72
-            } catch (Exception $exception) {
73
-                new ExceptionStackTraceDisplay(
74
-                    new RuntimeException(
75
-                        sprintf(
76
-                            esc_html__(
77
-                                'Failed to update order because of the following error(s): %1$s',
78
-                                'event_espresso'
79
-                            ),
80
-                            $exception->getMessage()
81
-                        )
82
-                    )
83
-                );
84
-            }
85
-
86
-            return compact('ok');
87
-        };
88
-    }
89
-
90
-    /**
91
-     * Prepares entity details to use for mutations
92
-     * @param array       $input   The input for the mutation
93
-     *
94
-     * @return array
95
-     */
96
-    public static function prepareEntityDetailsFromInput($input)
97
-    {
98
-        $entityGuids = ! empty($input['entityIds']) ? array_map('sanitize_text_field', (array) $input['entityIds']) : [];
99
-        $entityType  = ! empty($input['entityType']) ? sanitize_text_field($input['entityType']) : null;
100
-
101
-        /**
102
-         * Make sure we have the IDs and entity type
103
-         */
104
-        if (empty($entityGuids) || empty($entityType)) {
105
-            throw new UserError(
106
-                // translators: the placeholders are the names of the fields
107
-                sprintf(esc_html__('%1$s and %2$s are required.', 'event_espresso'), 'entityIds', 'entityType')
108
-            );
109
-        }
110
-
111
-        $model = EE_Registry::instance()->load_model($entityType);
112
-
113
-        if (!($model instanceof EEM_Base)) {
114
-            throw new UserError(
115
-                esc_html__(
116
-                    'A valid data model could not be obtained. Did you supply a valid entity type?',
117
-                    'event_espresso'
118
-                )
119
-            );
120
-        }
121
-
122
-        // convert GUIDs to DB IDs
123
-        $entityDbids = array_map(function ($entityGuid) {
124
-            $id_parts = Relay::fromGlobalId($entityGuid);
125
-            return ! empty($id_parts['id']) ? absint($id_parts['id']) : 0;
126
-        }, (array) $entityGuids);
127
-        // remove 0 values
128
-        $entityDbids = array_filter($entityDbids);
129
-
130
-        /**
131
-         * If we could not get DB IDs for some GUIDs
132
-         */
133
-        if (count($entityDbids) !== count($entityGuids)) {
134
-            throw new UserError(
135
-                esc_html__('Sorry, operation cancelled due to missing or invalid entity IDs.', 'event_espresso')
136
-            );
137
-        }
138
-
139
-        // e.g. DTT_ID, TKT_ID
140
-        $primaryKey = $model->get_primary_key_field()->get_name();
141
-        // e.g. "DTT_ID" will give us "DTT"
142
-        $keyPrefix = explode('_', $primaryKey)[0];
143
-        $deletedKey  = $keyPrefix . '_deleted'; // e.g. "TKT_deleted"
144
-
145
-        $entities = $model::instance()->get_all([
146
-            [
147
-                $primaryKey => ['IN', $entityDbids],
148
-                $deletedKey => ['IN', [true, false]],
149
-            ],
150
-        ]);
151
-
152
-        /**
153
-         * If we could not get exactly same number of entities for the given DB IDs
154
-         */
155
-        if (count($entityDbids) !== count($entities)) {
156
-            throw new UserError(esc_html__('Sorry, operation cancelled due to missing entities.', 'event_espresso'));
157
-        }
158
-
159
-        // Make sure we have an instance for every ID.
160
-        foreach ($entityDbids as $entityDbid) {
161
-            if (isset($entities[ $entityDbid ]) && $entities[ $entityDbid ] instanceof EE_Base_Class) {
162
-                continue;
163
-            }
164
-            throw new UserError(esc_html__('Sorry, operation cancelled due to invalid entities.', 'event_espresso'));
165
-        }
166
-
167
-        return compact('entities', 'entityGuids', 'entityDbids', 'entityType', 'keyPrefix');
168
-    }
25
+	/**
26
+	 * Defines the mutation data modification closure.
27
+	 *
28
+	 * @return callable
29
+	 */
30
+	public static function mutateAndGetPayload()
31
+	{
32
+		/**
33
+		 * Updates an entity.
34
+		 *
35
+		 * @param array       $input   The input for the mutation
36
+		 * @param AppContext  $context The AppContext passed down to all resolvers
37
+		 * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
38
+		 * @return array
39
+		 * @throws UserError
40
+		 * @throws ReflectionException
41
+		 * @throws InvalidArgumentException
42
+		 * @throws InvalidInterfaceException
43
+		 * @throws InvalidDataTypeException
44
+		 * @throws EE_Error
45
+		 */
46
+		return static function ($input, AppContext $context, ResolveInfo $info) {
47
+			/**
48
+			 * Stop now if a user isn't allowed to reorder.
49
+			 */
50
+			if (! current_user_can('ee_edit_events')) {
51
+				throw new UserError(
52
+					esc_html__('Sorry, you do not have the required permissions to reorder entities', 'event_espresso')
53
+				);
54
+			}
55
+
56
+			$details = EntityReorder::prepareEntityDetailsFromInput($input);
57
+
58
+			$orderKey  = $details['keyPrefix'] . '_order'; // e.g. "TKT_order"
59
+
60
+			$ok = false;
61
+
62
+			// We do not want to continue reorder if one fails.
63
+			// Thus wrap whole loop in try-catch
64
+			try {
65
+				foreach ($details['entityDbids'] as $order => $entityDbid) {
66
+					$args = [
67
+						$orderKey => $order + 1,
68
+					];
69
+					$details['entities'][ $entityDbid ]->save($args);
70
+				}
71
+				$ok = true;
72
+			} catch (Exception $exception) {
73
+				new ExceptionStackTraceDisplay(
74
+					new RuntimeException(
75
+						sprintf(
76
+							esc_html__(
77
+								'Failed to update order because of the following error(s): %1$s',
78
+								'event_espresso'
79
+							),
80
+							$exception->getMessage()
81
+						)
82
+					)
83
+				);
84
+			}
85
+
86
+			return compact('ok');
87
+		};
88
+	}
89
+
90
+	/**
91
+	 * Prepares entity details to use for mutations
92
+	 * @param array       $input   The input for the mutation
93
+	 *
94
+	 * @return array
95
+	 */
96
+	public static function prepareEntityDetailsFromInput($input)
97
+	{
98
+		$entityGuids = ! empty($input['entityIds']) ? array_map('sanitize_text_field', (array) $input['entityIds']) : [];
99
+		$entityType  = ! empty($input['entityType']) ? sanitize_text_field($input['entityType']) : null;
100
+
101
+		/**
102
+		 * Make sure we have the IDs and entity type
103
+		 */
104
+		if (empty($entityGuids) || empty($entityType)) {
105
+			throw new UserError(
106
+				// translators: the placeholders are the names of the fields
107
+				sprintf(esc_html__('%1$s and %2$s are required.', 'event_espresso'), 'entityIds', 'entityType')
108
+			);
109
+		}
110
+
111
+		$model = EE_Registry::instance()->load_model($entityType);
112
+
113
+		if (!($model instanceof EEM_Base)) {
114
+			throw new UserError(
115
+				esc_html__(
116
+					'A valid data model could not be obtained. Did you supply a valid entity type?',
117
+					'event_espresso'
118
+				)
119
+			);
120
+		}
121
+
122
+		// convert GUIDs to DB IDs
123
+		$entityDbids = array_map(function ($entityGuid) {
124
+			$id_parts = Relay::fromGlobalId($entityGuid);
125
+			return ! empty($id_parts['id']) ? absint($id_parts['id']) : 0;
126
+		}, (array) $entityGuids);
127
+		// remove 0 values
128
+		$entityDbids = array_filter($entityDbids);
129
+
130
+		/**
131
+		 * If we could not get DB IDs for some GUIDs
132
+		 */
133
+		if (count($entityDbids) !== count($entityGuids)) {
134
+			throw new UserError(
135
+				esc_html__('Sorry, operation cancelled due to missing or invalid entity IDs.', 'event_espresso')
136
+			);
137
+		}
138
+
139
+		// e.g. DTT_ID, TKT_ID
140
+		$primaryKey = $model->get_primary_key_field()->get_name();
141
+		// e.g. "DTT_ID" will give us "DTT"
142
+		$keyPrefix = explode('_', $primaryKey)[0];
143
+		$deletedKey  = $keyPrefix . '_deleted'; // e.g. "TKT_deleted"
144
+
145
+		$entities = $model::instance()->get_all([
146
+			[
147
+				$primaryKey => ['IN', $entityDbids],
148
+				$deletedKey => ['IN', [true, false]],
149
+			],
150
+		]);
151
+
152
+		/**
153
+		 * If we could not get exactly same number of entities for the given DB IDs
154
+		 */
155
+		if (count($entityDbids) !== count($entities)) {
156
+			throw new UserError(esc_html__('Sorry, operation cancelled due to missing entities.', 'event_espresso'));
157
+		}
158
+
159
+		// Make sure we have an instance for every ID.
160
+		foreach ($entityDbids as $entityDbid) {
161
+			if (isset($entities[ $entityDbid ]) && $entities[ $entityDbid ] instanceof EE_Base_Class) {
162
+				continue;
163
+			}
164
+			throw new UserError(esc_html__('Sorry, operation cancelled due to invalid entities.', 'event_espresso'));
165
+		}
166
+
167
+		return compact('entities', 'entityGuids', 'entityDbids', 'entityType', 'keyPrefix');
168
+	}
169 169
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
          * @throws InvalidDataTypeException
44 44
          * @throws EE_Error
45 45
          */
46
-        return static function ($input, AppContext $context, ResolveInfo $info) {
46
+        return static function($input, AppContext $context, ResolveInfo $info) {
47 47
             /**
48 48
              * Stop now if a user isn't allowed to reorder.
49 49
              */
50
-            if (! current_user_can('ee_edit_events')) {
50
+            if ( ! current_user_can('ee_edit_events')) {
51 51
                 throw new UserError(
52 52
                     esc_html__('Sorry, you do not have the required permissions to reorder entities', 'event_espresso')
53 53
                 );
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 
56 56
             $details = EntityReorder::prepareEntityDetailsFromInput($input);
57 57
 
58
-            $orderKey  = $details['keyPrefix'] . '_order'; // e.g. "TKT_order"
58
+            $orderKey = $details['keyPrefix'].'_order'; // e.g. "TKT_order"
59 59
 
60 60
             $ok = false;
61 61
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
                     $args = [
67 67
                         $orderKey => $order + 1,
68 68
                     ];
69
-                    $details['entities'][ $entityDbid ]->save($args);
69
+                    $details['entities'][$entityDbid]->save($args);
70 70
                 }
71 71
                 $ok = true;
72 72
             } catch (Exception $exception) {
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 
111 111
         $model = EE_Registry::instance()->load_model($entityType);
112 112
 
113
-        if (!($model instanceof EEM_Base)) {
113
+        if ( ! ($model instanceof EEM_Base)) {
114 114
             throw new UserError(
115 115
                 esc_html__(
116 116
                     'A valid data model could not be obtained. Did you supply a valid entity type?',
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
         }
121 121
 
122 122
         // convert GUIDs to DB IDs
123
-        $entityDbids = array_map(function ($entityGuid) {
123
+        $entityDbids = array_map(function($entityGuid) {
124 124
             $id_parts = Relay::fromGlobalId($entityGuid);
125 125
             return ! empty($id_parts['id']) ? absint($id_parts['id']) : 0;
126 126
         }, (array) $entityGuids);
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
         $primaryKey = $model->get_primary_key_field()->get_name();
141 141
         // e.g. "DTT_ID" will give us "DTT"
142 142
         $keyPrefix = explode('_', $primaryKey)[0];
143
-        $deletedKey  = $keyPrefix . '_deleted'; // e.g. "TKT_deleted"
143
+        $deletedKey = $keyPrefix.'_deleted'; // e.g. "TKT_deleted"
144 144
 
145 145
         $entities = $model::instance()->get_all([
146 146
             [
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 
159 159
         // Make sure we have an instance for every ID.
160 160
         foreach ($entityDbids as $entityDbid) {
161
-            if (isset($entities[ $entityDbid ]) && $entities[ $entityDbid ] instanceof EE_Base_Class) {
161
+            if (isset($entities[$entityDbid]) && $entities[$entityDbid] instanceof EE_Base_Class) {
162 162
                 continue;
163 163
             }
164 164
             throw new UserError(esc_html__('Sorry, operation cancelled due to invalid entities.', 'event_espresso'));
Please login to merge, or discard this patch.
core/domain/services/graphql/types/Datetime.php 2 patches
Indentation   +396 added lines, -396 removed lines patch added patch discarded remove patch
@@ -36,412 +36,412 @@
 block discarded – undo
36 36
 class Datetime extends TypeBase
37 37
 {
38 38
 
39
-    /**
40
-     * EventDate constructor.
41
-     *
42
-     * @param EEM_Datetime $datetime_model
43
-     */
44
-    public function __construct(EEM_Datetime $datetime_model)
45
-    {
46
-        $this->model = $datetime_model;
47
-        $this->setName($this->namespace . 'Datetime');
48
-        $this->setDescription(__('An event date', 'event_espresso'));
49
-        $this->setIsCustomPostType(false);
50
-        parent::__construct();
51
-    }
39
+	/**
40
+	 * EventDate constructor.
41
+	 *
42
+	 * @param EEM_Datetime $datetime_model
43
+	 */
44
+	public function __construct(EEM_Datetime $datetime_model)
45
+	{
46
+		$this->model = $datetime_model;
47
+		$this->setName($this->namespace . 'Datetime');
48
+		$this->setDescription(__('An event date', 'event_espresso'));
49
+		$this->setIsCustomPostType(false);
50
+		parent::__construct();
51
+	}
52 52
 
53 53
 
54
-    /**
55
-     * @return GraphQLFieldInterface[]
56
-     * @since $VID:$
57
-     */
58
-    public function getFields()
59
-    {
60
-        $fields = [
61
-            new GraphQLField(
62
-                'id',
63
-                ['non_null' => 'ID'],
64
-                null,
65
-                esc_html__('The globally unique ID for the object.', 'event_espresso')
66
-            ),
67
-            new GraphQLOutputField(
68
-                'dbId',
69
-                ['non_null' => 'Int'],
70
-                'ID',
71
-                esc_html__('The datetime ID.', 'event_espresso')
72
-            ),
73
-            new GraphQLOutputField(
74
-                'cacheId',
75
-                ['non_null' => 'String'],
76
-                null,
77
-                esc_html__('The cache ID of the object.', 'event_espresso')
78
-            ),
79
-            new GraphQLField(
80
-                'capacity',
81
-                'Int',
82
-                'reg_limit',
83
-                esc_html__('Registration Limit for this time', 'event_espresso'),
84
-                [$this, 'parseInfiniteValue']
85
-            ),
86
-            new GraphQLField(
87
-                'description',
88
-                'String',
89
-                'description',
90
-                esc_html__('Description for Datetime', 'event_espresso')
91
-            ),
92
-            new GraphQLField(
93
-                'endDate',
94
-                'String',
95
-                'end_date_and_time',
96
-                esc_html__('End date and time of the Event', 'event_espresso'),
97
-                [$this, 'formatDatetime']
98
-            ),
99
-            new GraphQLOutputField(
100
-                'event',
101
-                $this->namespace . 'Event',
102
-                null,
103
-                esc_html__('Event of the datetime.', 'event_espresso')
104
-            ),
105
-            new GraphQLInputField(
106
-                'event',
107
-                'ID',
108
-                null,
109
-                esc_html__('Globally unique event ID of the datetime.', 'event_espresso')
110
-            ),
111
-            new GraphQLInputField(
112
-                'eventId',
113
-                'Int',
114
-                null,
115
-                esc_html__('Event ID of the datetime.', 'event_espresso')
116
-            ),
117
-            new GraphQLOutputField(
118
-                'isActive',
119
-                'Boolean',
120
-                'is_active',
121
-                esc_html__('Flag indicating datetime is active', 'event_espresso')
122
-            ),
123
-            new GraphQLOutputField(
124
-                'isExpired',
125
-                'Boolean',
126
-                'is_expired',
127
-                esc_html__('Flag indicating datetime is expired or not', 'event_espresso')
128
-            ),
129
-            new GraphQLField(
130
-                'isPrimary',
131
-                'Boolean',
132
-                'is_primary',
133
-                esc_html__('Flag indicating datetime is primary one for event', 'event_espresso')
134
-            ),
135
-            new GraphQLOutputField(
136
-                'isSoldOut',
137
-                'Boolean',
138
-                'sold_out',
139
-                esc_html__(
140
-                    'Flag indicating whether the tickets sold for this datetime, met or exceed the registration limit',
141
-                    'event_espresso'
142
-                )
143
-            ),
144
-            new GraphQLField(
145
-                'isTrashed',
146
-                'Boolean',
147
-                null,
148
-                esc_html__('Flag indicating datetime has been trashed.', 'event_espresso'),
149
-                null,
150
-                [$this, 'getIsTrashed']
151
-            ),
152
-            new GraphQLOutputField(
153
-                'isUpcoming',
154
-                'Boolean',
155
-                'is_upcoming',
156
-                esc_html__('Whether the date is upcoming', 'event_espresso')
157
-            ),
158
-            new GraphQLOutputField(
159
-                'length',
160
-                'Int',
161
-                'length',
162
-                esc_html__('The length of the event (start to end time) in seconds', 'event_espresso')
163
-            ),
164
-            new GraphQLField(
165
-                'name',
166
-                'String',
167
-                'name',
168
-                esc_html__('Datetime Name', 'event_espresso')
169
-            ),
170
-            new GraphQLField(
171
-                'order',
172
-                'Int',
173
-                'order',
174
-                esc_html__('The order in which the Datetime is displayed', 'event_espresso')
175
-            ),
176
-            new GraphQLOutputField(
177
-                'parent',
178
-                $this->name(),
179
-                null,
180
-                esc_html__('The parent datetime of the current datetime', 'event_espresso')
181
-            ),
182
-            new GraphQLInputField(
183
-                'parent',
184
-                'ID',
185
-                null,
186
-                esc_html__('The parent datetime ID', 'event_espresso')
187
-            ),
188
-            new GraphQLField(
189
-                'reserved',
190
-                'Int',
191
-                'reserved',
192
-                esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso')
193
-            ),
194
-            new GraphQLField(
195
-                'startDate',
196
-                'String',
197
-                'start_date_and_time',
198
-                esc_html__('Start date and time of the Event', 'event_espresso'),
199
-                [$this, 'formatDatetime']
200
-            ),
201
-            new GraphQLField(
202
-                'sold',
203
-                'Int',
204
-                'sold',
205
-                esc_html__('How many sales for this Datetime that have occurred', 'event_espresso')
206
-            ),
207
-            new GraphQLOutputField(
208
-                'status',
209
-                $this->namespace . 'DatetimeStatusEnum',
210
-                'get_active_status',
211
-                esc_html__('Datetime status', 'event_espresso')
212
-            ),
213
-            new GraphQLInputField(
214
-                'tickets',
215
-                ['list_of' => 'ID'],
216
-                null,
217
-                sprintf(
218
-                    '%1$s %2$s',
219
-                    esc_html__('Globally unique IDs of the tickets related to the datetime.', 'event_espresso'),
220
-                    esc_html__('Ignored if empty.', 'event_espresso')
221
-                )
222
-            ),
223
-        ];
54
+	/**
55
+	 * @return GraphQLFieldInterface[]
56
+	 * @since $VID:$
57
+	 */
58
+	public function getFields()
59
+	{
60
+		$fields = [
61
+			new GraphQLField(
62
+				'id',
63
+				['non_null' => 'ID'],
64
+				null,
65
+				esc_html__('The globally unique ID for the object.', 'event_espresso')
66
+			),
67
+			new GraphQLOutputField(
68
+				'dbId',
69
+				['non_null' => 'Int'],
70
+				'ID',
71
+				esc_html__('The datetime ID.', 'event_espresso')
72
+			),
73
+			new GraphQLOutputField(
74
+				'cacheId',
75
+				['non_null' => 'String'],
76
+				null,
77
+				esc_html__('The cache ID of the object.', 'event_espresso')
78
+			),
79
+			new GraphQLField(
80
+				'capacity',
81
+				'Int',
82
+				'reg_limit',
83
+				esc_html__('Registration Limit for this time', 'event_espresso'),
84
+				[$this, 'parseInfiniteValue']
85
+			),
86
+			new GraphQLField(
87
+				'description',
88
+				'String',
89
+				'description',
90
+				esc_html__('Description for Datetime', 'event_espresso')
91
+			),
92
+			new GraphQLField(
93
+				'endDate',
94
+				'String',
95
+				'end_date_and_time',
96
+				esc_html__('End date and time of the Event', 'event_espresso'),
97
+				[$this, 'formatDatetime']
98
+			),
99
+			new GraphQLOutputField(
100
+				'event',
101
+				$this->namespace . 'Event',
102
+				null,
103
+				esc_html__('Event of the datetime.', 'event_espresso')
104
+			),
105
+			new GraphQLInputField(
106
+				'event',
107
+				'ID',
108
+				null,
109
+				esc_html__('Globally unique event ID of the datetime.', 'event_espresso')
110
+			),
111
+			new GraphQLInputField(
112
+				'eventId',
113
+				'Int',
114
+				null,
115
+				esc_html__('Event ID of the datetime.', 'event_espresso')
116
+			),
117
+			new GraphQLOutputField(
118
+				'isActive',
119
+				'Boolean',
120
+				'is_active',
121
+				esc_html__('Flag indicating datetime is active', 'event_espresso')
122
+			),
123
+			new GraphQLOutputField(
124
+				'isExpired',
125
+				'Boolean',
126
+				'is_expired',
127
+				esc_html__('Flag indicating datetime is expired or not', 'event_espresso')
128
+			),
129
+			new GraphQLField(
130
+				'isPrimary',
131
+				'Boolean',
132
+				'is_primary',
133
+				esc_html__('Flag indicating datetime is primary one for event', 'event_espresso')
134
+			),
135
+			new GraphQLOutputField(
136
+				'isSoldOut',
137
+				'Boolean',
138
+				'sold_out',
139
+				esc_html__(
140
+					'Flag indicating whether the tickets sold for this datetime, met or exceed the registration limit',
141
+					'event_espresso'
142
+				)
143
+			),
144
+			new GraphQLField(
145
+				'isTrashed',
146
+				'Boolean',
147
+				null,
148
+				esc_html__('Flag indicating datetime has been trashed.', 'event_espresso'),
149
+				null,
150
+				[$this, 'getIsTrashed']
151
+			),
152
+			new GraphQLOutputField(
153
+				'isUpcoming',
154
+				'Boolean',
155
+				'is_upcoming',
156
+				esc_html__('Whether the date is upcoming', 'event_espresso')
157
+			),
158
+			new GraphQLOutputField(
159
+				'length',
160
+				'Int',
161
+				'length',
162
+				esc_html__('The length of the event (start to end time) in seconds', 'event_espresso')
163
+			),
164
+			new GraphQLField(
165
+				'name',
166
+				'String',
167
+				'name',
168
+				esc_html__('Datetime Name', 'event_espresso')
169
+			),
170
+			new GraphQLField(
171
+				'order',
172
+				'Int',
173
+				'order',
174
+				esc_html__('The order in which the Datetime is displayed', 'event_espresso')
175
+			),
176
+			new GraphQLOutputField(
177
+				'parent',
178
+				$this->name(),
179
+				null,
180
+				esc_html__('The parent datetime of the current datetime', 'event_espresso')
181
+			),
182
+			new GraphQLInputField(
183
+				'parent',
184
+				'ID',
185
+				null,
186
+				esc_html__('The parent datetime ID', 'event_espresso')
187
+			),
188
+			new GraphQLField(
189
+				'reserved',
190
+				'Int',
191
+				'reserved',
192
+				esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso')
193
+			),
194
+			new GraphQLField(
195
+				'startDate',
196
+				'String',
197
+				'start_date_and_time',
198
+				esc_html__('Start date and time of the Event', 'event_espresso'),
199
+				[$this, 'formatDatetime']
200
+			),
201
+			new GraphQLField(
202
+				'sold',
203
+				'Int',
204
+				'sold',
205
+				esc_html__('How many sales for this Datetime that have occurred', 'event_espresso')
206
+			),
207
+			new GraphQLOutputField(
208
+				'status',
209
+				$this->namespace . 'DatetimeStatusEnum',
210
+				'get_active_status',
211
+				esc_html__('Datetime status', 'event_espresso')
212
+			),
213
+			new GraphQLInputField(
214
+				'tickets',
215
+				['list_of' => 'ID'],
216
+				null,
217
+				sprintf(
218
+					'%1$s %2$s',
219
+					esc_html__('Globally unique IDs of the tickets related to the datetime.', 'event_espresso'),
220
+					esc_html__('Ignored if empty.', 'event_espresso')
221
+				)
222
+			),
223
+		];
224 224
 
225
-        return apply_filters(
226
-            'FHEE__EventEspresso_core_domain_services_graphql_types__datetime_fields',
227
-            $fields,
228
-            $this->name,
229
-            $this->model
230
-        );
231
-    }
225
+		return apply_filters(
226
+			'FHEE__EventEspresso_core_domain_services_graphql_types__datetime_fields',
227
+			$fields,
228
+			$this->name,
229
+			$this->model
230
+		);
231
+	}
232 232
 
233 233
 
234
-    /**
235
-     * @param EE_Datetime   $source  The source that's passed down the GraphQL queries
236
-     * @param array       $args    The inputArgs on the field
237
-     * @param AppContext  $context The AppContext passed down the GraphQL tree
238
-     * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
239
-     * @return string
240
-     * @throws Exception
241
-     * @throws InvalidArgumentException
242
-     * @throws InvalidDataTypeException
243
-     * @throws InvalidInterfaceException
244
-     * @throws ReflectionException
245
-     * @throws UserError
246
-     * @throws UnexpectedEntityException
247
-     * @since $VID:$
248
-     */
249
-    public function getIsTrashed(EE_Datetime $source, array $args, AppContext $context, ResolveInfo $info)
250
-    {
251
-        return (bool) $source->get('DTT_deleted');
252
-    }
234
+	/**
235
+	 * @param EE_Datetime   $source  The source that's passed down the GraphQL queries
236
+	 * @param array       $args    The inputArgs on the field
237
+	 * @param AppContext  $context The AppContext passed down the GraphQL tree
238
+	 * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
239
+	 * @return string
240
+	 * @throws Exception
241
+	 * @throws InvalidArgumentException
242
+	 * @throws InvalidDataTypeException
243
+	 * @throws InvalidInterfaceException
244
+	 * @throws ReflectionException
245
+	 * @throws UserError
246
+	 * @throws UnexpectedEntityException
247
+	 * @since $VID:$
248
+	 */
249
+	public function getIsTrashed(EE_Datetime $source, array $args, AppContext $context, ResolveInfo $info)
250
+	{
251
+		return (bool) $source->get('DTT_deleted');
252
+	}
253 253
 
254
-    /**
255
-     * Return the base mutation config for bulk update.
256
-     *
257
-     * @param string $base_input
258
-     * @return array
259
-     */
260
-    public static function bulkUpdateBaseConfig($base_input)
261
-    {
262
-        return [
263
-            'inputFields'     => [
264
-                /**
265
-                 * represents the input that is unique for each entity
266
-                 * e.g. dates may be unique for dateimes and tickets
267
-                 */
268
-                'uniqueInputs' => [
269
-                    'type'        => [
270
-                        'non_null' => ['list_of' => $base_input],
271
-                    ],
272
-                    'description' => esc_html__(
273
-                        'List of unique inputs for each entity in bulk update',
274
-                        'event_espresso'
275
-                    ),
276
-                ],
277
-                /**
278
-                 * represents the common input for all entities
279
-                 * e.g. capacity or quantity may be same for all dates/tickets
280
-                 */
281
-                'sharedInput' => [
282
-                    'type'        => $base_input,
283
-                    'description' => esc_html__(
284
-                        'Shared input for all entities in bulk update',
285
-                        'event_espresso'
286
-                    ),
287
-                ],
288
-            ],
289
-            'outputFields'        => [
290
-                'updated' => [
291
-                    'type' => ['list_of' => 'ID'],
292
-                ],
293
-                'failed' => [
294
-                    'type' => ['list_of' => 'ID'],
295
-                ],
296
-            ],
297
-        ];
298
-    }
254
+	/**
255
+	 * Return the base mutation config for bulk update.
256
+	 *
257
+	 * @param string $base_input
258
+	 * @return array
259
+	 */
260
+	public static function bulkUpdateBaseConfig($base_input)
261
+	{
262
+		return [
263
+			'inputFields'     => [
264
+				/**
265
+				 * represents the input that is unique for each entity
266
+				 * e.g. dates may be unique for dateimes and tickets
267
+				 */
268
+				'uniqueInputs' => [
269
+					'type'        => [
270
+						'non_null' => ['list_of' => $base_input],
271
+					],
272
+					'description' => esc_html__(
273
+						'List of unique inputs for each entity in bulk update',
274
+						'event_espresso'
275
+					),
276
+				],
277
+				/**
278
+				 * represents the common input for all entities
279
+				 * e.g. capacity or quantity may be same for all dates/tickets
280
+				 */
281
+				'sharedInput' => [
282
+					'type'        => $base_input,
283
+					'description' => esc_html__(
284
+						'Shared input for all entities in bulk update',
285
+						'event_espresso'
286
+					),
287
+				],
288
+			],
289
+			'outputFields'        => [
290
+				'updated' => [
291
+					'type' => ['list_of' => 'ID'],
292
+				],
293
+				'failed' => [
294
+					'type' => ['list_of' => 'ID'],
295
+				],
296
+			],
297
+		];
298
+	}
299 299
 
300 300
 
301
-    /**
302
-     * @param array $inputFields The mutation input fields.
303
-     * @throws InvalidArgumentException
304
-     * @throws ReflectionException
305
-     * @since $VID:$
306
-     */
307
-    public function registerMutations(array $inputFields)
308
-    {
309
-        register_graphql_input_type(
310
-            'Update' .  $this->name() . 'BaseInput',
311
-            [
312
-                'fields' => $inputFields,
313
-            ]
314
-        );
315
-        // Register mutation to update an entity.
316
-        register_graphql_mutation(
317
-            'update' . $this->name(),
318
-            [
319
-                'inputFields'         => $inputFields,
320
-                'outputFields'        => [
321
-                    lcfirst($this->name()) => [
322
-                        'type'    => $this->name(),
323
-                        'resolve' => [$this, 'resolveFromPayload'],
324
-                    ],
325
-                ],
326
-                'mutateAndGetPayload' => DatetimeUpdate::mutateAndGetPayload($this->model, $this),
327
-            ]
328
-        );
329
-        $base_input = 'Update' .  $this->name() . 'BaseInput';
330
-        // Register mutation to update an entity.
331
-        register_graphql_mutation(
332
-            'bulkUpdate' . $this->name(),
333
-            array_merge(
334
-                Datetime::bulkUpdateBaseConfig($base_input),
335
-                [
336
-                    'mutateAndGetPayload' => DatetimeBulkUpdate::mutateAndGetPayload($this->model, $this),
337
-                ]
338
-            )
339
-        );
301
+	/**
302
+	 * @param array $inputFields The mutation input fields.
303
+	 * @throws InvalidArgumentException
304
+	 * @throws ReflectionException
305
+	 * @since $VID:$
306
+	 */
307
+	public function registerMutations(array $inputFields)
308
+	{
309
+		register_graphql_input_type(
310
+			'Update' .  $this->name() . 'BaseInput',
311
+			[
312
+				'fields' => $inputFields,
313
+			]
314
+		);
315
+		// Register mutation to update an entity.
316
+		register_graphql_mutation(
317
+			'update' . $this->name(),
318
+			[
319
+				'inputFields'         => $inputFields,
320
+				'outputFields'        => [
321
+					lcfirst($this->name()) => [
322
+						'type'    => $this->name(),
323
+						'resolve' => [$this, 'resolveFromPayload'],
324
+					],
325
+				],
326
+				'mutateAndGetPayload' => DatetimeUpdate::mutateAndGetPayload($this->model, $this),
327
+			]
328
+		);
329
+		$base_input = 'Update' .  $this->name() . 'BaseInput';
330
+		// Register mutation to update an entity.
331
+		register_graphql_mutation(
332
+			'bulkUpdate' . $this->name(),
333
+			array_merge(
334
+				Datetime::bulkUpdateBaseConfig($base_input),
335
+				[
336
+					'mutateAndGetPayload' => DatetimeBulkUpdate::mutateAndGetPayload($this->model, $this),
337
+				]
338
+			)
339
+		);
340 340
 
341
-        // Register mutation to update an entity.
342
-        register_graphql_mutation(
343
-            'bulkDelete' . $this->namespace . 'Entities',
344
-            [
345
-                'inputFields'         => [
346
-                    'entityIds'  => [
347
-                        'type'        => [
348
-                            'non_null' => ['list_of' => 'ID'],
349
-                        ],
350
-                        'description' => esc_html__('The list of GUIDs of the entities to be deleted.', 'event_espresso'),
351
-                    ],
352
-                    'entityType' => [
353
-                        'type'        => [
354
-                            'non_null' => $this->namespace . 'ModelNameEnum',
355
-                        ],
356
-                        'description' => esc_html__('The entity type for the IDs', 'event_espresso'),
357
-                    ],
358
-                    'deletePermanently' => [
359
-                        'type'        => 'Boolean',
360
-                        'description' => esc_html__('Whether to delete the entities permanently.', 'event_espresso'),
361
-                    ],
362
-                ],
363
-                'outputFields'        => [
364
-                    'deleted' => [
365
-                        'type' => ['list_of' => 'ID'],
366
-                    ],
367
-                    'failed' => [
368
-                        'type' => ['list_of' => 'ID'],
369
-                    ],
370
-                ],
371
-                'mutateAndGetPayload' => BulkEntityDelete::mutateAndGetPayload(),
372
-            ]
373
-        );
374
-        // Register mutation to delete an entity.
375
-        register_graphql_mutation(
376
-            'delete' . $this->name(),
377
-            [
378
-                'inputFields'         => [
379
-                    'id'                => $inputFields['id'],
380
-                    'deletePermanently' => [
381
-                        'type'        => 'Boolean',
382
-                        'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'),
383
-                    ],
384
-                ],
385
-                'outputFields'        => [
386
-                    lcfirst($this->name()) => [
387
-                        'type'        => $this->name(),
388
-                        'description' => esc_html__('The object before it was deleted', 'event_espresso'),
389
-                        'resolve'     => static function ($payload) {
390
-                            $deleted = (object) $payload['deleted'];
341
+		// Register mutation to update an entity.
342
+		register_graphql_mutation(
343
+			'bulkDelete' . $this->namespace . 'Entities',
344
+			[
345
+				'inputFields'         => [
346
+					'entityIds'  => [
347
+						'type'        => [
348
+							'non_null' => ['list_of' => 'ID'],
349
+						],
350
+						'description' => esc_html__('The list of GUIDs of the entities to be deleted.', 'event_espresso'),
351
+					],
352
+					'entityType' => [
353
+						'type'        => [
354
+							'non_null' => $this->namespace . 'ModelNameEnum',
355
+						],
356
+						'description' => esc_html__('The entity type for the IDs', 'event_espresso'),
357
+					],
358
+					'deletePermanently' => [
359
+						'type'        => 'Boolean',
360
+						'description' => esc_html__('Whether to delete the entities permanently.', 'event_espresso'),
361
+					],
362
+				],
363
+				'outputFields'        => [
364
+					'deleted' => [
365
+						'type' => ['list_of' => 'ID'],
366
+					],
367
+					'failed' => [
368
+						'type' => ['list_of' => 'ID'],
369
+					],
370
+				],
371
+				'mutateAndGetPayload' => BulkEntityDelete::mutateAndGetPayload(),
372
+			]
373
+		);
374
+		// Register mutation to delete an entity.
375
+		register_graphql_mutation(
376
+			'delete' . $this->name(),
377
+			[
378
+				'inputFields'         => [
379
+					'id'                => $inputFields['id'],
380
+					'deletePermanently' => [
381
+						'type'        => 'Boolean',
382
+						'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'),
383
+					],
384
+				],
385
+				'outputFields'        => [
386
+					lcfirst($this->name()) => [
387
+						'type'        => $this->name(),
388
+						'description' => esc_html__('The object before it was deleted', 'event_espresso'),
389
+						'resolve'     => static function ($payload) {
390
+							$deleted = (object) $payload['deleted'];
391 391
 
392
-                            return ! empty($deleted) ? $deleted : null;
393
-                        },
394
-                    ],
395
-                ],
396
-                'mutateAndGetPayload' => DatetimeDelete::mutateAndGetPayload($this->model, $this),
397
-            ]
398
-        );
392
+							return ! empty($deleted) ? $deleted : null;
393
+						},
394
+					],
395
+				],
396
+				'mutateAndGetPayload' => DatetimeDelete::mutateAndGetPayload($this->model, $this),
397
+			]
398
+		);
399 399
 
400
-        // remove primary key from input.
401
-        unset($inputFields['id']);
402
-        // Register mutation to update an entity.
403
-        register_graphql_mutation(
404
-            'create' . $this->name(),
405
-            [
406
-                'inputFields'         => $inputFields,
407
-                'outputFields'        => [
408
-                    lcfirst($this->name()) => [
409
-                        'type'    => $this->name(),
410
-                        'resolve' => [$this, 'resolveFromPayload'],
411
-                    ],
412
-                ],
413
-                'mutateAndGetPayload' => DatetimeCreate::mutateAndGetPayload($this->model, $this),
414
-            ]
415
-        );
400
+		// remove primary key from input.
401
+		unset($inputFields['id']);
402
+		// Register mutation to update an entity.
403
+		register_graphql_mutation(
404
+			'create' . $this->name(),
405
+			[
406
+				'inputFields'         => $inputFields,
407
+				'outputFields'        => [
408
+					lcfirst($this->name()) => [
409
+						'type'    => $this->name(),
410
+						'resolve' => [$this, 'resolveFromPayload'],
411
+					],
412
+				],
413
+				'mutateAndGetPayload' => DatetimeCreate::mutateAndGetPayload($this->model, $this),
414
+			]
415
+		);
416 416
 
417
-        // Register mutation to update an entity.
418
-        register_graphql_mutation(
419
-            'reorder' . $this->namespace . 'Entities',
420
-            [
421
-                'inputFields'         => [
422
-                    'entityIds'  => [
423
-                        'type'        => [
424
-                            'non_null' => ['list_of' => 'ID'],
425
-                        ],
426
-                        'description' => esc_html__('The reordered list of entity GUIDs.', 'event_espresso'),
427
-                    ],
428
-                    'entityType' => [
429
-                        'type'        => [
430
-                            'non_null' => $this->namespace . 'ModelNameEnum',
431
-                        ],
432
-                        'description' => esc_html__('The entity type for the IDs', 'event_espresso'),
433
-                    ],
434
-                ],
435
-                'outputFields'        => [
436
-                    'ok' => [
437
-                        'type'    => 'Boolean',
438
-                        'resolve' => function ($payload) {
439
-                            return (bool) $payload['ok'];
440
-                        },
441
-                    ],
442
-                ],
443
-                'mutateAndGetPayload' => EntityReorder::mutateAndGetPayload(),
444
-            ]
445
-        );
446
-    }
417
+		// Register mutation to update an entity.
418
+		register_graphql_mutation(
419
+			'reorder' . $this->namespace . 'Entities',
420
+			[
421
+				'inputFields'         => [
422
+					'entityIds'  => [
423
+						'type'        => [
424
+							'non_null' => ['list_of' => 'ID'],
425
+						],
426
+						'description' => esc_html__('The reordered list of entity GUIDs.', 'event_espresso'),
427
+					],
428
+					'entityType' => [
429
+						'type'        => [
430
+							'non_null' => $this->namespace . 'ModelNameEnum',
431
+						],
432
+						'description' => esc_html__('The entity type for the IDs', 'event_espresso'),
433
+					],
434
+				],
435
+				'outputFields'        => [
436
+					'ok' => [
437
+						'type'    => 'Boolean',
438
+						'resolve' => function ($payload) {
439
+							return (bool) $payload['ok'];
440
+						},
441
+					],
442
+				],
443
+				'mutateAndGetPayload' => EntityReorder::mutateAndGetPayload(),
444
+			]
445
+		);
446
+	}
447 447
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
     public function __construct(EEM_Datetime $datetime_model)
45 45
     {
46 46
         $this->model = $datetime_model;
47
-        $this->setName($this->namespace . 'Datetime');
47
+        $this->setName($this->namespace.'Datetime');
48 48
         $this->setDescription(__('An event date', 'event_espresso'));
49 49
         $this->setIsCustomPostType(false);
50 50
         parent::__construct();
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
             ),
99 99
             new GraphQLOutputField(
100 100
                 'event',
101
-                $this->namespace . 'Event',
101
+                $this->namespace.'Event',
102 102
                 null,
103 103
                 esc_html__('Event of the datetime.', 'event_espresso')
104 104
             ),
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
             ),
207 207
             new GraphQLOutputField(
208 208
                 'status',
209
-                $this->namespace . 'DatetimeStatusEnum',
209
+                $this->namespace.'DatetimeStatusEnum',
210 210
                 'get_active_status',
211 211
                 esc_html__('Datetime status', 'event_espresso')
212 212
             ),
@@ -307,14 +307,14 @@  discard block
 block discarded – undo
307 307
     public function registerMutations(array $inputFields)
308 308
     {
309 309
         register_graphql_input_type(
310
-            'Update' .  $this->name() . 'BaseInput',
310
+            'Update'.$this->name().'BaseInput',
311 311
             [
312 312
                 'fields' => $inputFields,
313 313
             ]
314 314
         );
315 315
         // Register mutation to update an entity.
316 316
         register_graphql_mutation(
317
-            'update' . $this->name(),
317
+            'update'.$this->name(),
318 318
             [
319 319
                 'inputFields'         => $inputFields,
320 320
                 'outputFields'        => [
@@ -326,10 +326,10 @@  discard block
 block discarded – undo
326 326
                 'mutateAndGetPayload' => DatetimeUpdate::mutateAndGetPayload($this->model, $this),
327 327
             ]
328 328
         );
329
-        $base_input = 'Update' .  $this->name() . 'BaseInput';
329
+        $base_input = 'Update'.$this->name().'BaseInput';
330 330
         // Register mutation to update an entity.
331 331
         register_graphql_mutation(
332
-            'bulkUpdate' . $this->name(),
332
+            'bulkUpdate'.$this->name(),
333 333
             array_merge(
334 334
                 Datetime::bulkUpdateBaseConfig($base_input),
335 335
                 [
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 
341 341
         // Register mutation to update an entity.
342 342
         register_graphql_mutation(
343
-            'bulkDelete' . $this->namespace . 'Entities',
343
+            'bulkDelete'.$this->namespace.'Entities',
344 344
             [
345 345
                 'inputFields'         => [
346 346
                     'entityIds'  => [
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
                     ],
352 352
                     'entityType' => [
353 353
                         'type'        => [
354
-                            'non_null' => $this->namespace . 'ModelNameEnum',
354
+                            'non_null' => $this->namespace.'ModelNameEnum',
355 355
                         ],
356 356
                         'description' => esc_html__('The entity type for the IDs', 'event_espresso'),
357 357
                     ],
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
         );
374 374
         // Register mutation to delete an entity.
375 375
         register_graphql_mutation(
376
-            'delete' . $this->name(),
376
+            'delete'.$this->name(),
377 377
             [
378 378
                 'inputFields'         => [
379 379
                     'id'                => $inputFields['id'],
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
                     lcfirst($this->name()) => [
387 387
                         'type'        => $this->name(),
388 388
                         'description' => esc_html__('The object before it was deleted', 'event_espresso'),
389
-                        'resolve'     => static function ($payload) {
389
+                        'resolve'     => static function($payload) {
390 390
                             $deleted = (object) $payload['deleted'];
391 391
 
392 392
                             return ! empty($deleted) ? $deleted : null;
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
         unset($inputFields['id']);
402 402
         // Register mutation to update an entity.
403 403
         register_graphql_mutation(
404
-            'create' . $this->name(),
404
+            'create'.$this->name(),
405 405
             [
406 406
                 'inputFields'         => $inputFields,
407 407
                 'outputFields'        => [
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 
417 417
         // Register mutation to update an entity.
418 418
         register_graphql_mutation(
419
-            'reorder' . $this->namespace . 'Entities',
419
+            'reorder'.$this->namespace.'Entities',
420 420
             [
421 421
                 'inputFields'         => [
422 422
                     'entityIds'  => [
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
                     ],
428 428
                     'entityType' => [
429 429
                         'type'        => [
430
-                            'non_null' => $this->namespace . 'ModelNameEnum',
430
+                            'non_null' => $this->namespace.'ModelNameEnum',
431 431
                         ],
432 432
                         'description' => esc_html__('The entity type for the IDs', 'event_espresso'),
433 433
                     ],
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
                 'outputFields'        => [
436 436
                     'ok' => [
437 437
                         'type'    => 'Boolean',
438
-                        'resolve' => function ($payload) {
438
+                        'resolve' => function($payload) {
439 439
                             return (bool) $payload['ok'];
440 440
                         },
441 441
                     ],
Please login to merge, or discard this patch.