@@ -35,6 +35,9 @@ |
||
35 | 35 | |
36 | 36 | protected $itemNodes; |
37 | 37 | |
38 | + /** |
|
39 | + * @param EE_Base_Class $mainEntity |
|
40 | + */ |
|
38 | 41 | public function __construct($mainEntity, $relation) |
39 | 42 | { |
40 | 43 | $this->mainEntity = $mainEntity; |
@@ -17,109 +17,109 @@ |
||
17 | 17 | */ |
18 | 18 | class RelationNode extends BaseNode |
19 | 19 | { |
20 | - /** |
|
21 | - * @var EE_Base_Class |
|
22 | - */ |
|
23 | - protected $mainEntity; |
|
20 | + /** |
|
21 | + * @var EE_Base_Class |
|
22 | + */ |
|
23 | + protected $mainEntity; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var int |
|
27 | - */ |
|
28 | - protected $count; |
|
25 | + /** |
|
26 | + * @var int |
|
27 | + */ |
|
28 | + protected $count; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var \EE_Model_Relation_Base |
|
32 | - */ |
|
33 | - protected $relation; |
|
30 | + /** |
|
31 | + * @var \EE_Model_Relation_Base |
|
32 | + */ |
|
33 | + protected $relation; |
|
34 | 34 | |
35 | 35 | |
36 | - protected $itemNodes; |
|
36 | + protected $itemNodes; |
|
37 | 37 | |
38 | - public function __construct($mainEntity, $relation) |
|
39 | - { |
|
40 | - $this->mainEntity = $mainEntity; |
|
41 | - $this->relation = $relation; |
|
42 | - } |
|
38 | + public function __construct($mainEntity, $relation) |
|
39 | + { |
|
40 | + $this->mainEntity = $mainEntity; |
|
41 | + $this->relation = $relation; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * Here is where most of the work happens. We've counted how many related model objects exist, but now we need to |
|
47 | - * trigger visiting each of them, and then visiting their children etc. |
|
48 | - * @since $VID:$ |
|
49 | - * @param $work_budget |
|
50 | - * @return int|void |
|
51 | - * @throws \EE_Error |
|
52 | - */ |
|
53 | - protected function work($work_budget){ |
|
54 | - $work_done = 0; |
|
55 | - foreach($this->itemNodes as $entity_node){ |
|
56 | - if($work_done < $work_budget){ |
|
57 | - $work_done += $entity_node->visit($work_budget); |
|
58 | - } |
|
59 | - } |
|
60 | - if($work_done < $work_budget){ |
|
61 | - $items = $this->relation->get_this_model()->get_all_related( |
|
62 | - $this->mainEntity, |
|
63 | - $this->relation->get_other_model(), |
|
64 | - [ |
|
65 | - 'limit' => [ |
|
66 | - count($this->itemNodes), |
|
67 | - $work_budget |
|
68 | - ] |
|
69 | - ] |
|
70 | - ); |
|
71 | - $work_done += count($items); |
|
72 | - $new_item_nodes = []; |
|
45 | + /** |
|
46 | + * Here is where most of the work happens. We've counted how many related model objects exist, but now we need to |
|
47 | + * trigger visiting each of them, and then visiting their children etc. |
|
48 | + * @since $VID:$ |
|
49 | + * @param $work_budget |
|
50 | + * @return int|void |
|
51 | + * @throws \EE_Error |
|
52 | + */ |
|
53 | + protected function work($work_budget){ |
|
54 | + $work_done = 0; |
|
55 | + foreach($this->itemNodes as $entity_node){ |
|
56 | + if($work_done < $work_budget){ |
|
57 | + $work_done += $entity_node->visit($work_budget); |
|
58 | + } |
|
59 | + } |
|
60 | + if($work_done < $work_budget){ |
|
61 | + $items = $this->relation->get_this_model()->get_all_related( |
|
62 | + $this->mainEntity, |
|
63 | + $this->relation->get_other_model(), |
|
64 | + [ |
|
65 | + 'limit' => [ |
|
66 | + count($this->itemNodes), |
|
67 | + $work_budget |
|
68 | + ] |
|
69 | + ] |
|
70 | + ); |
|
71 | + $work_done += count($items); |
|
72 | + $new_item_nodes = []; |
|
73 | 73 | |
74 | - // Add entity nodes for each of the model objects we fetched. |
|
75 | - foreach($items as $item){ |
|
76 | - $entity_node = new EntityNode($item); |
|
77 | - $this->itemNodes[] = $entity_node; |
|
78 | - $new_item_nodes[] = $entity_node; |
|
79 | - } |
|
74 | + // Add entity nodes for each of the model objects we fetched. |
|
75 | + foreach($items as $item){ |
|
76 | + $entity_node = new EntityNode($item); |
|
77 | + $this->itemNodes[] = $entity_node; |
|
78 | + $new_item_nodes[] = $entity_node; |
|
79 | + } |
|
80 | 80 | |
81 | - // And lastly do the work. |
|
82 | - foreach($new_item_nodes as $new_item_node){ |
|
83 | - if($work_done >= $work_budget){ |
|
84 | - break; |
|
85 | - } |
|
86 | - $work_done += $new_item_node->visit($work_budget - $work_done); |
|
87 | - } |
|
88 | - } |
|
89 | - // We're all done this node if we've done everything here and still have budget for more. |
|
90 | - if($work_done < $work_budget){ |
|
91 | - $this->complete = true; |
|
92 | - } |
|
93 | - return $work_done; |
|
94 | - } |
|
81 | + // And lastly do the work. |
|
82 | + foreach($new_item_nodes as $new_item_node){ |
|
83 | + if($work_done >= $work_budget){ |
|
84 | + break; |
|
85 | + } |
|
86 | + $work_done += $new_item_node->visit($work_budget - $work_done); |
|
87 | + } |
|
88 | + } |
|
89 | + // We're all done this node if we've done everything here and still have budget for more. |
|
90 | + if($work_done < $work_budget){ |
|
91 | + $this->complete = true; |
|
92 | + } |
|
93 | + return $work_done; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Whether this item has already been initialized |
|
98 | - */ |
|
99 | - protected function isDiscovered() |
|
100 | - { |
|
101 | - return $this->count !== null; |
|
102 | - } |
|
96 | + /** |
|
97 | + * Whether this item has already been initialized |
|
98 | + */ |
|
99 | + protected function isDiscovered() |
|
100 | + { |
|
101 | + return $this->count !== null; |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @since $VID:$ |
|
106 | - * @return boolean |
|
107 | - */ |
|
108 | - public function isComplete() |
|
109 | - { |
|
110 | - return $this->complete; |
|
111 | - } |
|
104 | + /** |
|
105 | + * @since $VID:$ |
|
106 | + * @return boolean |
|
107 | + */ |
|
108 | + public function isComplete() |
|
109 | + { |
|
110 | + return $this->complete; |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Discovers how many related model objects exist. |
|
115 | - * @since $VID:$ |
|
116 | - * @return mixed|void |
|
117 | - * @throws \EE_Error |
|
118 | - */ |
|
119 | - protected function discover() |
|
120 | - { |
|
121 | - $this->count = $this->relation->get_this_model()->count_related($this->mainEntity, $this->relation->get_other_model()); |
|
122 | - } |
|
113 | + /** |
|
114 | + * Discovers how many related model objects exist. |
|
115 | + * @since $VID:$ |
|
116 | + * @return mixed|void |
|
117 | + * @throws \EE_Error |
|
118 | + */ |
|
119 | + protected function discover() |
|
120 | + { |
|
121 | + $this->count = $this->relation->get_this_model()->count_related($this->mainEntity, $this->relation->get_other_model()); |
|
122 | + } |
|
123 | 123 | } |
124 | 124 | // End of file RelationNode.php |
125 | 125 | // Location: EventEspresso\core\services\orm\tree_traversal/RelationNode.php |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | * @return int|void |
51 | 51 | * @throws \EE_Error |
52 | 52 | */ |
53 | - protected function work($work_budget){ |
|
53 | + protected function work($work_budget) { |
|
54 | 54 | $work_done = 0; |
55 | - foreach($this->itemNodes as $entity_node){ |
|
56 | - if($work_done < $work_budget){ |
|
55 | + foreach ($this->itemNodes as $entity_node) { |
|
56 | + if ($work_done < $work_budget) { |
|
57 | 57 | $work_done += $entity_node->visit($work_budget); |
58 | 58 | } |
59 | 59 | } |
60 | - if($work_done < $work_budget){ |
|
60 | + if ($work_done < $work_budget) { |
|
61 | 61 | $items = $this->relation->get_this_model()->get_all_related( |
62 | 62 | $this->mainEntity, |
63 | 63 | $this->relation->get_other_model(), |
@@ -72,22 +72,22 @@ discard block |
||
72 | 72 | $new_item_nodes = []; |
73 | 73 | |
74 | 74 | // Add entity nodes for each of the model objects we fetched. |
75 | - foreach($items as $item){ |
|
75 | + foreach ($items as $item) { |
|
76 | 76 | $entity_node = new EntityNode($item); |
77 | 77 | $this->itemNodes[] = $entity_node; |
78 | 78 | $new_item_nodes[] = $entity_node; |
79 | 79 | } |
80 | 80 | |
81 | 81 | // And lastly do the work. |
82 | - foreach($new_item_nodes as $new_item_node){ |
|
83 | - if($work_done >= $work_budget){ |
|
82 | + foreach ($new_item_nodes as $new_item_node) { |
|
83 | + if ($work_done >= $work_budget) { |
|
84 | 84 | break; |
85 | 85 | } |
86 | 86 | $work_done += $new_item_node->visit($work_budget - $work_done); |
87 | 87 | } |
88 | 88 | } |
89 | 89 | // We're all done this node if we've done everything here and still have budget for more. |
90 | - if($work_done < $work_budget){ |
|
90 | + if ($work_done < $work_budget) { |
|
91 | 91 | $this->complete = true; |
92 | 92 | } |
93 | 93 | return $work_done; |
@@ -16,81 +16,81 @@ |
||
16 | 16 | */ |
17 | 17 | class EntityNode extends BaseNode |
18 | 18 | { |
19 | - /** |
|
20 | - * @var EE_Base_Class |
|
21 | - */ |
|
22 | - protected $initialInstance; |
|
19 | + /** |
|
20 | + * @var EE_Base_Class |
|
21 | + */ |
|
22 | + protected $initialInstance; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var RelationNode[] |
|
26 | - */ |
|
27 | - protected $relation_nodes; |
|
24 | + /** |
|
25 | + * @var RelationNode[] |
|
26 | + */ |
|
27 | + protected $relation_nodes; |
|
28 | 28 | |
29 | - public function __construct( $instance) |
|
30 | - { |
|
31 | - $this->initialInstance = $instance; |
|
32 | - } |
|
29 | + public function __construct( $instance) |
|
30 | + { |
|
31 | + $this->initialInstance = $instance; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Creates a relation node for each relation of this model's relations. |
|
36 | - * Does NOT call `discover` on them yet though. |
|
37 | - * @since $VID:$ |
|
38 | - * @throws \EE_Error |
|
39 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
40 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
41 | - * @throws \InvalidArgumentException |
|
42 | - * @throws \ReflectionException |
|
43 | - */ |
|
44 | - protected function discover(){ |
|
45 | - $this->relation_nodes = []; |
|
46 | - foreach($this->initialInstance->get_model()->relation_settings() as $relation){ |
|
47 | - if($relation->block_delete_if_related_models_exist()){ |
|
48 | - $this->relation_nodes[] = new RelationNode($this->initialInstance, $relation); |
|
49 | - } |
|
50 | - } |
|
51 | - } |
|
34 | + /** |
|
35 | + * Creates a relation node for each relation of this model's relations. |
|
36 | + * Does NOT call `discover` on them yet though. |
|
37 | + * @since $VID:$ |
|
38 | + * @throws \EE_Error |
|
39 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
40 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
41 | + * @throws \InvalidArgumentException |
|
42 | + * @throws \ReflectionException |
|
43 | + */ |
|
44 | + protected function discover(){ |
|
45 | + $this->relation_nodes = []; |
|
46 | + foreach($this->initialInstance->get_model()->relation_settings() as $relation){ |
|
47 | + if($relation->block_delete_if_related_models_exist()){ |
|
48 | + $this->relation_nodes[] = new RelationNode($this->initialInstance, $relation); |
|
49 | + } |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * Whether this item has already been initialized |
|
56 | - */ |
|
57 | - protected function isDiscovered() |
|
58 | - { |
|
59 | - return $this->relation_nodes !== null && is_array($this->relation_nodes); |
|
60 | - } |
|
54 | + /** |
|
55 | + * Whether this item has already been initialized |
|
56 | + */ |
|
57 | + protected function isDiscovered() |
|
58 | + { |
|
59 | + return $this->relation_nodes !== null && is_array($this->relation_nodes); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @since $VID:$ |
|
64 | - * @return boolean |
|
65 | - */ |
|
66 | - public function isComplete() |
|
67 | - { |
|
68 | - if($this->complete === null){ |
|
69 | - $this->complete = false; |
|
70 | - } |
|
71 | - return $this->complete; |
|
72 | - } |
|
62 | + /** |
|
63 | + * @since $VID:$ |
|
64 | + * @return boolean |
|
65 | + */ |
|
66 | + public function isComplete() |
|
67 | + { |
|
68 | + if($this->complete === null){ |
|
69 | + $this->complete = false; |
|
70 | + } |
|
71 | + return $this->complete; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Triggers working on each child relation node that has work to do. |
|
76 | - * @since $VID:$ |
|
77 | - * @param $work_budget |
|
78 | - * @return int units of work done |
|
79 | - */ |
|
80 | - protected function work($work_budget) |
|
81 | - { |
|
82 | - $units_worked = 0; |
|
83 | - foreach($this->relation_nodes as $relation_node){ |
|
84 | - $units_worked += $relation_node->visit($work_budget); |
|
85 | - if($units_worked >= $work_budget){ |
|
86 | - break; |
|
87 | - } |
|
88 | - } |
|
89 | - if($units_worked < $work_budget){ |
|
90 | - $this->complete = true; |
|
91 | - } |
|
92 | - return $units_worked; |
|
93 | - } |
|
74 | + /** |
|
75 | + * Triggers working on each child relation node that has work to do. |
|
76 | + * @since $VID:$ |
|
77 | + * @param $work_budget |
|
78 | + * @return int units of work done |
|
79 | + */ |
|
80 | + protected function work($work_budget) |
|
81 | + { |
|
82 | + $units_worked = 0; |
|
83 | + foreach($this->relation_nodes as $relation_node){ |
|
84 | + $units_worked += $relation_node->visit($work_budget); |
|
85 | + if($units_worked >= $work_budget){ |
|
86 | + break; |
|
87 | + } |
|
88 | + } |
|
89 | + if($units_worked < $work_budget){ |
|
90 | + $this->complete = true; |
|
91 | + } |
|
92 | + return $units_worked; |
|
93 | + } |
|
94 | 94 | } |
95 | 95 | // End of file Visitor.php |
96 | 96 | // Location: EventEspresso\core\services\orm\tree_traversal/Visitor.php |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | protected $relation_nodes; |
28 | 28 | |
29 | - public function __construct( $instance) |
|
29 | + public function __construct($instance) |
|
30 | 30 | { |
31 | 31 | $this->initialInstance = $instance; |
32 | 32 | } |
@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | * @throws \InvalidArgumentException |
42 | 42 | * @throws \ReflectionException |
43 | 43 | */ |
44 | - protected function discover(){ |
|
44 | + protected function discover() { |
|
45 | 45 | $this->relation_nodes = []; |
46 | - foreach($this->initialInstance->get_model()->relation_settings() as $relation){ |
|
47 | - if($relation->block_delete_if_related_models_exist()){ |
|
46 | + foreach ($this->initialInstance->get_model()->relation_settings() as $relation) { |
|
47 | + if ($relation->block_delete_if_related_models_exist()) { |
|
48 | 48 | $this->relation_nodes[] = new RelationNode($this->initialInstance, $relation); |
49 | 49 | } |
50 | 50 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function isComplete() |
67 | 67 | { |
68 | - if($this->complete === null){ |
|
68 | + if ($this->complete === null) { |
|
69 | 69 | $this->complete = false; |
70 | 70 | } |
71 | 71 | return $this->complete; |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | protected function work($work_budget) |
81 | 81 | { |
82 | 82 | $units_worked = 0; |
83 | - foreach($this->relation_nodes as $relation_node){ |
|
83 | + foreach ($this->relation_nodes as $relation_node) { |
|
84 | 84 | $units_worked += $relation_node->visit($work_budget); |
85 | - if($units_worked >= $work_budget){ |
|
85 | + if ($units_worked >= $work_budget) { |
|
86 | 86 | break; |
87 | 87 | } |
88 | 88 | } |
89 | - if($units_worked < $work_budget){ |
|
89 | + if ($units_worked < $work_budget) { |
|
90 | 90 | $this->complete = true; |
91 | 91 | } |
92 | 92 | return $units_worked; |
@@ -14,54 +14,54 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class BaseNode |
16 | 16 | { |
17 | - /** |
|
18 | - * @var boolean |
|
19 | - */ |
|
20 | - protected $complete; |
|
21 | - /** |
|
22 | - * Whether this item has already been initialized |
|
23 | - */ |
|
24 | - protected abstract function isDiscovered(); |
|
17 | + /** |
|
18 | + * @var boolean |
|
19 | + */ |
|
20 | + protected $complete; |
|
21 | + /** |
|
22 | + * Whether this item has already been initialized |
|
23 | + */ |
|
24 | + protected abstract function isDiscovered(); |
|
25 | 25 | |
26 | - /** |
|
27 | - * Determines if the work is done yet or not. Requires you to have first discovered what work exists by calling |
|
28 | - * discover(). |
|
29 | - * @since $VID:$ |
|
30 | - * @return boolean |
|
31 | - */ |
|
32 | - public abstract function isComplete(); |
|
26 | + /** |
|
27 | + * Determines if the work is done yet or not. Requires you to have first discovered what work exists by calling |
|
28 | + * discover(). |
|
29 | + * @since $VID:$ |
|
30 | + * @return boolean |
|
31 | + */ |
|
32 | + public abstract function isComplete(); |
|
33 | 33 | |
34 | - /** |
|
35 | - * Discovers what work needs to be done to complete traversing this node and its children. |
|
36 | - * Note that this is separate from the constructor, so we can create child nodes without |
|
37 | - * discovering them immediately. |
|
38 | - * @since $VID:$ |
|
39 | - * @return mixed |
|
40 | - */ |
|
41 | - protected abstract function discover(); |
|
34 | + /** |
|
35 | + * Discovers what work needs to be done to complete traversing this node and its children. |
|
36 | + * Note that this is separate from the constructor, so we can create child nodes without |
|
37 | + * discovering them immediately. |
|
38 | + * @since $VID:$ |
|
39 | + * @return mixed |
|
40 | + */ |
|
41 | + protected abstract function discover(); |
|
42 | 42 | |
43 | - /** |
|
44 | - * @since $VID:$ |
|
45 | - * @param $work_to_do |
|
46 | - * @return int units of work done |
|
47 | - */ |
|
48 | - public function visit($work_to_do){ |
|
49 | - if(! $this->isDiscovered()){ |
|
50 | - $this->discover(); |
|
51 | - } |
|
52 | - if($this->isComplete()){ |
|
53 | - return 0; |
|
54 | - } |
|
55 | - return $this->work($work_to_do); |
|
56 | - } |
|
43 | + /** |
|
44 | + * @since $VID:$ |
|
45 | + * @param $work_to_do |
|
46 | + * @return int units of work done |
|
47 | + */ |
|
48 | + public function visit($work_to_do){ |
|
49 | + if(! $this->isDiscovered()){ |
|
50 | + $this->discover(); |
|
51 | + } |
|
52 | + if($this->isComplete()){ |
|
53 | + return 0; |
|
54 | + } |
|
55 | + return $this->work($work_to_do); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * |
|
60 | - * @since $VID:$ |
|
61 | - * @param $work_budget |
|
62 | - * @return int units of work done |
|
63 | - */ |
|
64 | - protected abstract function work($work_budget); |
|
58 | + /** |
|
59 | + * |
|
60 | + * @since $VID:$ |
|
61 | + * @param $work_budget |
|
62 | + * @return int units of work done |
|
63 | + */ |
|
64 | + protected abstract function work($work_budget); |
|
65 | 65 | } |
66 | 66 | // End of file BaseNode.php |
67 | 67 | // Location: EventEspresso\core\services\orm\tree_traversal/BaseNode.php |
@@ -45,11 +45,11 @@ |
||
45 | 45 | * @param $work_to_do |
46 | 46 | * @return int units of work done |
47 | 47 | */ |
48 | - public function visit($work_to_do){ |
|
49 | - if(! $this->isDiscovered()){ |
|
48 | + public function visit($work_to_do) { |
|
49 | + if ( ! $this->isDiscovered()) { |
|
50 | 50 | $this->discover(); |
51 | 51 | } |
52 | - if($this->isComplete()){ |
|
52 | + if ($this->isComplete()) { |
|
53 | 53 | return 0; |
54 | 54 | } |
55 | 55 | return $this->work($work_to_do); |