Completed
Branch dev (65a946)
by
unknown
35:11 queued 25:50
created
core/services/orm/tree_traversal/BaseNode.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@
 block discarded – undo
68 68
      */
69 69
     public function visit($model_objects_to_identify)
70 70
     {
71
-        if (! $this->isDiscovered()) {
71
+        if ( ! $this->isDiscovered()) {
72 72
             $this->discover();
73 73
         }
74 74
         if ($this->isComplete()) {
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@
 block discarded – undo
102 102
     /**
103 103
      * Make sure we encode whether its complete or not, but don't use such a long name.
104 104
      * @since $VID:$
105
-     * @return array
105
+     * @return string[]
106 106
      */
107 107
     public function __sleep()
108 108
     {
Please login to merge, or discard this patch.
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -31,105 +31,105 @@
 block discarded – undo
31 31
  */
32 32
 abstract class BaseNode
33 33
 {
34
-    /**
35
-     * @var boolean
36
-     */
37
-    protected $complete;
34
+	/**
35
+	 * @var boolean
36
+	 */
37
+	protected $complete;
38 38
 
39 39
 
40
-    /**
41
-     * @var array of model names we don't want to traverse
42
-     */
43
-    protected $dont_traverse_models;
40
+	/**
41
+	 * @var array of model names we don't want to traverse
42
+	 */
43
+	protected $dont_traverse_models;
44 44
 
45
-    /**
46
-     * Whether this item has already been initialized
47
-     */
48
-    abstract protected function isDiscovered();
45
+	/**
46
+	 * Whether this item has already been initialized
47
+	 */
48
+	abstract protected function isDiscovered();
49 49
 
50
-    /**
51
-     * Determines if the work is done yet or not. Requires you to have first discovered what work exists by calling
52
-     * discover().
53
-     * @since $VID:$
54
-     * @return boolean
55
-     */
56
-    abstract public function isComplete();
50
+	/**
51
+	 * Determines if the work is done yet or not. Requires you to have first discovered what work exists by calling
52
+	 * discover().
53
+	 * @since $VID:$
54
+	 * @return boolean
55
+	 */
56
+	abstract public function isComplete();
57 57
 
58
-    /**
59
-     * Discovers what work needs to be done to complete traversing this node and its children.
60
-     * Note that this is separate from the constructor, so we can create child nodes without
61
-     * discovering them immediately.
62
-     * @since $VID:$
63
-     * @return mixed
64
-     */
65
-    abstract protected function discover();
58
+	/**
59
+	 * Discovers what work needs to be done to complete traversing this node and its children.
60
+	 * Note that this is separate from the constructor, so we can create child nodes without
61
+	 * discovering them immediately.
62
+	 * @since $VID:$
63
+	 * @return mixed
64
+	 */
65
+	abstract protected function discover();
66 66
 
67
-    /**
68
-     * Identifies model objects, up to the limit $model_objects_to_identify.
69
-     * @since $VID:$
70
-     * @param int $model_objects_to_identify
71
-     * @return int units of work done
72
-     */
73
-    abstract protected function work($model_objects_to_identify);
67
+	/**
68
+	 * Identifies model objects, up to the limit $model_objects_to_identify.
69
+	 * @since $VID:$
70
+	 * @param int $model_objects_to_identify
71
+	 * @return int units of work done
72
+	 */
73
+	abstract protected function work($model_objects_to_identify);
74 74
 
75
-    /**
76
-     * Shows the entity/relation node as an array.
77
-     * @since $VID:$
78
-     * @return array
79
-     */
80
-    abstract public function toArray();
75
+	/**
76
+	 * Shows the entity/relation node as an array.
77
+	 * @since $VID:$
78
+	 * @return array
79
+	 */
80
+	abstract public function toArray();
81 81
 
82
-    /**
83
-     * Discovers how much work there is to do, double-checks the work isn't already finished, and then does the work.
84
-     * Note: do not call when site is in maintenance mode level 2.
85
-     *
86
-     * @since $VID:$
87
-     * @param $model_objects_to_identify
88
-     * @return int number of model objects we want to identify during this call. On subsequent calls we'll continue
89
-     * where we left off.
90
-     */
91
-    public function visit($model_objects_to_identify)
92
-    {
93
-        if (! $this->isDiscovered()) {
94
-            $this->discover();
95
-        }
96
-        if ($this->isComplete()) {
97
-            return 0;
98
-        }
99
-        return $this->work($model_objects_to_identify);
100
-    }
82
+	/**
83
+	 * Discovers how much work there is to do, double-checks the work isn't already finished, and then does the work.
84
+	 * Note: do not call when site is in maintenance mode level 2.
85
+	 *
86
+	 * @since $VID:$
87
+	 * @param $model_objects_to_identify
88
+	 * @return int number of model objects we want to identify during this call. On subsequent calls we'll continue
89
+	 * where we left off.
90
+	 */
91
+	public function visit($model_objects_to_identify)
92
+	{
93
+		if (! $this->isDiscovered()) {
94
+			$this->discover();
95
+		}
96
+		if ($this->isComplete()) {
97
+			return 0;
98
+		}
99
+		return $this->work($model_objects_to_identify);
100
+	}
101 101
 
102
-    /**
103
-     * Gets the IDs of completely identified model objects that can be deleted.
104
-     * @since $VID:$
105
-     * @return mixed
106
-     */
107
-    abstract public function getIds();
102
+	/**
103
+	 * Gets the IDs of completely identified model objects that can be deleted.
104
+	 * @since $VID:$
105
+	 * @return mixed
106
+	 */
107
+	abstract public function getIds();
108 108
 
109
-    /**
110
-     * Make sure we encode whether its complete or not, but don't use such a long name.
111
-     * @since $VID:$
112
-     * @return array
113
-     */
114
-    public function __sleep()
115
-    {
116
-        $this->c = $this->complete;
117
-        $this->dtm = $this->dont_traverse_models;
118
-        return [
119
-            'c',
120
-            'dtm'
121
-        ];
122
-    }
109
+	/**
110
+	 * Make sure we encode whether its complete or not, but don't use such a long name.
111
+	 * @since $VID:$
112
+	 * @return array
113
+	 */
114
+	public function __sleep()
115
+	{
116
+		$this->c = $this->complete;
117
+		$this->dtm = $this->dont_traverse_models;
118
+		return [
119
+			'c',
120
+			'dtm'
121
+		];
122
+	}
123 123
 
124
-    /**
125
-     * Use the dynamic property to set the "complete" property.
126
-     * @since $VID:$
127
-     */
128
-    public function __wakeup()
129
-    {
130
-        $this->complete = $this->c;
131
-        $this->dont_traverse_models = $this->dtm;
132
-    }
124
+	/**
125
+	 * Use the dynamic property to set the "complete" property.
126
+	 * @since $VID:$
127
+	 */
128
+	public function __wakeup()
129
+	{
130
+		$this->complete = $this->c;
131
+		$this->dont_traverse_models = $this->dtm;
132
+	}
133 133
 }
134 134
 // End of file BaseNode.php
135 135
 // Location: EventEspresso\core\services\orm\tree_traversal/BaseNode.php
Please login to merge, or discard this patch.
core/services/orm/tree_traversal/RelationNode.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@
 block discarded – undo
130 130
      * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget.
131 131
      * @since $VID:$
132 132
      * @param ModelObjNode[] $model_obj_nodes
133
-     * @param $work_budget
133
+     * @param integer $work_budget
134 134
      * @return int
135 135
      */
136 136
     protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)
Please login to merge, or discard this patch.
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -2,15 +2,12 @@
 block discarded – undo
2 2
 
3 3
 namespace EventEspresso\core\services\orm\tree_traversal;
4 4
 
5
-use EE_Base_Class;
6 5
 use EE_Error;
7 6
 use EE_Has_Many_Any_Relation;
8
-use EE_Model_Relation_Base;
9 7
 use EE_Registry;
10 8
 use EEM_Base;
11 9
 use EventEspresso\core\exceptions\InvalidDataTypeException;
12 10
 use EventEspresso\core\exceptions\InvalidInterfaceException;
13
-use EventEspresso\core\services\payment_methods\forms\PayPalSettingsForm;
14 11
 use InvalidArgumentException;
15 12
 use ReflectionException;
16 13
 
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
             // Add entity nodes for each of the model objects we fetched.
94 94
             foreach ($related_model_objs as $related_model_obj) {
95 95
                 $entity_node = new ModelObjNode($related_model_obj->ID(), $related_model_obj->get_model(), $this->dont_traverse_models);
96
-                $this->nodes[ $related_model_obj->ID() ] = $entity_node;
97
-                $new_item_nodes[ $related_model_obj->ID() ] = $entity_node;
96
+                $this->nodes[$related_model_obj->ID()] = $entity_node;
97
+                $new_item_nodes[$related_model_obj->ID()] = $entity_node;
98 98
             }
99 99
             $num_identified += count($new_item_nodes);
100 100
             if ($num_identified < $model_objects_to_identify) {
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
     protected function allChildrenComplete()
121 121
     {
122 122
         foreach ($this->nodes as $model_obj_node) {
123
-            if (! $model_obj_node->isComplete()) {
123
+            if ( ! $model_obj_node->isComplete()) {
124 124
                 return false;
125 125
             }
126 126
         }
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
     protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)
138 138
     {
139 139
         $work_done = 0;
140
-        if (! $model_obj_nodes) {
140
+        if ( ! $model_obj_nodes) {
141 141
             return 0;
142 142
         }
143 143
         foreach ($model_obj_nodes as $model_obj_node) {
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
      */
200 200
     protected function whereQueryParams()
201 201
     {
202
-        $where_params =  [
202
+        $where_params = [
203 203
             $this->related_model->get_foreign_key_to(
204 204
                 $this->main_model->get_this_model_name()
205 205
             )->get_name() => $this->id
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
             $relation_settings = null;
213 213
         }
214 214
         if ($relation_settings instanceof EE_Has_Many_Any_Relation) {
215
-            $where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = $this->main_model->get_this_model_name();
215
+            $where_params[$this->related_model->get_field_containing_related_model_name()->get_name()] = $this->main_model->get_this_model_name();
216 216
         }
217 217
         return $where_params;
218 218
     }
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
             'objs' => []
229 229
         ];
230 230
         foreach ($this->nodes as $id => $model_obj_node) {
231
-            $tree['objs'][ $id ] = $model_obj_node->toArray();
231
+            $tree['objs'][$id] = $model_obj_node->toArray();
232 232
         }
233 233
         return $tree;
234 234
     }
Please login to merge, or discard this patch.
Indentation   +264 added lines, -264 removed lines patch added patch discarded remove patch
@@ -28,289 +28,289 @@
 block discarded – undo
28 28
 class RelationNode extends BaseNode
29 29
 {
30 30
 
31
-    /**
32
-     * @var string|int
33
-     */
34
-    protected $id;
31
+	/**
32
+	 * @var string|int
33
+	 */
34
+	protected $id;
35 35
 
36
-    /**
37
-     * @var EEM_Base
38
-     */
39
-    protected $main_model;
36
+	/**
37
+	 * @var EEM_Base
38
+	 */
39
+	protected $main_model;
40 40
 
41
-    /**
42
-     * @var int
43
-     */
44
-    protected $count;
41
+	/**
42
+	 * @var int
43
+	 */
44
+	protected $count;
45 45
 
46
-    /**
47
-     * @var EEM_Base
48
-     */
49
-    protected $related_model;
46
+	/**
47
+	 * @var EEM_Base
48
+	 */
49
+	protected $related_model;
50 50
 
51
-    /**
52
-     * @var ModelObjNode[]
53
-     */
54
-    protected $nodes;
51
+	/**
52
+	 * @var ModelObjNode[]
53
+	 */
54
+	protected $nodes;
55 55
 
56
-    /**
57
-     * RelationNode constructor.
58
-     * @param $main_model_obj_id
59
-     * @param EEM_Base $main_model
60
-     * @param EEM_Base $related_model
61
-     * @param array $dont_traverse_models array of model names we DON'T want to traverse
62
-     */
63
-    public function __construct(
64
-        $main_model_obj_id,
65
-        EEM_Base $main_model,
66
-        EEM_Base $related_model,
67
-        array $dont_traverse_models = []
68
-    ) {
69
-        $this->id = $main_model_obj_id;
70
-        $this->main_model = $main_model;
71
-        $this->related_model = $related_model;
72
-        $this->nodes = [];
73
-        $this->dont_traverse_models = $dont_traverse_models;
74
-    }
56
+	/**
57
+	 * RelationNode constructor.
58
+	 * @param $main_model_obj_id
59
+	 * @param EEM_Base $main_model
60
+	 * @param EEM_Base $related_model
61
+	 * @param array $dont_traverse_models array of model names we DON'T want to traverse
62
+	 */
63
+	public function __construct(
64
+		$main_model_obj_id,
65
+		EEM_Base $main_model,
66
+		EEM_Base $related_model,
67
+		array $dont_traverse_models = []
68
+	) {
69
+		$this->id = $main_model_obj_id;
70
+		$this->main_model = $main_model;
71
+		$this->related_model = $related_model;
72
+		$this->nodes = [];
73
+		$this->dont_traverse_models = $dont_traverse_models;
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * Here is where most of the work happens. We've counted how many related model objects exist, here we identify
79
-     * them (ie, learn their IDs). But its recursive, so we'll also find their related dependent model objects etc.
80
-     * @since $VID:$
81
-     * @param int $model_objects_to_identify
82
-     * @return int
83
-     * @throws EE_Error
84
-     * @throws InvalidArgumentException
85
-     * @throws InvalidDataTypeException
86
-     * @throws InvalidInterfaceException
87
-     * @throws ReflectionException
88
-     */
89
-    protected function work($model_objects_to_identify)
90
-    {
91
-        $num_identified = $this->visitAlreadyDiscoveredNodes($this->nodes, $model_objects_to_identify);
92
-        if ($num_identified < $model_objects_to_identify) {
93
-            $related_model_objs = $this->related_model->get_all(
94
-                [
95
-                    $this->whereQueryParams(),
96
-                    'limit' => [
97
-                        count($this->nodes),
98
-                        $model_objects_to_identify - $num_identified
99
-                    ]
100
-                ]
101
-            );
102
-            $new_item_nodes = [];
77
+	/**
78
+	 * Here is where most of the work happens. We've counted how many related model objects exist, here we identify
79
+	 * them (ie, learn their IDs). But its recursive, so we'll also find their related dependent model objects etc.
80
+	 * @since $VID:$
81
+	 * @param int $model_objects_to_identify
82
+	 * @return int
83
+	 * @throws EE_Error
84
+	 * @throws InvalidArgumentException
85
+	 * @throws InvalidDataTypeException
86
+	 * @throws InvalidInterfaceException
87
+	 * @throws ReflectionException
88
+	 */
89
+	protected function work($model_objects_to_identify)
90
+	{
91
+		$num_identified = $this->visitAlreadyDiscoveredNodes($this->nodes, $model_objects_to_identify);
92
+		if ($num_identified < $model_objects_to_identify) {
93
+			$related_model_objs = $this->related_model->get_all(
94
+				[
95
+					$this->whereQueryParams(),
96
+					'limit' => [
97
+						count($this->nodes),
98
+						$model_objects_to_identify - $num_identified
99
+					]
100
+				]
101
+			);
102
+			$new_item_nodes = [];
103 103
 
104
-            // Add entity nodes for each of the model objects we fetched.
105
-            foreach ($related_model_objs as $related_model_obj) {
106
-                $entity_node = new ModelObjNode($related_model_obj->ID(), $related_model_obj->get_model(), $this->dont_traverse_models);
107
-                $this->nodes[ $related_model_obj->ID() ] = $entity_node;
108
-                $new_item_nodes[ $related_model_obj->ID() ] = $entity_node;
109
-            }
110
-            $num_identified += count($new_item_nodes);
111
-            if ($num_identified < $model_objects_to_identify) {
112
-                // And lastly do the work.
113
-                $num_identified += $this->visitAlreadyDiscoveredNodes(
114
-                    $new_item_nodes,
115
-                    $model_objects_to_identify - $num_identified
116
-                );
117
-            }
118
-        }
104
+			// Add entity nodes for each of the model objects we fetched.
105
+			foreach ($related_model_objs as $related_model_obj) {
106
+				$entity_node = new ModelObjNode($related_model_obj->ID(), $related_model_obj->get_model(), $this->dont_traverse_models);
107
+				$this->nodes[ $related_model_obj->ID() ] = $entity_node;
108
+				$new_item_nodes[ $related_model_obj->ID() ] = $entity_node;
109
+			}
110
+			$num_identified += count($new_item_nodes);
111
+			if ($num_identified < $model_objects_to_identify) {
112
+				// And lastly do the work.
113
+				$num_identified += $this->visitAlreadyDiscoveredNodes(
114
+					$new_item_nodes,
115
+					$model_objects_to_identify - $num_identified
116
+				);
117
+			}
118
+		}
119 119
 
120
-        if (count($this->nodes) >= $this->count && $this->allChildrenComplete()) {
121
-            $this->complete = true;
122
-        }
123
-        return $num_identified;
124
-    }
120
+		if (count($this->nodes) >= $this->count && $this->allChildrenComplete()) {
121
+			$this->complete = true;
122
+		}
123
+		return $num_identified;
124
+	}
125 125
 
126
-    /**
127
-     * Checks if all the identified child nodes are complete or not.
128
-     * @since $VID:$
129
-     * @return bool
130
-     */
131
-    protected function allChildrenComplete()
132
-    {
133
-        foreach ($this->nodes as $model_obj_node) {
134
-            if (! $model_obj_node->isComplete()) {
135
-                return false;
136
-            }
137
-        }
138
-        return true;
139
-    }
126
+	/**
127
+	 * Checks if all the identified child nodes are complete or not.
128
+	 * @since $VID:$
129
+	 * @return bool
130
+	 */
131
+	protected function allChildrenComplete()
132
+	{
133
+		foreach ($this->nodes as $model_obj_node) {
134
+			if (! $model_obj_node->isComplete()) {
135
+				return false;
136
+			}
137
+		}
138
+		return true;
139
+	}
140 140
 
141
-    /**
142
-     * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget.
143
-     * @since $VID:$
144
-     * @param ModelObjNode[] $model_obj_nodes
145
-     * @param $work_budget
146
-     * @return int
147
-     */
148
-    protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)
149
-    {
150
-        $work_done = 0;
151
-        if (! $model_obj_nodes) {
152
-            return 0;
153
-        }
154
-        foreach ($model_obj_nodes as $model_obj_node) {
155
-            if ($work_done >= $work_budget) {
156
-                break;
157
-            }
158
-            $work_done += $model_obj_node->visit($work_budget - $work_done);
159
-        }
160
-        return $work_done;
161
-    }
141
+	/**
142
+	 * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget.
143
+	 * @since $VID:$
144
+	 * @param ModelObjNode[] $model_obj_nodes
145
+	 * @param $work_budget
146
+	 * @return int
147
+	 */
148
+	protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)
149
+	{
150
+		$work_done = 0;
151
+		if (! $model_obj_nodes) {
152
+			return 0;
153
+		}
154
+		foreach ($model_obj_nodes as $model_obj_node) {
155
+			if ($work_done >= $work_budget) {
156
+				break;
157
+			}
158
+			$work_done += $model_obj_node->visit($work_budget - $work_done);
159
+		}
160
+		return $work_done;
161
+	}
162 162
 
163
-    /**
164
-     * Whether this item has already been initialized
165
-     */
166
-    protected function isDiscovered()
167
-    {
168
-        return $this->count !== null;
169
-    }
163
+	/**
164
+	 * Whether this item has already been initialized
165
+	 */
166
+	protected function isDiscovered()
167
+	{
168
+		return $this->count !== null;
169
+	}
170 170
 
171
-    /**
172
-     * @since $VID:$
173
-     * @return boolean
174
-     */
175
-    public function isComplete()
176
-    {
177
-        if ($this->complete === null) {
178
-            if (count($this->nodes) === $this->count) {
179
-                $this->complete = true;
180
-            } else {
181
-                $this->complete = false;
182
-            }
183
-        }
184
-        return $this->complete;
185
-    }
171
+	/**
172
+	 * @since $VID:$
173
+	 * @return boolean
174
+	 */
175
+	public function isComplete()
176
+	{
177
+		if ($this->complete === null) {
178
+			if (count($this->nodes) === $this->count) {
179
+				$this->complete = true;
180
+			} else {
181
+				$this->complete = false;
182
+			}
183
+		}
184
+		return $this->complete;
185
+	}
186 186
 
187
-    /**
188
-     * Discovers how many related model objects exist.
189
-     * @since $VID:$
190
-     * @return mixed|void
191
-     * @throws EE_Error
192
-     * @throws InvalidArgumentException
193
-     * @throws InvalidDataTypeException
194
-     * @throws InvalidInterfaceException
195
-     * @throws ReflectionException
196
-     */
197
-    protected function discover()
198
-    {
199
-        $this->count = $this->related_model->count([$this->whereQueryParams()]);
200
-    }
187
+	/**
188
+	 * Discovers how many related model objects exist.
189
+	 * @since $VID:$
190
+	 * @return mixed|void
191
+	 * @throws EE_Error
192
+	 * @throws InvalidArgumentException
193
+	 * @throws InvalidDataTypeException
194
+	 * @throws InvalidInterfaceException
195
+	 * @throws ReflectionException
196
+	 */
197
+	protected function discover()
198
+	{
199
+		$this->count = $this->related_model->count([$this->whereQueryParams()]);
200
+	}
201 201
 
202
-    /**
203
-     * @since $VID:$
204
-     * @return array
205
-     * @throws EE_Error
206
-     * @throws InvalidDataTypeException
207
-     * @throws InvalidInterfaceException
208
-     * @throws InvalidArgumentException
209
-     * @throws ReflectionException
210
-     */
211
-    protected function whereQueryParams()
212
-    {
213
-        $where_params =  [
214
-            $this->related_model->get_foreign_key_to(
215
-                $this->main_model->get_this_model_name()
216
-            )->get_name() => $this->id
217
-        ];
218
-        try {
219
-            $relation_settings = $this->main_model->related_settings_for($this->related_model->get_this_model_name());
220
-        } catch (EE_Error $e) {
221
-            // This will happen for has-and-belongs-to-many relations, when this node's related model is that join table
222
-            // which hasn't been explicitly declared in the main model object's model's relations.
223
-            $relation_settings = null;
224
-        }
225
-        if ($relation_settings instanceof EE_Has_Many_Any_Relation) {
226
-            $where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = $this->main_model->get_this_model_name();
227
-        }
228
-        return $where_params;
229
-    }
230
-    /**
231
-     * @since $VID:$
232
-     * @return array
233
-     */
234
-    public function toArray()
235
-    {
236
-        $tree = [
237
-            'count' => $this->count,
238
-            'complete' => $this->isComplete(),
239
-            'objs' => []
240
-        ];
241
-        foreach ($this->nodes as $id => $model_obj_node) {
242
-            $tree['objs'][ $id ] = $model_obj_node->toArray();
243
-        }
244
-        return $tree;
245
-    }
202
+	/**
203
+	 * @since $VID:$
204
+	 * @return array
205
+	 * @throws EE_Error
206
+	 * @throws InvalidDataTypeException
207
+	 * @throws InvalidInterfaceException
208
+	 * @throws InvalidArgumentException
209
+	 * @throws ReflectionException
210
+	 */
211
+	protected function whereQueryParams()
212
+	{
213
+		$where_params =  [
214
+			$this->related_model->get_foreign_key_to(
215
+				$this->main_model->get_this_model_name()
216
+			)->get_name() => $this->id
217
+		];
218
+		try {
219
+			$relation_settings = $this->main_model->related_settings_for($this->related_model->get_this_model_name());
220
+		} catch (EE_Error $e) {
221
+			// This will happen for has-and-belongs-to-many relations, when this node's related model is that join table
222
+			// which hasn't been explicitly declared in the main model object's model's relations.
223
+			$relation_settings = null;
224
+		}
225
+		if ($relation_settings instanceof EE_Has_Many_Any_Relation) {
226
+			$where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = $this->main_model->get_this_model_name();
227
+		}
228
+		return $where_params;
229
+	}
230
+	/**
231
+	 * @since $VID:$
232
+	 * @return array
233
+	 */
234
+	public function toArray()
235
+	{
236
+		$tree = [
237
+			'count' => $this->count,
238
+			'complete' => $this->isComplete(),
239
+			'objs' => []
240
+		];
241
+		foreach ($this->nodes as $id => $model_obj_node) {
242
+			$tree['objs'][ $id ] = $model_obj_node->toArray();
243
+		}
244
+		return $tree;
245
+	}
246 246
 
247
-    /**
248
-     * Gets the IDs of all the model objects to delete; indexed first by model object name.
249
-     * @since $VID:$
250
-     * @return array
251
-     */
252
-    public function getIds()
253
-    {
254
-        if (empty($this->nodes)) {
255
-            return [];
256
-        }
257
-        $ids = [
258
-            $this->related_model->get_this_model_name() => array_combine(
259
-                array_keys($this->nodes),
260
-                array_keys($this->nodes)
261
-            )
262
-        ];
263
-        foreach ($this->nodes as $model_obj_node) {
264
-            $ids = array_replace_recursive($ids, $model_obj_node->getIds());
265
-        }
266
-        return $ids;
267
-    }
247
+	/**
248
+	 * Gets the IDs of all the model objects to delete; indexed first by model object name.
249
+	 * @since $VID:$
250
+	 * @return array
251
+	 */
252
+	public function getIds()
253
+	{
254
+		if (empty($this->nodes)) {
255
+			return [];
256
+		}
257
+		$ids = [
258
+			$this->related_model->get_this_model_name() => array_combine(
259
+				array_keys($this->nodes),
260
+				array_keys($this->nodes)
261
+			)
262
+		];
263
+		foreach ($this->nodes as $model_obj_node) {
264
+			$ids = array_replace_recursive($ids, $model_obj_node->getIds());
265
+		}
266
+		return $ids;
267
+	}
268 268
 
269
-    /**
270
-     * Returns the number of sub-nodes found (ie, related model objects across this relation.)
271
-     * @since $VID:$
272
-     * @return int
273
-     */
274
-    public function countSubNodes()
275
-    {
276
-        return count($this->nodes);
277
-    }
269
+	/**
270
+	 * Returns the number of sub-nodes found (ie, related model objects across this relation.)
271
+	 * @since $VID:$
272
+	 * @return int
273
+	 */
274
+	public function countSubNodes()
275
+	{
276
+		return count($this->nodes);
277
+	}
278 278
 
279
-    /**
280
-     * Don't serialize the models. Just record their names on some dynamic properties.
281
-     * @since $VID:$
282
-     */
283
-    public function __sleep()
284
-    {
285
-        $this->m = $this->main_model->get_this_model_name();
286
-        $this->rm = $this->related_model->get_this_model_name();
287
-        return array_merge(
288
-            [
289
-                'm',
290
-                'rm',
291
-                'id',
292
-                'count',
293
-                'nodes',
294
-            ],
295
-            parent::__sleep()
296
-        );
297
-    }
279
+	/**
280
+	 * Don't serialize the models. Just record their names on some dynamic properties.
281
+	 * @since $VID:$
282
+	 */
283
+	public function __sleep()
284
+	{
285
+		$this->m = $this->main_model->get_this_model_name();
286
+		$this->rm = $this->related_model->get_this_model_name();
287
+		return array_merge(
288
+			[
289
+				'm',
290
+				'rm',
291
+				'id',
292
+				'count',
293
+				'nodes',
294
+			],
295
+			parent::__sleep()
296
+		);
297
+	}
298 298
 
299
-    /**
300
-     * Use the dynamic properties to instantiate the models we use.
301
-     * @since $VID:$
302
-     * @throws EE_Error
303
-     * @throws InvalidArgumentException
304
-     * @throws InvalidDataTypeException
305
-     * @throws InvalidInterfaceException
306
-     * @throws ReflectionException
307
-     */
308
-    public function __wakeup()
309
-    {
310
-        $this->main_model = EE_Registry::instance()->load_model($this->m);
311
-        $this->related_model = EE_Registry::instance()->load_model($this->rm);
312
-        parent::__wakeup();
313
-    }
299
+	/**
300
+	 * Use the dynamic properties to instantiate the models we use.
301
+	 * @since $VID:$
302
+	 * @throws EE_Error
303
+	 * @throws InvalidArgumentException
304
+	 * @throws InvalidDataTypeException
305
+	 * @throws InvalidInterfaceException
306
+	 * @throws ReflectionException
307
+	 */
308
+	public function __wakeup()
309
+	{
310
+		$this->main_model = EE_Registry::instance()->load_model($this->m);
311
+		$this->related_model = EE_Registry::instance()->load_model($this->rm);
312
+		parent::__wakeup();
313
+	}
314 314
 }
315 315
 // End of file RelationNode.php
316 316
 // Location: EventEspresso\core\services\orm\tree_traversal/RelationNode.php
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlers/ExecuteBatchDeletion.php 3 patches
Unused Use Statements   -8 removed lines patch added patch discarded remove patch
@@ -4,21 +4,13 @@
 block discarded – undo
4 4
 
5 5
 use EE_Change_Log;
6 6
 use EE_Registry;
7
-use EEM_Event;
8
-use EEM_Price;
9
-use EEM_Ticket;
10
-use EventEspresso\core\exceptions\InvalidClassException;
11
-use EventEspresso\core\exceptions\InvalidDataTypeException;
12
-use EventEspresso\core\exceptions\InvalidInterfaceException;
13 7
 use EventEspresso\core\exceptions\UnexpectedEntityException;
14
-use EventEspresso\core\services\loaders\LoaderFactory;
15 8
 use EventEspresso\core\services\orm\tree_traversal\NodeGroupDao;
16 9
 use EventEspresso\core\services\orm\tree_traversal\ModelObjNode;
17 10
 use EventEspressoBatchRequest\Helpers\BatchRequestException;
18 11
 use EventEspressoBatchRequest\Helpers\JobParameters;
19 12
 use EventEspressoBatchRequest\Helpers\JobStepResponse;
20 13
 use EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandler;
21
-use InvalidArgumentException;
22 14
 
23 15
 /**
24 16
  * Class EventDeletion
Please login to merge, or discard this patch.
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -32,158 +32,158 @@
 block discarded – undo
32 32
  */
33 33
 class ExecuteBatchDeletion extends JobHandler
34 34
 {
35
-    /**
36
-     * @var NodeGroupDao
37
-     */
38
-    protected $model_obj_node_group_persister;
39
-    public function __construct(NodeGroupDao $model_obj_node_group_persister)
40
-    {
41
-        $this->model_obj_node_group_persister = $model_obj_node_group_persister;
42
-    }
35
+	/**
36
+	 * @var NodeGroupDao
37
+	 */
38
+	protected $model_obj_node_group_persister;
39
+	public function __construct(NodeGroupDao $model_obj_node_group_persister)
40
+	{
41
+		$this->model_obj_node_group_persister = $model_obj_node_group_persister;
42
+	}
43 43
 
44 44
 
45
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
46
-    /**
47
-     *
48
-     * @param JobParameters $job_parameters
49
-     * @throws BatchRequestException
50
-     * @return JobStepResponse
51
-     */
52
-    public function create_job(JobParameters $job_parameters)
53
-    {
54
-        $deletion_job_code = $job_parameters->request_datum('deletion_job_code', null);
55
-        $roots = $this->model_obj_node_group_persister->getModelObjNodesInGroup($deletion_job_code);
56
-        if ($roots === null) {
57
-            throw new UnexpectedEntityException($roots, 'array', esc_html__('The job seems to be stale. Please press the back button in your browser twice.', 'event_espresso'));
58
-        }
59
-        $models_and_ids_to_delete = [];
60
-        foreach ($roots as $root) {
61
-            if (! $root instanceof ModelObjNode) {
62
-                throw new UnexpectedEntityException($root, 'ModelObjNode');
63
-            }
64
-            $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds());
65
-        }
66
-        $job_parameters->set_extra_data(
67
-            [
68
-                'models_and_ids_to_delete' => $models_and_ids_to_delete
69
-            ]
70
-        );
71
-        // Find the job's actual size.
72
-        $job_size = 0;
73
-        foreach ($models_and_ids_to_delete as $model_name => $ids) {
74
-            $job_size += count($ids);
75
-        }
76
-        $job_parameters->set_job_size($job_size);
77
-        return new JobStepResponse(
78
-            $job_parameters,
79
-            esc_html__('Beginning to delete items...', 'event_espresso')
80
-        );
81
-    }
45
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
46
+	/**
47
+	 *
48
+	 * @param JobParameters $job_parameters
49
+	 * @throws BatchRequestException
50
+	 * @return JobStepResponse
51
+	 */
52
+	public function create_job(JobParameters $job_parameters)
53
+	{
54
+		$deletion_job_code = $job_parameters->request_datum('deletion_job_code', null);
55
+		$roots = $this->model_obj_node_group_persister->getModelObjNodesInGroup($deletion_job_code);
56
+		if ($roots === null) {
57
+			throw new UnexpectedEntityException($roots, 'array', esc_html__('The job seems to be stale. Please press the back button in your browser twice.', 'event_espresso'));
58
+		}
59
+		$models_and_ids_to_delete = [];
60
+		foreach ($roots as $root) {
61
+			if (! $root instanceof ModelObjNode) {
62
+				throw new UnexpectedEntityException($root, 'ModelObjNode');
63
+			}
64
+			$models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds());
65
+		}
66
+		$job_parameters->set_extra_data(
67
+			[
68
+				'models_and_ids_to_delete' => $models_and_ids_to_delete
69
+			]
70
+		);
71
+		// Find the job's actual size.
72
+		$job_size = 0;
73
+		foreach ($models_and_ids_to_delete as $model_name => $ids) {
74
+			$job_size += count($ids);
75
+		}
76
+		$job_parameters->set_job_size($job_size);
77
+		return new JobStepResponse(
78
+			$job_parameters,
79
+			esc_html__('Beginning to delete items...', 'event_espresso')
80
+		);
81
+	}
82 82
 
83
-    /**
84
-     * Performs another step of the job
85
-     * @param JobParameters $job_parameters
86
-     * @param int $batch_size
87
-     * @return JobStepResponse
88
-     * @throws BatchRequestException
89
-     */
90
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
91
-    {
92
-        // We already have the items IDs. So deleting is really fast. Let's speed it up.
93
-        $batch_size *= 10;
94
-        $units_processed = 0;
95
-        $models_and_ids_to_delete = $job_parameters->extra_datum('models_and_ids_to_delete', []);
96
-        // Build a new list of everything leftover after this request's of deletions.
97
-        $models_and_ids_remaining = [];
98
-        foreach ($models_and_ids_to_delete as $model_name => $ids_to_delete) {
99
-            if ($units_processed < $batch_size) {
100
-                $model = EE_Registry::instance()->load_model($model_name);
101
-                $ids_to_delete_this_query = array_slice($ids_to_delete, 0, $batch_size - $units_processed, true);
102
-                if ($model->has_primary_key_field()) {
103
-                    $where_conditions = [
104
-                        $model->primary_key_name() => [
105
-                            'IN',
106
-                            $ids_to_delete_this_query
107
-                        ]
108
-                    ];
109
-                } else {
110
-                    $where_conditions = [
111
-                        'OR' => []
112
-                    ];
113
-                    foreach ($ids_to_delete_this_query as $index_primary_key_string) {
114
-                        $keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string);
115
-                        $where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values;
116
-                    }
117
-                }
118
-                // Deleting time!
119
-                // The model's deletion method reports every ROW deleted, and in the case of CPT models that will be
120
-                // two rows deleted for event CPT item. So don't rely on it for the count of items deleted.
121
-                $model->delete_permanently(
122
-                    [
123
-                        $where_conditions
124
-                    ],
125
-                    false
126
-                );
127
-                $units_processed += count($ids_to_delete_this_query);
128
-                $remaining_ids = array_diff_key($ids_to_delete, $ids_to_delete_this_query);
129
-                // If there's any more from this model, we'll do them next time.
130
-                if (count($remaining_ids) > 0) {
131
-                    $models_and_ids_remaining[ $model_name ] = $remaining_ids;
132
-                }
133
-            } else {
134
-                $models_and_ids_remaining[ $model_name ] = $models_and_ids_to_delete[ $model_name ];
135
-            }
136
-        }
137
-        $job_parameters->mark_processed($units_processed);
138
-        // All done deleting for this request. Is there anything to do next time?
139
-        if (empty($models_and_ids_remaining)) {
140
-            $job_parameters->set_status(JobParameters::status_complete);
141
-            return new JobStepResponse(
142
-                $job_parameters,
143
-                esc_html__('Deletion complete.', 'event_espresso')
144
-            );
145
-        }
146
-        $job_parameters->add_extra_data('models_and_ids_to_delete', $models_and_ids_remaining);
147
-        return new JobStepResponse(
148
-            $job_parameters,
149
-            sprintf(
150
-                esc_html__('Deleted %d items.', 'event_espresso'),
151
-                $units_processed
152
-            )
153
-        );
154
-    }
83
+	/**
84
+	 * Performs another step of the job
85
+	 * @param JobParameters $job_parameters
86
+	 * @param int $batch_size
87
+	 * @return JobStepResponse
88
+	 * @throws BatchRequestException
89
+	 */
90
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
91
+	{
92
+		// We already have the items IDs. So deleting is really fast. Let's speed it up.
93
+		$batch_size *= 10;
94
+		$units_processed = 0;
95
+		$models_and_ids_to_delete = $job_parameters->extra_datum('models_and_ids_to_delete', []);
96
+		// Build a new list of everything leftover after this request's of deletions.
97
+		$models_and_ids_remaining = [];
98
+		foreach ($models_and_ids_to_delete as $model_name => $ids_to_delete) {
99
+			if ($units_processed < $batch_size) {
100
+				$model = EE_Registry::instance()->load_model($model_name);
101
+				$ids_to_delete_this_query = array_slice($ids_to_delete, 0, $batch_size - $units_processed, true);
102
+				if ($model->has_primary_key_field()) {
103
+					$where_conditions = [
104
+						$model->primary_key_name() => [
105
+							'IN',
106
+							$ids_to_delete_this_query
107
+						]
108
+					];
109
+				} else {
110
+					$where_conditions = [
111
+						'OR' => []
112
+					];
113
+					foreach ($ids_to_delete_this_query as $index_primary_key_string) {
114
+						$keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string);
115
+						$where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values;
116
+					}
117
+				}
118
+				// Deleting time!
119
+				// The model's deletion method reports every ROW deleted, and in the case of CPT models that will be
120
+				// two rows deleted for event CPT item. So don't rely on it for the count of items deleted.
121
+				$model->delete_permanently(
122
+					[
123
+						$where_conditions
124
+					],
125
+					false
126
+				);
127
+				$units_processed += count($ids_to_delete_this_query);
128
+				$remaining_ids = array_diff_key($ids_to_delete, $ids_to_delete_this_query);
129
+				// If there's any more from this model, we'll do them next time.
130
+				if (count($remaining_ids) > 0) {
131
+					$models_and_ids_remaining[ $model_name ] = $remaining_ids;
132
+				}
133
+			} else {
134
+				$models_and_ids_remaining[ $model_name ] = $models_and_ids_to_delete[ $model_name ];
135
+			}
136
+		}
137
+		$job_parameters->mark_processed($units_processed);
138
+		// All done deleting for this request. Is there anything to do next time?
139
+		if (empty($models_and_ids_remaining)) {
140
+			$job_parameters->set_status(JobParameters::status_complete);
141
+			return new JobStepResponse(
142
+				$job_parameters,
143
+				esc_html__('Deletion complete.', 'event_espresso')
144
+			);
145
+		}
146
+		$job_parameters->add_extra_data('models_and_ids_to_delete', $models_and_ids_remaining);
147
+		return new JobStepResponse(
148
+			$job_parameters,
149
+			sprintf(
150
+				esc_html__('Deleted %d items.', 'event_espresso'),
151
+				$units_processed
152
+			)
153
+		);
154
+	}
155 155
 
156
-    /**
157
-     * Performs any clean-up logic when we know the job is completed
158
-     * @param JobParameters $job_parameters
159
-     * @return JobStepResponse
160
-     */
161
-    public function cleanup_job(JobParameters $job_parameters)
162
-    {
163
-        $this->model_obj_node_group_persister->deleteModelObjNodesInGroup(
164
-            $job_parameters->request_datum('deletion_job_code')
165
-        );
166
-        // For backwards compatibility with how we used to delete events, make sure we still trigger the old action.
167
-        $models_and_ids_to_delete = $job_parameters->extra_datum('models_and_ids_to_delete', []);
168
-        foreach ($models_and_ids_to_delete['Event'] as $event_id) {
169
-            // Create a log entry so we know who and when this event was permanently deleted.
170
-            (EE_Change_Log::new_instance(
171
-                [
172
-                    'OBJ_ID' => $event_id,
173
-                    'OBJ_type' => 'Event',
174
-                    'LOG_message' => sprintf(
175
-                        esc_html__('Event %1$d permanently deleted using ExecuteBatchDeletion.', 'event_espresso'),
176
-                        $event_id
177
-                    )
178
-                ]
179
-            ))->save();
180
-            do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $event_id);
181
-        }
182
-        return new JobStepResponse(
183
-            $job_parameters,
184
-            esc_html__('All done', 'event_espresso')
185
-        );
186
-    }
156
+	/**
157
+	 * Performs any clean-up logic when we know the job is completed
158
+	 * @param JobParameters $job_parameters
159
+	 * @return JobStepResponse
160
+	 */
161
+	public function cleanup_job(JobParameters $job_parameters)
162
+	{
163
+		$this->model_obj_node_group_persister->deleteModelObjNodesInGroup(
164
+			$job_parameters->request_datum('deletion_job_code')
165
+		);
166
+		// For backwards compatibility with how we used to delete events, make sure we still trigger the old action.
167
+		$models_and_ids_to_delete = $job_parameters->extra_datum('models_and_ids_to_delete', []);
168
+		foreach ($models_and_ids_to_delete['Event'] as $event_id) {
169
+			// Create a log entry so we know who and when this event was permanently deleted.
170
+			(EE_Change_Log::new_instance(
171
+				[
172
+					'OBJ_ID' => $event_id,
173
+					'OBJ_type' => 'Event',
174
+					'LOG_message' => sprintf(
175
+						esc_html__('Event %1$d permanently deleted using ExecuteBatchDeletion.', 'event_espresso'),
176
+						$event_id
177
+					)
178
+				]
179
+			))->save();
180
+			do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $event_id);
181
+		}
182
+		return new JobStepResponse(
183
+			$job_parameters,
184
+			esc_html__('All done', 'event_espresso')
185
+		);
186
+	}
187 187
 }
188 188
 // End of file EventDeletion.php
189 189
 // Location: EventEspressoBatchRequest\JobHandlers/EventDeletion.php
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         }
59 59
         $models_and_ids_to_delete = [];
60 60
         foreach ($roots as $root) {
61
-            if (! $root instanceof ModelObjNode) {
61
+            if ( ! $root instanceof ModelObjNode) {
62 62
                 throw new UnexpectedEntityException($root, 'ModelObjNode');
63 63
             }
64 64
             $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds());
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
                     ];
113 113
                     foreach ($ids_to_delete_this_query as $index_primary_key_string) {
114 114
                         $keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string);
115
-                        $where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values;
115
+                        $where_conditions['OR']['AND*'.$index_primary_key_string] = $keys_n_values;
116 116
                     }
117 117
                 }
118 118
                 // Deleting time!
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
                 $remaining_ids = array_diff_key($ids_to_delete, $ids_to_delete_this_query);
129 129
                 // If there's any more from this model, we'll do them next time.
130 130
                 if (count($remaining_ids) > 0) {
131
-                    $models_and_ids_remaining[ $model_name ] = $remaining_ids;
131
+                    $models_and_ids_remaining[$model_name] = $remaining_ids;
132 132
                 }
133 133
             } else {
134
-                $models_and_ids_remaining[ $model_name ] = $models_and_ids_to_delete[ $model_name ];
134
+                $models_and_ids_remaining[$model_name] = $models_and_ids_to_delete[$model_name];
135 135
             }
136 136
         }
137 137
         $job_parameters->mark_processed($units_processed);
Please login to merge, or discard this patch.
core/services/orm/tree_traversal/NodeGroupDao.php 2 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -22,112 +22,112 @@
 block discarded – undo
22 22
  */
23 23
 class NodeGroupDao
24 24
 {
25
-    /**
26
-     * @since $VID:$
27
-     * @return mixed|void
28
-     */
29
-    public function generateGroupCode()
30
-    {
31
-        return wp_generate_password(6, false);
32
-    }
25
+	/**
26
+	 * @since $VID:$
27
+	 * @return mixed|void
28
+	 */
29
+	public function generateGroupCode()
30
+	{
31
+		return wp_generate_password(6, false);
32
+	}
33 33
 
34
-    /**
35
-     * Gets the string we put in front of the WP Option name used to store the jobs.
36
-     * @since $VID:$
37
-     * @return string
38
-     */
39
-    private function getOptionPrefix()
40
-    {
41
-        return 'ee_deletion_';
42
-    }
34
+	/**
35
+	 * Gets the string we put in front of the WP Option name used to store the jobs.
36
+	 * @since $VID:$
37
+	 * @return string
38
+	 */
39
+	private function getOptionPrefix()
40
+	{
41
+		return 'ee_deletion_';
42
+	}
43 43
 
44
-    /**
45
-     * @since $VID:$
46
-     * @param $code
47
-     * @return ModelObjNode[]
48
-     * @throws UnexpectedEntityException
49
-     */
50
-    public function getModelObjNodesInGroup($code)
51
-    {
52
-        if (! $code) {
53
-            throw new Exception(esc_html__('We aren’t sure which job you are performing. Please press back in your browser and try again.', 'event_espresso'));
54
-        }
55
-        $deletion_data = get_option($this->getOptionPrefix() . $code, []);
56
-        foreach ($deletion_data as $root) {
57
-            if (! $root instanceof ModelObjNode) {
58
-                throw new UnexpectedEntityException($root, 'ModelObjNode');
59
-            }
60
-        }
61
-        return $deletion_data;
62
-    }
44
+	/**
45
+	 * @since $VID:$
46
+	 * @param $code
47
+	 * @return ModelObjNode[]
48
+	 * @throws UnexpectedEntityException
49
+	 */
50
+	public function getModelObjNodesInGroup($code)
51
+	{
52
+		if (! $code) {
53
+			throw new Exception(esc_html__('We aren’t sure which job you are performing. Please press back in your browser and try again.', 'event_espresso'));
54
+		}
55
+		$deletion_data = get_option($this->getOptionPrefix() . $code, []);
56
+		foreach ($deletion_data as $root) {
57
+			if (! $root instanceof ModelObjNode) {
58
+				throw new UnexpectedEntityException($root, 'ModelObjNode');
59
+			}
60
+		}
61
+		return $deletion_data;
62
+	}
63 63
 
64
-    /**
65
-     * Gets an array indicating what database rows are contained in the job.
66
-     * Each top-level key is a model name, and its value is an array of IDs.
67
-     * @since $VID:$
68
-     * @param ModelObjNode[] $model_obj_nodes
69
-     * @return array
70
-     * @throws EE_Error
71
-     * @throws InvalidDataTypeException
72
-     * @throws InvalidInterfaceException
73
-     * @throws InvalidArgumentException
74
-     * @throws ReflectionException
75
-     */
76
-    public function getModelsAndIdsContainedIn($model_obj_nodes)
77
-    {
78
-        $models_and_ids_to_delete = [];
79
-        foreach ($model_obj_nodes as $root) {
80
-            $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds());
81
-        }
82
-        return $models_and_ids_to_delete;
83
-    }
64
+	/**
65
+	 * Gets an array indicating what database rows are contained in the job.
66
+	 * Each top-level key is a model name, and its value is an array of IDs.
67
+	 * @since $VID:$
68
+	 * @param ModelObjNode[] $model_obj_nodes
69
+	 * @return array
70
+	 * @throws EE_Error
71
+	 * @throws InvalidDataTypeException
72
+	 * @throws InvalidInterfaceException
73
+	 * @throws InvalidArgumentException
74
+	 * @throws ReflectionException
75
+	 */
76
+	public function getModelsAndIdsContainedIn($model_obj_nodes)
77
+	{
78
+		$models_and_ids_to_delete = [];
79
+		foreach ($model_obj_nodes as $root) {
80
+			$models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds());
81
+		}
82
+		return $models_and_ids_to_delete;
83
+	}
84 84
 
85
-    /**
86
-     * Gets an array indicating what database rows are contained in the job.
87
-     * Each top-level key is a model name, and its value is an array of IDs.
88
-     * @since $VID:$
89
-     * @param string $code
90
-     * @return array
91
-     * @throws EE_Error
92
-     * @throws InvalidArgumentException
93
-     * @throws InvalidDataTypeException
94
-     * @throws InvalidInterfaceException
95
-     * @throws ReflectionException
96
-     * @throws UnexpectedEntityException
97
-     */
98
-    public function getModelsAndIdsFromGroup($code)
99
-    {
100
-        $model_obj_nodes = $this->getModelObjNodesInGroup($code);
101
-        return $this->getModelsAndIdsContainedIn($model_obj_nodes);
102
-    }
85
+	/**
86
+	 * Gets an array indicating what database rows are contained in the job.
87
+	 * Each top-level key is a model name, and its value is an array of IDs.
88
+	 * @since $VID:$
89
+	 * @param string $code
90
+	 * @return array
91
+	 * @throws EE_Error
92
+	 * @throws InvalidArgumentException
93
+	 * @throws InvalidDataTypeException
94
+	 * @throws InvalidInterfaceException
95
+	 * @throws ReflectionException
96
+	 * @throws UnexpectedEntityException
97
+	 */
98
+	public function getModelsAndIdsFromGroup($code)
99
+	{
100
+		$model_obj_nodes = $this->getModelObjNodesInGroup($code);
101
+		return $this->getModelsAndIdsContainedIn($model_obj_nodes);
102
+	}
103 103
 
104
-    /**
105
-     * Persists the ModelObjNodes for future requests, using the code for reference.
106
-     * @since $VID:$
107
-     * @param ModelObjNode[] $model_obj_nodes
108
-     * @param string $code
109
-     * @return bool
110
-     */
111
-    public function persistModelObjNodesGroup($model_obj_nodes, $code)
112
-    {
113
-        return add_option(
114
-            $this->getOptionPrefix() . $code,
115
-            $model_obj_nodes,
116
-            null,
117
-            'no'
118
-        );
119
-    }
104
+	/**
105
+	 * Persists the ModelObjNodes for future requests, using the code for reference.
106
+	 * @since $VID:$
107
+	 * @param ModelObjNode[] $model_obj_nodes
108
+	 * @param string $code
109
+	 * @return bool
110
+	 */
111
+	public function persistModelObjNodesGroup($model_obj_nodes, $code)
112
+	{
113
+		return add_option(
114
+			$this->getOptionPrefix() . $code,
115
+			$model_obj_nodes,
116
+			null,
117
+			'no'
118
+		);
119
+	}
120 120
 
121
-    /**
122
-     * Forgets about the group of ModelObjNodes. Doesn't delete the rows in the database they reference though.
123
-     * @since $VID:$
124
-     * @param $code
125
-     * @return bool
126
-     */
127
-    public function deleteModelObjNodesInGroup($code)
128
-    {
129
-        return delete_option($this->getOptionPrefix() . $code);
130
-    }
121
+	/**
122
+	 * Forgets about the group of ModelObjNodes. Doesn't delete the rows in the database they reference though.
123
+	 * @since $VID:$
124
+	 * @param $code
125
+	 * @return bool
126
+	 */
127
+	public function deleteModelObjNodesInGroup($code)
128
+	{
129
+		return delete_option($this->getOptionPrefix() . $code);
130
+	}
131 131
 }
132 132
 // End of file NodeGroupDao.php
133 133
 // Location: EventEspresso\core\services\orm\tree_traversal/NodeGroupDao.php
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -49,12 +49,12 @@  discard block
 block discarded – undo
49 49
      */
50 50
     public function getModelObjNodesInGroup($code)
51 51
     {
52
-        if (! $code) {
52
+        if ( ! $code) {
53 53
             throw new Exception(esc_html__('We aren’t sure which job you are performing. Please press back in your browser and try again.', 'event_espresso'));
54 54
         }
55
-        $deletion_data = get_option($this->getOptionPrefix() . $code, []);
55
+        $deletion_data = get_option($this->getOptionPrefix().$code, []);
56 56
         foreach ($deletion_data as $root) {
57
-            if (! $root instanceof ModelObjNode) {
57
+            if ( ! $root instanceof ModelObjNode) {
58 58
                 throw new UnexpectedEntityException($root, 'ModelObjNode');
59 59
             }
60 60
         }
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
     public function persistModelObjNodesGroup($model_obj_nodes, $code)
112 112
     {
113 113
         return add_option(
114
-            $this->getOptionPrefix() . $code,
114
+            $this->getOptionPrefix().$code,
115 115
             $model_obj_nodes,
116 116
             null,
117 117
             'no'
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
      */
127 127
     public function deleteModelObjNodesInGroup($code)
128 128
     {
129
-        return delete_option($this->getOptionPrefix() . $code);
129
+        return delete_option($this->getOptionPrefix().$code);
130 130
     }
131 131
 }
132 132
 // End of file NodeGroupDao.php
Please login to merge, or discard this patch.
core/domain/services/admin/events/data/ConfirmDeletion.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -30,86 +30,86 @@
 block discarded – undo
30 30
  */
31 31
 class ConfirmDeletion
32 32
 {
33
-    /**
34
-     * @var NodeGroupDao
35
-     */
36
-    private $dao;
33
+	/**
34
+	 * @var NodeGroupDao
35
+	 */
36
+	private $dao;
37 37
 
38
-    /**
39
-     * ConfirmDeletion constructor.
40
-     * @param NodeGroupDao $dao
41
-     */
42
-    public function __construct(
43
-        NodeGroupDao $dao
44
-    ) {
38
+	/**
39
+	 * ConfirmDeletion constructor.
40
+	 * @param NodeGroupDao $dao
41
+	 */
42
+	public function __construct(
43
+		NodeGroupDao $dao
44
+	) {
45 45
 
46
-        $this->dao = $dao;
47
-    }
46
+		$this->dao = $dao;
47
+	}
48 48
 
49
-    /**
50
-     * Redirects to the batch job for deleting events if the form submission is valid, otherwise back to the deletion
51
-     * preview page.
52
-     * @since $VID:$
53
-     * @param $request_data
54
-     * @param $admin_base_url
55
-     * @throws EE_Error
56
-     * @throws InvalidArgumentException
57
-     * @throws InvalidDataTypeException
58
-     * @throws InvalidInterfaceException
59
-     * @throws ReflectionException
60
-     * @throws UnexpectedEntityException
61
-     */
62
-    public function handle($request_data, $admin_base_url)
63
-    {
64
-        $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : '';
65
-        $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code);
66
-        $form = new ConfirmEventDeletionForm($models_and_ids_to_delete['Event']);
67
-        // Initialize the form from the request, and check if its valid.
68
-        $form->receive_form_submission($request_data);
69
-        if ($form->is_valid()) {
70
-            // Redirect the user to the deletion batch job.
71
-            EEH_URL::safeRedirectAndExit(
72
-                EE_Admin_Page::add_query_args_and_nonce(
73
-                    array(
74
-                        'page' => 'espresso_batch',
75
-                        'batch' => EED_Batch::batch_job,
76
-                        'deletion_job_code' => $deletion_job_code,
77
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion'),
78
-                        'return_url' => urlencode(
79
-                            add_query_arg(
80
-                                [
81
-                                    'status' => 'trash'
82
-                                ],
83
-                                EVENTS_ADMIN_URL
84
-                            )
85
-                        )
86
-                    ),
87
-                    admin_url()
88
-                )
89
-            );
90
-        }
91
-        // Dont' use $form->submission_error_message() because it adds the form input's label in front
92
-        // of each validation error which ends up looking quite confusing.
93
-        $validation_errors = $form->get_validation_errors_accumulated();
94
-        foreach ($validation_errors as $validation_error) {
95
-            EE_Error::add_error(
96
-                $validation_error->getMessage(),
97
-                __FILE__,
98
-                __FUNCTION__,
99
-                __LINE__
100
-            );
101
-        }
49
+	/**
50
+	 * Redirects to the batch job for deleting events if the form submission is valid, otherwise back to the deletion
51
+	 * preview page.
52
+	 * @since $VID:$
53
+	 * @param $request_data
54
+	 * @param $admin_base_url
55
+	 * @throws EE_Error
56
+	 * @throws InvalidArgumentException
57
+	 * @throws InvalidDataTypeException
58
+	 * @throws InvalidInterfaceException
59
+	 * @throws ReflectionException
60
+	 * @throws UnexpectedEntityException
61
+	 */
62
+	public function handle($request_data, $admin_base_url)
63
+	{
64
+		$deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : '';
65
+		$models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code);
66
+		$form = new ConfirmEventDeletionForm($models_and_ids_to_delete['Event']);
67
+		// Initialize the form from the request, and check if its valid.
68
+		$form->receive_form_submission($request_data);
69
+		if ($form->is_valid()) {
70
+			// Redirect the user to the deletion batch job.
71
+			EEH_URL::safeRedirectAndExit(
72
+				EE_Admin_Page::add_query_args_and_nonce(
73
+					array(
74
+						'page' => 'espresso_batch',
75
+						'batch' => EED_Batch::batch_job,
76
+						'deletion_job_code' => $deletion_job_code,
77
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion'),
78
+						'return_url' => urlencode(
79
+							add_query_arg(
80
+								[
81
+									'status' => 'trash'
82
+								],
83
+								EVENTS_ADMIN_URL
84
+							)
85
+						)
86
+					),
87
+					admin_url()
88
+				)
89
+			);
90
+		}
91
+		// Dont' use $form->submission_error_message() because it adds the form input's label in front
92
+		// of each validation error which ends up looking quite confusing.
93
+		$validation_errors = $form->get_validation_errors_accumulated();
94
+		foreach ($validation_errors as $validation_error) {
95
+			EE_Error::add_error(
96
+				$validation_error->getMessage(),
97
+				__FILE__,
98
+				__FUNCTION__,
99
+				__LINE__
100
+			);
101
+		}
102 102
 
103
-        EEH_URL::safeRedirectAndExit(
104
-            EE_Admin_Page::add_query_args_and_nonce(
105
-                [
106
-                    'action' => 'preview_deletion',
107
-                    'deletion_job_code' => $deletion_job_code
108
-                ],
109
-                $admin_base_url
110
-            )
111
-        );
112
-    }
103
+		EEH_URL::safeRedirectAndExit(
104
+			EE_Admin_Page::add_query_args_and_nonce(
105
+				[
106
+					'action' => 'preview_deletion',
107
+					'deletion_job_code' => $deletion_job_code
108
+				],
109
+				$admin_base_url
110
+			)
111
+		);
112
+	}
113 113
 }
114 114
 // End of file ConfirmDeletion.php
115 115
 // Location: EventEspresso\core\domain\services\admin\events\data/ConfirmDeletion.php
Please login to merge, or discard this patch.
core/domain/services/admin/events/data/PreviewDeletion.php 2 patches
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -31,127 +31,127 @@
 block discarded – undo
31 31
  */
32 32
 class PreviewDeletion
33 33
 {
34
-    /**
35
-     * @var NodeGroupDao
36
-     */
37
-    protected $dao;
34
+	/**
35
+	 * @var NodeGroupDao
36
+	 */
37
+	protected $dao;
38 38
 
39
-    /**
40
-     * @var EEM_Event
41
-     */
42
-    protected $event_model;
39
+	/**
40
+	 * @var EEM_Event
41
+	 */
42
+	protected $event_model;
43 43
 
44
-    /**
45
-     * @var EEM_Datetime
46
-     */
47
-    protected $datetime_model;
44
+	/**
45
+	 * @var EEM_Datetime
46
+	 */
47
+	protected $datetime_model;
48 48
 
49
-    /**
50
-     * @var EEM_Registration
51
-     */
52
-    protected $registration_model;
49
+	/**
50
+	 * @var EEM_Registration
51
+	 */
52
+	protected $registration_model;
53 53
 
54
-    /**
55
-     * PreviewDeletion constructor.
56
-     * @param NodeGroupDao $dao
57
-     * @param EEM_Event $event_model
58
-     * @param EEM_Datetime $datetime_model
59
-     * @param EEM_Registration $registration_model
60
-     */
61
-    public function __construct(
62
-        NodeGroupDao $dao,
63
-        EEM_Event $event_model,
64
-        EEM_Datetime $datetime_model,
65
-        EEM_Registration $registration_model
66
-    ) {
67
-        $this->dao = $dao;
68
-        $this->event_model = $event_model;
69
-        $this->datetime_model = $datetime_model;
70
-        $this->registration_model = $registration_model;
71
-    }
54
+	/**
55
+	 * PreviewDeletion constructor.
56
+	 * @param NodeGroupDao $dao
57
+	 * @param EEM_Event $event_model
58
+	 * @param EEM_Datetime $datetime_model
59
+	 * @param EEM_Registration $registration_model
60
+	 */
61
+	public function __construct(
62
+		NodeGroupDao $dao,
63
+		EEM_Event $event_model,
64
+		EEM_Datetime $datetime_model,
65
+		EEM_Registration $registration_model
66
+	) {
67
+		$this->dao = $dao;
68
+		$this->event_model = $event_model;
69
+		$this->datetime_model = $datetime_model;
70
+		$this->registration_model = $registration_model;
71
+	}
72 72
 
73
-    /**
74
-     * Renders the preview deletion page.
75
-     * @since $VID:$
76
-     * @param $request_data
77
-     * @param $admin_base_url
78
-     * @return array
79
-     * @throws UnexpectedEntityException
80
-     * @throws DomainException
81
-     * @throws EE_Error
82
-     * @throws InvalidDataTypeException
83
-     * @throws InvalidInterfaceException
84
-     * @throws InvalidArgumentException
85
-     * @throws ReflectionException
86
-     */
87
-    public function handle($request_data, $admin_base_url)
88
-    {
89
-        $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : '';
90
-        $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code);
91
-        $event_ids = isset($models_and_ids_to_delete['Event']) ? $models_and_ids_to_delete['Event'] : array();
92
-        if (empty($event_ids) || !is_array($event_ids)) {
93
-            throw new EE_Error(
94
-                esc_html__('No Events were found to delete.', 'event_espresso')
95
-            );
96
-        }
97
-        $datetime_ids = isset($models_and_ids_to_delete['Datetime']) ? $models_and_ids_to_delete['Datetime'] : array();
98
-        if (!is_array($datetime_ids)) {
99
-            throw new UnexpectedEntityException($datetime_ids, 'array');
100
-        }
101
-        $registration_ids = isset($models_and_ids_to_delete['Registration']) ? $models_and_ids_to_delete['Registration'] : array();
102
-        if (!is_array($registration_ids)) {
103
-            throw new UnexpectedEntityException($registration_ids, 'array');
104
-        }
105
-        $num_registrations_to_show = 10;
106
-        $reg_count = count($registration_ids);
107
-        if ($reg_count > $num_registrations_to_show) {
108
-            $registration_ids = array_slice($registration_ids, 0, $num_registrations_to_show);
109
-        }
110
-        $form = new ConfirmEventDeletionForm($event_ids);
111
-        $events = $this->event_model->get_all_deleted_and_undeleted(
112
-            [
113
-                [
114
-                    'EVT_ID' => ['IN', $event_ids]
115
-                ]
116
-            ]
117
-        );
118
-        $datetimes = $this->datetime_model->get_all_deleted_and_undeleted(
119
-            [
120
-                [
121
-                    'DTT_ID' => ['IN', $datetime_ids]
122
-                ]
123
-            ]
124
-        );
125
-        $registrations = $this->registration_model->get_all_deleted_and_undeleted(
126
-            [
127
-                [
128
-                    'REG_ID' => ['IN', $registration_ids]
129
-                ]
130
-            ]
131
-        );
132
-        $confirm_deletion_args = [
133
-            'action' => 'confirm_deletion',
134
-            'deletion_job_code' => $deletion_job_code
135
-        ];
136
-        return [
137
-            'admin_page_content' => EEH_Template::display_template(
138
-                EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php',
139
-                [
140
-                    'form_url' => EE_Admin_Page::add_query_args_and_nonce(
141
-                        $confirm_deletion_args,
142
-                        $admin_base_url
143
-                    ),
144
-                    'form' => $form,
145
-                    'events' => $events,
146
-                    'datetimes' => $datetimes,
147
-                    'registrations' => $registrations,
148
-                    'reg_count' => $reg_count,
149
-                    'num_registrations_to_show' => $num_registrations_to_show
150
-                ],
151
-                true
152
-            )
153
-        ];
154
-    }
73
+	/**
74
+	 * Renders the preview deletion page.
75
+	 * @since $VID:$
76
+	 * @param $request_data
77
+	 * @param $admin_base_url
78
+	 * @return array
79
+	 * @throws UnexpectedEntityException
80
+	 * @throws DomainException
81
+	 * @throws EE_Error
82
+	 * @throws InvalidDataTypeException
83
+	 * @throws InvalidInterfaceException
84
+	 * @throws InvalidArgumentException
85
+	 * @throws ReflectionException
86
+	 */
87
+	public function handle($request_data, $admin_base_url)
88
+	{
89
+		$deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : '';
90
+		$models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code);
91
+		$event_ids = isset($models_and_ids_to_delete['Event']) ? $models_and_ids_to_delete['Event'] : array();
92
+		if (empty($event_ids) || !is_array($event_ids)) {
93
+			throw new EE_Error(
94
+				esc_html__('No Events were found to delete.', 'event_espresso')
95
+			);
96
+		}
97
+		$datetime_ids = isset($models_and_ids_to_delete['Datetime']) ? $models_and_ids_to_delete['Datetime'] : array();
98
+		if (!is_array($datetime_ids)) {
99
+			throw new UnexpectedEntityException($datetime_ids, 'array');
100
+		}
101
+		$registration_ids = isset($models_and_ids_to_delete['Registration']) ? $models_and_ids_to_delete['Registration'] : array();
102
+		if (!is_array($registration_ids)) {
103
+			throw new UnexpectedEntityException($registration_ids, 'array');
104
+		}
105
+		$num_registrations_to_show = 10;
106
+		$reg_count = count($registration_ids);
107
+		if ($reg_count > $num_registrations_to_show) {
108
+			$registration_ids = array_slice($registration_ids, 0, $num_registrations_to_show);
109
+		}
110
+		$form = new ConfirmEventDeletionForm($event_ids);
111
+		$events = $this->event_model->get_all_deleted_and_undeleted(
112
+			[
113
+				[
114
+					'EVT_ID' => ['IN', $event_ids]
115
+				]
116
+			]
117
+		);
118
+		$datetimes = $this->datetime_model->get_all_deleted_and_undeleted(
119
+			[
120
+				[
121
+					'DTT_ID' => ['IN', $datetime_ids]
122
+				]
123
+			]
124
+		);
125
+		$registrations = $this->registration_model->get_all_deleted_and_undeleted(
126
+			[
127
+				[
128
+					'REG_ID' => ['IN', $registration_ids]
129
+				]
130
+			]
131
+		);
132
+		$confirm_deletion_args = [
133
+			'action' => 'confirm_deletion',
134
+			'deletion_job_code' => $deletion_job_code
135
+		];
136
+		return [
137
+			'admin_page_content' => EEH_Template::display_template(
138
+				EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php',
139
+				[
140
+					'form_url' => EE_Admin_Page::add_query_args_and_nonce(
141
+						$confirm_deletion_args,
142
+						$admin_base_url
143
+					),
144
+					'form' => $form,
145
+					'events' => $events,
146
+					'datetimes' => $datetimes,
147
+					'registrations' => $registrations,
148
+					'reg_count' => $reg_count,
149
+					'num_registrations_to_show' => $num_registrations_to_show
150
+				],
151
+				true
152
+			)
153
+		];
154
+	}
155 155
 }
156 156
 // End of file PreviewDeletion.php
157 157
 // Location: EventEspresso\core\domain\services\admin\events\data/PreviewDeletion.php
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -89,17 +89,17 @@  discard block
 block discarded – undo
89 89
         $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : '';
90 90
         $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code);
91 91
         $event_ids = isset($models_and_ids_to_delete['Event']) ? $models_and_ids_to_delete['Event'] : array();
92
-        if (empty($event_ids) || !is_array($event_ids)) {
92
+        if (empty($event_ids) || ! is_array($event_ids)) {
93 93
             throw new EE_Error(
94 94
                 esc_html__('No Events were found to delete.', 'event_espresso')
95 95
             );
96 96
         }
97 97
         $datetime_ids = isset($models_and_ids_to_delete['Datetime']) ? $models_and_ids_to_delete['Datetime'] : array();
98
-        if (!is_array($datetime_ids)) {
98
+        if ( ! is_array($datetime_ids)) {
99 99
             throw new UnexpectedEntityException($datetime_ids, 'array');
100 100
         }
101 101
         $registration_ids = isset($models_and_ids_to_delete['Registration']) ? $models_and_ids_to_delete['Registration'] : array();
102
-        if (!is_array($registration_ids)) {
102
+        if ( ! is_array($registration_ids)) {
103 103
             throw new UnexpectedEntityException($registration_ids, 'array');
104 104
         }
105 105
         $num_registrations_to_show = 10;
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
         ];
136 136
         return [
137 137
             'admin_page_content' => EEH_Template::display_template(
138
-                EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php',
138
+                EVENTS_TEMPLATE_PATH.'event_preview_deletion.template.php',
139 139
                 [
140 140
                     'form_url' => EE_Admin_Page::add_query_args_and_nonce(
141 141
                         $confirm_deletion_args,
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlers/PreviewEventDeletion.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -199,7 +199,7 @@
 block discarded – undo
199 199
             if ($units_processed >= $batch_size) {
200 200
                 break;
201 201
             }
202
-            if (!$root_node instanceof ModelObjNode) {
202
+            if ( ! $root_node instanceof ModelObjNode) {
203 203
                 throw new InvalidClassException('ModelObjNode');
204 204
             }
205 205
             if ($root_node->isComplete()) {
Please login to merge, or discard this patch.
Indentation   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -36,149 +36,149 @@  discard block
 block discarded – undo
36 36
 class PreviewEventDeletion extends JobHandler
37 37
 {
38 38
 
39
-    /**
40
-     * @var NodeGroupDao
41
-     */
42
-    protected $model_obj_node_group_persister;
39
+	/**
40
+	 * @var NodeGroupDao
41
+	 */
42
+	protected $model_obj_node_group_persister;
43 43
 
44
-    public function __construct(NodeGroupDao $model_obj_node_group_persister)
45
-    {
46
-        $this->model_obj_node_group_persister = $model_obj_node_group_persister;
47
-    }
44
+	public function __construct(NodeGroupDao $model_obj_node_group_persister)
45
+	{
46
+		$this->model_obj_node_group_persister = $model_obj_node_group_persister;
47
+	}
48 48
 
49
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
49
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
50 50
 
51
-    /**
52
-     *
53
-     * @param JobParameters $job_parameters
54
-     * @return JobStepResponse
55
-     * @throws EE_Error
56
-     * @throws InvalidDataTypeException
57
-     * @throws InvalidInterfaceException
58
-     * @throws InvalidArgumentException
59
-     * @throws ReflectionException
60
-     */
61
-    public function create_job(JobParameters $job_parameters)
62
-    {
63
-        // Set the "root" model objects we will want to delete (record their ID and model)
64
-        $event_ids = $job_parameters->request_datum('EVT_IDs', array());
65
-        // Find all the root nodes to delete (this isn't just events, because there's other data, like related tickets,
66
-        // prices, message templates, etc, whose model definition doesn't make them dependent on events. But,
67
-        // we have no UI to access them independent of events, so they may as well get deleted too.)
68
-        $roots = [];
69
-        foreach ($event_ids as $event_id) {
70
-            $roots[] = new ModelObjNode(
71
-                $event_id,
72
-                EEM_Event::instance()
73
-            );
74
-            // Also, we want to delete their related, non-global, tickets, prices and message templates
75
-            $related_non_global_tickets = EEM_Ticket::instance()->get_all_deleted_and_undeleted(
76
-                [
77
-                    [
78
-                        'TKT_is_default' => false,
79
-                        'Datetime.EVT_ID' => $event_id
80
-                    ]
81
-                ]
82
-            );
83
-            foreach ($related_non_global_tickets as $ticket) {
84
-                $roots[] = new ModelObjNode(
85
-                    $ticket->ID(),
86
-                    $ticket->get_model(),
87
-                    ['Registration']
88
-                );
89
-            }
90
-            $related_non_global_prices = EEM_Price::instance()->get_all_deleted_and_undeleted(
91
-                [
92
-                    [
93
-                        'PRC_is_default' => false,
94
-                        'Ticket.Datetime.EVT_ID' => $event_id
95
-                    ]
96
-                ]
97
-            );
98
-            foreach ($related_non_global_prices as $price) {
99
-                $roots[] = new ModelObjNode(
100
-                    $price->ID(),
101
-                    $price->get_model()
102
-                );
103
-            }
104
-        }
105
-        $transactions_ids = $this->getTransactionsToDelete($event_ids);
106
-        foreach ($transactions_ids as $transaction_id) {
107
-            $roots[] = new ModelObjNode(
108
-                $transaction_id,
109
-                EEM_Transaction::instance(),
110
-                ['Registration']
111
-            );
112
-        }
113
-        $job_parameters->add_extra_data('roots', $roots);
114
-        // Set an estimate of how long this will take (we're discovering as we go, so it seems impossible to give
115
-        // an accurate count.)
116
-        $estimated_work_per_model_obj = 10;
117
-        $count_regs = EEM_Registration::instance()->count(
118
-            [
119
-                [
120
-                    'EVT_ID' => ['IN', $event_ids]
121
-                ]
122
-            ]
123
-        );
124
-        $job_parameters->set_job_size((count($roots) + $count_regs) * $estimated_work_per_model_obj);
125
-        return new JobStepResponse(
126
-            $job_parameters,
127
-            esc_html__('Generating preview of data to be deleted...', 'event_espresso')
128
-        );
129
-    }
51
+	/**
52
+	 *
53
+	 * @param JobParameters $job_parameters
54
+	 * @return JobStepResponse
55
+	 * @throws EE_Error
56
+	 * @throws InvalidDataTypeException
57
+	 * @throws InvalidInterfaceException
58
+	 * @throws InvalidArgumentException
59
+	 * @throws ReflectionException
60
+	 */
61
+	public function create_job(JobParameters $job_parameters)
62
+	{
63
+		// Set the "root" model objects we will want to delete (record their ID and model)
64
+		$event_ids = $job_parameters->request_datum('EVT_IDs', array());
65
+		// Find all the root nodes to delete (this isn't just events, because there's other data, like related tickets,
66
+		// prices, message templates, etc, whose model definition doesn't make them dependent on events. But,
67
+		// we have no UI to access them independent of events, so they may as well get deleted too.)
68
+		$roots = [];
69
+		foreach ($event_ids as $event_id) {
70
+			$roots[] = new ModelObjNode(
71
+				$event_id,
72
+				EEM_Event::instance()
73
+			);
74
+			// Also, we want to delete their related, non-global, tickets, prices and message templates
75
+			$related_non_global_tickets = EEM_Ticket::instance()->get_all_deleted_and_undeleted(
76
+				[
77
+					[
78
+						'TKT_is_default' => false,
79
+						'Datetime.EVT_ID' => $event_id
80
+					]
81
+				]
82
+			);
83
+			foreach ($related_non_global_tickets as $ticket) {
84
+				$roots[] = new ModelObjNode(
85
+					$ticket->ID(),
86
+					$ticket->get_model(),
87
+					['Registration']
88
+				);
89
+			}
90
+			$related_non_global_prices = EEM_Price::instance()->get_all_deleted_and_undeleted(
91
+				[
92
+					[
93
+						'PRC_is_default' => false,
94
+						'Ticket.Datetime.EVT_ID' => $event_id
95
+					]
96
+				]
97
+			);
98
+			foreach ($related_non_global_prices as $price) {
99
+				$roots[] = new ModelObjNode(
100
+					$price->ID(),
101
+					$price->get_model()
102
+				);
103
+			}
104
+		}
105
+		$transactions_ids = $this->getTransactionsToDelete($event_ids);
106
+		foreach ($transactions_ids as $transaction_id) {
107
+			$roots[] = new ModelObjNode(
108
+				$transaction_id,
109
+				EEM_Transaction::instance(),
110
+				['Registration']
111
+			);
112
+		}
113
+		$job_parameters->add_extra_data('roots', $roots);
114
+		// Set an estimate of how long this will take (we're discovering as we go, so it seems impossible to give
115
+		// an accurate count.)
116
+		$estimated_work_per_model_obj = 10;
117
+		$count_regs = EEM_Registration::instance()->count(
118
+			[
119
+				[
120
+					'EVT_ID' => ['IN', $event_ids]
121
+				]
122
+			]
123
+		);
124
+		$job_parameters->set_job_size((count($roots) + $count_regs) * $estimated_work_per_model_obj);
125
+		return new JobStepResponse(
126
+			$job_parameters,
127
+			esc_html__('Generating preview of data to be deleted...', 'event_espresso')
128
+		);
129
+	}
130 130
 
131
-    /**
132
-     * @since $VID:$
133
-     * @param EE_Base_Class[] $model_objs
134
-     * @param array $dont_traverse_models
135
-     * @return array
136
-     * @throws EE_Error
137
-     * @throws InvalidArgumentException
138
-     * @throws InvalidDataTypeException
139
-     * @throws InvalidInterfaceException
140
-     * @throws ReflectionException
141
-     */
142
-    protected function createModelObjNodes($model_objs, array $dont_traverse_models = [])
143
-    {
144
-        $nodes = [];
145
-        foreach ($model_objs as $model_obj) {
146
-            $nodes[] = new ModelObjNode(
147
-                $model_obj->ID(),
148
-                $model_obj->get_model(),
149
-                $dont_traverse_models
150
-            );
151
-        }
152
-        return $nodes;
153
-    }
131
+	/**
132
+	 * @since $VID:$
133
+	 * @param EE_Base_Class[] $model_objs
134
+	 * @param array $dont_traverse_models
135
+	 * @return array
136
+	 * @throws EE_Error
137
+	 * @throws InvalidArgumentException
138
+	 * @throws InvalidDataTypeException
139
+	 * @throws InvalidInterfaceException
140
+	 * @throws ReflectionException
141
+	 */
142
+	protected function createModelObjNodes($model_objs, array $dont_traverse_models = [])
143
+	{
144
+		$nodes = [];
145
+		foreach ($model_objs as $model_obj) {
146
+			$nodes[] = new ModelObjNode(
147
+				$model_obj->ID(),
148
+				$model_obj->get_model(),
149
+				$dont_traverse_models
150
+			);
151
+		}
152
+		return $nodes;
153
+	}
154 154
 
155
-    /**
156
-     * Gets all the transactions related to these events that aren't related to other events. They'll be deleted too.
157
-     * (Ones that are related to other events can stay around until those other events are deleted too.)
158
-     * @since $VID:$
159
-     * @param $event_ids
160
-     * @return array of transaction IDs
161
-     */
162
-    protected function getTransactionsToDelete($event_ids)
163
-    {
164
-        if (empty($event_ids)) {
165
-            return [];
166
-        }
167
-        global $wpdb;
168
-        $event_ids = array_map(
169
-            'intval',
170
-            $event_ids
171
-        );
172
-        $imploded_sanitized_event_ids = implode(',', $event_ids);
173
-        // Select transactions with registrations for the events $event_ids which also don't have registrations
174
-        // for any events NOT in $event_ids.
175
-        // Notice the outer query searched for transactions whose registrations ARE in $event_ids,
176
-        // whereas the inner query checks if the outer query's transaction has any registrations that are
177
-        // NOT IN $event_ids (ie, don't have registrations for events we're not just about to delete.)
178
-        return array_map(
179
-            'intval',
180
-            $wpdb->get_col(
181
-                "SELECT 
155
+	/**
156
+	 * Gets all the transactions related to these events that aren't related to other events. They'll be deleted too.
157
+	 * (Ones that are related to other events can stay around until those other events are deleted too.)
158
+	 * @since $VID:$
159
+	 * @param $event_ids
160
+	 * @return array of transaction IDs
161
+	 */
162
+	protected function getTransactionsToDelete($event_ids)
163
+	{
164
+		if (empty($event_ids)) {
165
+			return [];
166
+		}
167
+		global $wpdb;
168
+		$event_ids = array_map(
169
+			'intval',
170
+			$event_ids
171
+		);
172
+		$imploded_sanitized_event_ids = implode(',', $event_ids);
173
+		// Select transactions with registrations for the events $event_ids which also don't have registrations
174
+		// for any events NOT in $event_ids.
175
+		// Notice the outer query searched for transactions whose registrations ARE in $event_ids,
176
+		// whereas the inner query checks if the outer query's transaction has any registrations that are
177
+		// NOT IN $event_ids (ie, don't have registrations for events we're not just about to delete.)
178
+		return array_map(
179
+			'intval',
180
+			$wpdb->get_col(
181
+				"SELECT 
182 182
                       DISTINCT t.TXN_ID
183 183
                     FROM 
184 184
                       {$wpdb->prefix}esp_transaction t INNER JOIN 
@@ -196,84 +196,84 @@  discard block
 block discarded – undo
196 196
                            tsub.TXN_ID=t.TXN_ID AND
197 197
                            rsub.EVT_ID NOT IN ({$imploded_sanitized_event_ids})
198 198
                        )"
199
-            )
200
-        );
201
-    }
199
+			)
200
+		);
201
+	}
202 202
 
203
-    /**
204
-     * Performs another step of the job
205
-     * @param JobParameters $job_parameters
206
-     * @param int $batch_size
207
-     * @return JobStepResponse
208
-     * @throws BatchRequestException
209
-     */
210
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
211
-    {
212
-        // Serializing and unserializing is what really makes this drag on (eg on localhost, the ajax requests took
213
-        // about 4 seconds when the batch size was 250, but 3 seconds when the batch size was 50. So like
214
-        // 50% of the request is just serializing and unserializing.) So, make the batches much bigger.
215
-        $batch_size *= 3;
216
-        $units_processed = 0;
217
-        foreach ($job_parameters->extra_datum('roots', array()) as $root_node) {
218
-            if ($units_processed >= $batch_size) {
219
-                break;
220
-            }
221
-            if (!$root_node instanceof ModelObjNode) {
222
-                throw new InvalidClassException('ModelObjNode');
223
-            }
224
-            if ($root_node->isComplete()) {
225
-                continue;
226
-            }
227
-            $units_processed += $root_node->visit($batch_size - $units_processed);
228
-        }
229
-        $job_parameters->mark_processed($units_processed);
230
-        // If the most-recently processed root node is complete, we must be all done because we're doing them
231
-        // sequentially.
232
-        if (isset($root_node) && $root_node instanceof ModelObjNode && $root_node->isComplete()) {
233
-            $job_parameters->set_status(JobParameters::status_complete);
234
-            // Show a full progress bar.
235
-            $job_parameters->set_units_processed($job_parameters->job_size());
236
-            $deletion_job_code = $job_parameters->request_datum('deletion_job_code');
237
-            $this->model_obj_node_group_persister->persistModelObjNodesGroup(
238
-                $job_parameters->extra_datum('roots'),
239
-                $deletion_job_code
240
-            );
241
-            return new JobStepResponse(
242
-                $job_parameters,
243
-                esc_html__('Finished identifying items for deletion.', 'event_espresso'),
244
-                [
245
-                    'deletion_job_code' => $deletion_job_code
246
-                ]
247
-            );
248
-        } else {
249
-            // Because the job size was a guess, it may have likely been provden wrong. We don't want to show more work
250
-            // done than we originally said there would be. So adjust the estimate.
251
-            if (($job_parameters->units_processed() / $job_parameters->job_size()) > .8) {
252
-                $job_parameters->set_job_size($job_parameters->job_size() * 2);
253
-            }
254
-            return new JobStepResponse(
255
-                $job_parameters,
256
-                sprintf(
257
-                    esc_html__('Identified %d items for deletion.', 'event_espresso'),
258
-                    $units_processed
259
-                )
260
-            );
261
-        }
262
-    }
203
+	/**
204
+	 * Performs another step of the job
205
+	 * @param JobParameters $job_parameters
206
+	 * @param int $batch_size
207
+	 * @return JobStepResponse
208
+	 * @throws BatchRequestException
209
+	 */
210
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
211
+	{
212
+		// Serializing and unserializing is what really makes this drag on (eg on localhost, the ajax requests took
213
+		// about 4 seconds when the batch size was 250, but 3 seconds when the batch size was 50. So like
214
+		// 50% of the request is just serializing and unserializing.) So, make the batches much bigger.
215
+		$batch_size *= 3;
216
+		$units_processed = 0;
217
+		foreach ($job_parameters->extra_datum('roots', array()) as $root_node) {
218
+			if ($units_processed >= $batch_size) {
219
+				break;
220
+			}
221
+			if (!$root_node instanceof ModelObjNode) {
222
+				throw new InvalidClassException('ModelObjNode');
223
+			}
224
+			if ($root_node->isComplete()) {
225
+				continue;
226
+			}
227
+			$units_processed += $root_node->visit($batch_size - $units_processed);
228
+		}
229
+		$job_parameters->mark_processed($units_processed);
230
+		// If the most-recently processed root node is complete, we must be all done because we're doing them
231
+		// sequentially.
232
+		if (isset($root_node) && $root_node instanceof ModelObjNode && $root_node->isComplete()) {
233
+			$job_parameters->set_status(JobParameters::status_complete);
234
+			// Show a full progress bar.
235
+			$job_parameters->set_units_processed($job_parameters->job_size());
236
+			$deletion_job_code = $job_parameters->request_datum('deletion_job_code');
237
+			$this->model_obj_node_group_persister->persistModelObjNodesGroup(
238
+				$job_parameters->extra_datum('roots'),
239
+				$deletion_job_code
240
+			);
241
+			return new JobStepResponse(
242
+				$job_parameters,
243
+				esc_html__('Finished identifying items for deletion.', 'event_espresso'),
244
+				[
245
+					'deletion_job_code' => $deletion_job_code
246
+				]
247
+			);
248
+		} else {
249
+			// Because the job size was a guess, it may have likely been provden wrong. We don't want to show more work
250
+			// done than we originally said there would be. So adjust the estimate.
251
+			if (($job_parameters->units_processed() / $job_parameters->job_size()) > .8) {
252
+				$job_parameters->set_job_size($job_parameters->job_size() * 2);
253
+			}
254
+			return new JobStepResponse(
255
+				$job_parameters,
256
+				sprintf(
257
+					esc_html__('Identified %d items for deletion.', 'event_espresso'),
258
+					$units_processed
259
+				)
260
+			);
261
+		}
262
+	}
263 263
 
264
-    /**
265
-     * Performs any clean-up logic when we know the job is completed
266
-     * @param JobParameters $job_parameters
267
-     * @return JobStepResponse
268
-     */
269
-    public function cleanup_job(JobParameters $job_parameters)
270
-    {
271
-        // Nothing much to do. We can't delete the option with the built tree because we may need it in a moment for the deletion
272
-        return new JobStepResponse(
273
-            $job_parameters,
274
-            esc_html__('All done', 'event_espresso')
275
-        );
276
-    }
264
+	/**
265
+	 * Performs any clean-up logic when we know the job is completed
266
+	 * @param JobParameters $job_parameters
267
+	 * @return JobStepResponse
268
+	 */
269
+	public function cleanup_job(JobParameters $job_parameters)
270
+	{
271
+		// Nothing much to do. We can't delete the option with the built tree because we may need it in a moment for the deletion
272
+		return new JobStepResponse(
273
+			$job_parameters,
274
+			esc_html__('All done', 'event_espresso')
275
+		);
276
+	}
277 277
 }
278 278
 // End of file EventDeletion.php
279 279
 // Location: EventEspressoBatchRequest\JobHandlers/EventDeletion.php
Please login to merge, or discard this patch.
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -9,11 +9,9 @@
 block discarded – undo
9 9
 use EEM_Registration;
10 10
 use EEM_Ticket;
11 11
 use EEM_Transaction;
12
-use EETests\bootstrap\CoreLoader;
13 12
 use EventEspresso\core\exceptions\InvalidClassException;
14 13
 use EventEspresso\core\exceptions\InvalidDataTypeException;
15 14
 use EventEspresso\core\exceptions\InvalidInterfaceException;
16
-use EventEspresso\core\services\loaders\LoaderFactory;
17 15
 use EventEspresso\core\services\orm\tree_traversal\ModelObjNode;
18 16
 use EventEspresso\core\services\orm\tree_traversal\NodeGroupDao;
19 17
 use EventEspressoBatchRequest\Helpers\BatchRequestException;
Please login to merge, or discard this patch.
core/services/orm/tree_traversal/ModelObjNode.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
                 continue;
69 69
             }
70 70
             if ($relation instanceof EE_Has_Many_Relation) {
71
-                $this->nodes[ $relationName ] = new RelationNode(
71
+                $this->nodes[$relationName] = new RelationNode(
72 72
                     $this->id,
73 73
                     $this->model,
74 74
                     $relation->get_other_model(),
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
                     $relation->get_join_model()->get_this_model_name(),
80 80
                     $this->dont_traverse_models
81 81
                 )) {
82
-                $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode(
82
+                $this->nodes[$relation->get_join_model()->get_this_model_name()] = new RelationNode(
83 83
                     $this->id,
84 84
                     $this->model,
85 85
                     $relation->get_join_model(),
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
             // To save on space when serializing, only bother keeping a record of relation nodes that actually found
128 128
             // related model objects.
129 129
             if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) {
130
-                unset($this->nodes[ $model_name ]);
130
+                unset($this->nodes[$model_name]);
131 131
             }
132 132
             if ($num_identified >= $model_objects_to_identify) {
133 133
                 // ...but admit we're wrong if the work exceeded the budget.
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
             $tree['rels'] = null;
159 159
         } else {
160 160
             foreach ($this->nodes as $relation_name => $relation_node) {
161
-                $tree['rels'][ $relation_name ] = $relation_node->toArray();
161
+                $tree['rels'][$relation_name] = $relation_node->toArray();
162 162
             }
163 163
         }
164 164
         return $tree;
Please login to merge, or discard this patch.
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -22,204 +22,204 @@
 block discarded – undo
22 22
  */
23 23
 class ModelObjNode extends BaseNode
24 24
 {
25
-    /**
26
-     * @var int|string
27
-     */
28
-    protected $id;
25
+	/**
26
+	 * @var int|string
27
+	 */
28
+	protected $id;
29 29
 
30
-    /**
31
-     * @var EEM_Base
32
-     */
33
-    protected $model;
30
+	/**
31
+	 * @var EEM_Base
32
+	 */
33
+	protected $model;
34 34
 
35
-    /**
36
-     * @var RelationNode[]
37
-     */
38
-    protected $nodes;
35
+	/**
36
+	 * @var RelationNode[]
37
+	 */
38
+	protected $nodes;
39 39
 
40
-    /**
41
-     * We don't pass the model objects because this needs to serialize to something tiny for effiency.
42
-     * @param $model_obj_id
43
-     * @param EEM_Base $model
44
-     * @param array $dont_traverse_models array of model names we DON'T want to traverse.
45
-     */
46
-    public function __construct($model_obj_id, EEM_Base $model, array $dont_traverse_models = [])
47
-    {
48
-        $this->id = $model_obj_id;
49
-        $this->model = $model;
50
-        $this->dont_traverse_models = $dont_traverse_models;
51
-    }
40
+	/**
41
+	 * We don't pass the model objects because this needs to serialize to something tiny for effiency.
42
+	 * @param $model_obj_id
43
+	 * @param EEM_Base $model
44
+	 * @param array $dont_traverse_models array of model names we DON'T want to traverse.
45
+	 */
46
+	public function __construct($model_obj_id, EEM_Base $model, array $dont_traverse_models = [])
47
+	{
48
+		$this->id = $model_obj_id;
49
+		$this->model = $model;
50
+		$this->dont_traverse_models = $dont_traverse_models;
51
+	}
52 52
 
53
-    /**
54
-     * Creates a relation node for each relation of this model's relations.
55
-     * Does NOT call `discover` on them yet though.
56
-     * @since $VID:$
57
-     * @throws \EE_Error
58
-     * @throws InvalidDataTypeException
59
-     * @throws InvalidInterfaceException
60
-     * @throws InvalidArgumentException
61
-     * @throws ReflectionException
62
-     */
63
-    protected function discover()
64
-    {
65
-        $this->nodes = [];
66
-        foreach ($this->model->relation_settings() as $relationName => $relation) {
67
-            // Make sure this isn't one of the models we were told to not traverse into.
68
-            if (in_array($relationName, $this->dont_traverse_models)) {
69
-                continue;
70
-            }
71
-            if ($relation instanceof EE_Has_Many_Relation) {
72
-                $this->nodes[ $relationName ] = new RelationNode(
73
-                    $this->id,
74
-                    $this->model,
75
-                    $relation->get_other_model(),
76
-                    $this->dont_traverse_models
77
-                );
78
-            } elseif ($relation instanceof EE_HABTM_Relation &&
79
-                ! in_array(
80
-                    $relation->get_join_model()->get_this_model_name(),
81
-                    $this->dont_traverse_models
82
-                )) {
83
-                $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode(
84
-                    $this->id,
85
-                    $this->model,
86
-                    $relation->get_join_model(),
87
-                    $this->dont_traverse_models
88
-                );
89
-            }
90
-        }
91
-        ksort($this->nodes);
92
-    }
53
+	/**
54
+	 * Creates a relation node for each relation of this model's relations.
55
+	 * Does NOT call `discover` on them yet though.
56
+	 * @since $VID:$
57
+	 * @throws \EE_Error
58
+	 * @throws InvalidDataTypeException
59
+	 * @throws InvalidInterfaceException
60
+	 * @throws InvalidArgumentException
61
+	 * @throws ReflectionException
62
+	 */
63
+	protected function discover()
64
+	{
65
+		$this->nodes = [];
66
+		foreach ($this->model->relation_settings() as $relationName => $relation) {
67
+			// Make sure this isn't one of the models we were told to not traverse into.
68
+			if (in_array($relationName, $this->dont_traverse_models)) {
69
+				continue;
70
+			}
71
+			if ($relation instanceof EE_Has_Many_Relation) {
72
+				$this->nodes[ $relationName ] = new RelationNode(
73
+					$this->id,
74
+					$this->model,
75
+					$relation->get_other_model(),
76
+					$this->dont_traverse_models
77
+				);
78
+			} elseif ($relation instanceof EE_HABTM_Relation &&
79
+				! in_array(
80
+					$relation->get_join_model()->get_this_model_name(),
81
+					$this->dont_traverse_models
82
+				)) {
83
+				$this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode(
84
+					$this->id,
85
+					$this->model,
86
+					$relation->get_join_model(),
87
+					$this->dont_traverse_models
88
+				);
89
+			}
90
+		}
91
+		ksort($this->nodes);
92
+	}
93 93
 
94 94
 
95
-    /**
96
-     * Whether this item has already been initialized
97
-     */
98
-    protected function isDiscovered()
99
-    {
100
-        return $this->nodes !== null && is_array($this->nodes);
101
-    }
95
+	/**
96
+	 * Whether this item has already been initialized
97
+	 */
98
+	protected function isDiscovered()
99
+	{
100
+		return $this->nodes !== null && is_array($this->nodes);
101
+	}
102 102
 
103
-    /**
104
-     * @since $VID:$
105
-     * @return boolean
106
-     */
107
-    public function isComplete()
108
-    {
109
-        if ($this->complete === null) {
110
-            $this->complete = false;
111
-        }
112
-        return $this->complete;
113
-    }
103
+	/**
104
+	 * @since $VID:$
105
+	 * @return boolean
106
+	 */
107
+	public function isComplete()
108
+	{
109
+		if ($this->complete === null) {
110
+			$this->complete = false;
111
+		}
112
+		return $this->complete;
113
+	}
114 114
 
115
-    /**
116
-     * Triggers working on each child relation node that has work to do.
117
-     * @since $VID:$
118
-     * @param $model_objects_to_identify
119
-     * @return int units of work done
120
-     */
121
-    protected function work($model_objects_to_identify)
122
-    {
123
-        $num_identified = 0;
124
-        // Begin assuming we'll finish all the work on this node and its children...
125
-        $this->complete = true;
126
-        foreach ($this->nodes as $model_name => $relation_node) {
127
-            $num_identified += $relation_node->visit($model_objects_to_identify - $num_identified);
128
-            // To save on space when serializing, only bother keeping a record of relation nodes that actually found
129
-            // related model objects.
130
-            if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) {
131
-                unset($this->nodes[ $model_name ]);
132
-            }
133
-            if ($num_identified >= $model_objects_to_identify) {
134
-                // ...but admit we're wrong if the work exceeded the budget.
135
-                $this->complete = false;
136
-                break;
137
-            }
138
-        }
139
-        return $num_identified;
140
-    }
115
+	/**
116
+	 * Triggers working on each child relation node that has work to do.
117
+	 * @since $VID:$
118
+	 * @param $model_objects_to_identify
119
+	 * @return int units of work done
120
+	 */
121
+	protected function work($model_objects_to_identify)
122
+	{
123
+		$num_identified = 0;
124
+		// Begin assuming we'll finish all the work on this node and its children...
125
+		$this->complete = true;
126
+		foreach ($this->nodes as $model_name => $relation_node) {
127
+			$num_identified += $relation_node->visit($model_objects_to_identify - $num_identified);
128
+			// To save on space when serializing, only bother keeping a record of relation nodes that actually found
129
+			// related model objects.
130
+			if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) {
131
+				unset($this->nodes[ $model_name ]);
132
+			}
133
+			if ($num_identified >= $model_objects_to_identify) {
134
+				// ...but admit we're wrong if the work exceeded the budget.
135
+				$this->complete = false;
136
+				break;
137
+			}
138
+		}
139
+		return $num_identified;
140
+	}
141 141
 
142
-    /**
143
-     * @since $VID:$
144
-     * @return array
145
-     * @throws \EE_Error
146
-     * @throws InvalidDataTypeException
147
-     * @throws InvalidInterfaceException
148
-     * @throws InvalidArgumentException
149
-     * @throws ReflectionException
150
-     */
151
-    public function toArray()
152
-    {
153
-        $tree = [
154
-            'id' => $this->id,
155
-            'complete' => $this->isComplete(),
156
-            'rels' => []
157
-        ];
158
-        if ($this->nodes === null) {
159
-            $tree['rels'] = null;
160
-        } else {
161
-            foreach ($this->nodes as $relation_name => $relation_node) {
162
-                $tree['rels'][ $relation_name ] = $relation_node->toArray();
163
-            }
164
-        }
165
-        return $tree;
166
-    }
142
+	/**
143
+	 * @since $VID:$
144
+	 * @return array
145
+	 * @throws \EE_Error
146
+	 * @throws InvalidDataTypeException
147
+	 * @throws InvalidInterfaceException
148
+	 * @throws InvalidArgumentException
149
+	 * @throws ReflectionException
150
+	 */
151
+	public function toArray()
152
+	{
153
+		$tree = [
154
+			'id' => $this->id,
155
+			'complete' => $this->isComplete(),
156
+			'rels' => []
157
+		];
158
+		if ($this->nodes === null) {
159
+			$tree['rels'] = null;
160
+		} else {
161
+			foreach ($this->nodes as $relation_name => $relation_node) {
162
+				$tree['rels'][ $relation_name ] = $relation_node->toArray();
163
+			}
164
+		}
165
+		return $tree;
166
+	}
167 167
 
168
-    /**
169
-     * @since $VID:$
170
-     * @return array|mixed
171
-     * @throws InvalidArgumentException
172
-     * @throws InvalidDataTypeException
173
-     * @throws InvalidInterfaceException
174
-     * @throws ReflectionException
175
-     * @throws \EE_Error
176
-     */
177
-    public function getIds()
178
-    {
179
-        $ids = [
180
-            $this->model->get_this_model_name() => [
181
-                $this->id => $this->id
182
-            ]
183
-        ];
184
-        if ($this->nodes && is_array($this->nodes)) {
185
-            foreach ($this->nodes as $relation_node) {
186
-                $ids = array_replace_recursive($ids, $relation_node->getIds());
187
-            }
188
-        }
189
-        return $ids;
190
-    }
168
+	/**
169
+	 * @since $VID:$
170
+	 * @return array|mixed
171
+	 * @throws InvalidArgumentException
172
+	 * @throws InvalidDataTypeException
173
+	 * @throws InvalidInterfaceException
174
+	 * @throws ReflectionException
175
+	 * @throws \EE_Error
176
+	 */
177
+	public function getIds()
178
+	{
179
+		$ids = [
180
+			$this->model->get_this_model_name() => [
181
+				$this->id => $this->id
182
+			]
183
+		];
184
+		if ($this->nodes && is_array($this->nodes)) {
185
+			foreach ($this->nodes as $relation_node) {
186
+				$ids = array_replace_recursive($ids, $relation_node->getIds());
187
+			}
188
+		}
189
+		return $ids;
190
+	}
191 191
 
192
-    /**
193
-     * Don't serialize the models. Just record their names on some dynamic properties.
194
-     * @since $VID:$
195
-     */
196
-    public function __sleep()
197
-    {
198
-        $this->m = $this->model->get_this_model_name();
199
-        return array_merge(
200
-            [
201
-                'm',
202
-                'id',
203
-                'nodes',
204
-            ],
205
-            parent::__sleep()
206
-        );
207
-    }
192
+	/**
193
+	 * Don't serialize the models. Just record their names on some dynamic properties.
194
+	 * @since $VID:$
195
+	 */
196
+	public function __sleep()
197
+	{
198
+		$this->m = $this->model->get_this_model_name();
199
+		return array_merge(
200
+			[
201
+				'm',
202
+				'id',
203
+				'nodes',
204
+			],
205
+			parent::__sleep()
206
+		);
207
+	}
208 208
 
209
-    /**
210
-     * Use the dynamic properties to instantiate the models we use.
211
-     * @since $VID:$
212
-     * @throws EE_Error
213
-     * @throws InvalidArgumentException
214
-     * @throws InvalidDataTypeException
215
-     * @throws InvalidInterfaceException
216
-     * @throws ReflectionException
217
-     */
218
-    public function __wakeup()
219
-    {
220
-        $this->model = EE_Registry::instance()->load_model($this->m);
221
-        parent::__wakeup();
222
-    }
209
+	/**
210
+	 * Use the dynamic properties to instantiate the models we use.
211
+	 * @since $VID:$
212
+	 * @throws EE_Error
213
+	 * @throws InvalidArgumentException
214
+	 * @throws InvalidDataTypeException
215
+	 * @throws InvalidInterfaceException
216
+	 * @throws ReflectionException
217
+	 */
218
+	public function __wakeup()
219
+	{
220
+		$this->model = EE_Registry::instance()->load_model($this->m);
221
+		parent::__wakeup();
222
+	}
223 223
 }
224 224
 // End of file Visitor.php
225 225
 // Location: EventEspresso\core\services\orm\tree_traversal/Visitor.php
Please login to merge, or discard this patch.
admin_pages/events/form_sections/ConfirmEventDeletionForm.php 3 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,6 @@
 block discarded – undo
4 4
 
5 5
 use EE_Checkbox_Multi_Input;
6 6
 use EE_Event;
7
-use EE_Form_Section_HTML;
8
-use EEH_HTML;
9 7
 use EEM_Event;
10 8
 use EventEspresso\core\exceptions\UnexpectedEntityException;
11 9
 
Please login to merge, or discard this patch.
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -22,55 +22,55 @@
 block discarded – undo
22 22
  */
23 23
 class ConfirmEventDeletionForm extends \EE_Form_Section_Proper
24 24
 {
25
-    /**
26
-     * @var EE_Event[]
27
-     */
28
-    protected $events;
29
-    public function __construct($event_ids, $options_array = array())
30
-    {
31
-        if (! isset($options_array['subsections'])) {
32
-            $options_array['subsections'] = [];
33
-        }
34
-        if (! isset($options_array['subsections']['events'])) {
35
-            $events_subsection = new \EE_Form_Section_Proper();
36
-            $options_array['subsections']['events'] = $events_subsection;
37
-        }
38
-        $events = EEM_Event::instance()->get_all_deleted_and_undeleted(
39
-            [
40
-                [
41
-                    'EVT_ID' => ['IN',$event_ids]
42
-                ]
43
-            ]
44
-        );
45
-        if (! is_array($events)) {
46
-            throw new UnexpectedEntityException($event_ids, 'array');
47
-        }
48
-        $this->events = $events;
49
-        $events_inputs = [
50
-        ];
51
-        foreach ($events as $event) {
52
-            $events_inputs[ $event->ID() ] = new EE_Checkbox_Multi_Input(
53
-                [
54
-                    'yes' => $event->name(),
55
-                ],
56
-                [
57
-                    'html_label_text' => esc_html__('Please confirm you wish to delete:', 'event_espresso'),
58
-                    'required' => true
59
-                ]
60
-            );
61
-        }
62
-        $events_subsection->add_subsections($events_inputs);
63
-        $options_array['subsections']['backup'] = new EE_Checkbox_Multi_Input(
64
-            [
65
-                'yes' => esc_html__('I have backed up my database.', 'event_espresso')
66
-            ],
67
-            [
68
-                'html_label_text' => esc_html__('Deleting this data cannot be undone. Please confirm you have a usable database backup.', 'event_espresso'),
69
-                'required' => true
70
-            ]
71
-        );
72
-        parent::__construct($options_array);
73
-    }
25
+	/**
26
+	 * @var EE_Event[]
27
+	 */
28
+	protected $events;
29
+	public function __construct($event_ids, $options_array = array())
30
+	{
31
+		if (! isset($options_array['subsections'])) {
32
+			$options_array['subsections'] = [];
33
+		}
34
+		if (! isset($options_array['subsections']['events'])) {
35
+			$events_subsection = new \EE_Form_Section_Proper();
36
+			$options_array['subsections']['events'] = $events_subsection;
37
+		}
38
+		$events = EEM_Event::instance()->get_all_deleted_and_undeleted(
39
+			[
40
+				[
41
+					'EVT_ID' => ['IN',$event_ids]
42
+				]
43
+			]
44
+		);
45
+		if (! is_array($events)) {
46
+			throw new UnexpectedEntityException($event_ids, 'array');
47
+		}
48
+		$this->events = $events;
49
+		$events_inputs = [
50
+		];
51
+		foreach ($events as $event) {
52
+			$events_inputs[ $event->ID() ] = new EE_Checkbox_Multi_Input(
53
+				[
54
+					'yes' => $event->name(),
55
+				],
56
+				[
57
+					'html_label_text' => esc_html__('Please confirm you wish to delete:', 'event_espresso'),
58
+					'required' => true
59
+				]
60
+			);
61
+		}
62
+		$events_subsection->add_subsections($events_inputs);
63
+		$options_array['subsections']['backup'] = new EE_Checkbox_Multi_Input(
64
+			[
65
+				'yes' => esc_html__('I have backed up my database.', 'event_espresso')
66
+			],
67
+			[
68
+				'html_label_text' => esc_html__('Deleting this data cannot be undone. Please confirm you have a usable database backup.', 'event_espresso'),
69
+				'required' => true
70
+			]
71
+		);
72
+		parent::__construct($options_array);
73
+	}
74 74
 }
75 75
 // End of file ConfirmEventDeletionForm.php
76 76
 // Location: EventEspresso\admin_pages\events\form_sections/ConfirmEventDeletionForm.php
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -28,28 +28,28 @@
 block discarded – undo
28 28
     protected $events;
29 29
     public function __construct($event_ids, $options_array = array())
30 30
     {
31
-        if (! isset($options_array['subsections'])) {
31
+        if ( ! isset($options_array['subsections'])) {
32 32
             $options_array['subsections'] = [];
33 33
         }
34
-        if (! isset($options_array['subsections']['events'])) {
34
+        if ( ! isset($options_array['subsections']['events'])) {
35 35
             $events_subsection = new \EE_Form_Section_Proper();
36 36
             $options_array['subsections']['events'] = $events_subsection;
37 37
         }
38 38
         $events = EEM_Event::instance()->get_all_deleted_and_undeleted(
39 39
             [
40 40
                 [
41
-                    'EVT_ID' => ['IN',$event_ids]
41
+                    'EVT_ID' => ['IN', $event_ids]
42 42
                 ]
43 43
             ]
44 44
         );
45
-        if (! is_array($events)) {
45
+        if ( ! is_array($events)) {
46 46
             throw new UnexpectedEntityException($event_ids, 'array');
47 47
         }
48 48
         $this->events = $events;
49 49
         $events_inputs = [
50 50
         ];
51 51
         foreach ($events as $event) {
52
-            $events_inputs[ $event->ID() ] = new EE_Checkbox_Multi_Input(
52
+            $events_inputs[$event->ID()] = new EE_Checkbox_Multi_Input(
53 53
                 [
54 54
                     'yes' => $event->name(),
55 55
                 ],
Please login to merge, or discard this patch.