@@ -98,7 +98,7 @@ public function analyze($registryBefore, $registryAfter)
98
98
if ($ addedNodes ) {
99
99
$ afterFile = $ registryAfter ->mapping [XmlRegistry::NODES_KEY ][$ moduleName ];
100
100
$ duplicateNode = $ this ->reportAddedNodesWithDuplicateCheck ($ afterFile , $ addedNodes , $ moduleNodesBefore );
101
- print_r ('Duplicate node ' . $ duplicateNode. ' found ' );
101
+ print_r ('Duplicate node ' . ( $ duplicateNode ? ' found ' : ' not found ') );
102
102
print_r ("After file " . $ afterFile );
103
103
if ($ duplicateNode ) {
104
104
$ this ->reportDuplicateNodes ($ afterFile , $ addedNodes );
@@ -126,9 +126,6 @@ private function reportAddedNodesWithDuplicateCheck($afterFile, $addedNodes, $mo
126
126
foreach ($ addedNodes as $ nodeId => $ node ) {
127
127
$ this ->inspectObject ($ node );
128
128
129
- print_r ('Modulesfsdfsfdsf node before in reportAddedNodesWithDuplicateCheck method ' );
130
- print_r ($ moduleNodesBefore );
131
-
132
129
// Check for duplicates by comparing node content except for 'id'
133
130
foreach ($ moduleNodesBefore as $ existingNodeId => $ existingNode ) {
134
131
if ($ this ->isDuplicateNode ($ node , $ existingNode )) {
@@ -150,12 +147,12 @@ private function inspectObject($object)
150
147
151
148
echo "\nProperties: \n" ;
152
149
foreach ($ properties as $ property ) {
153
- echo $ property ->getName () . "\n" ;
150
+ // echo $property->getName() . "\n";
154
151
}
155
152
156
153
echo "\nMethods: \n" ;
157
154
foreach ($ methods as $ method ) {
158
- echo $ method ->getName () . "\n" ;
155
+ // echo $method->getName() . "\n";
159
156
}
160
157
}
161
158
@@ -168,17 +165,61 @@ private function inspectObject($object)
168
165
*/
169
166
private function isDuplicateNode ($ node , $ existingNode )
170
167
{
171
- print_r ('\nis Duplicated node\n ' );
172
- // Get node data excluding 'id' and 'parent' for comparison
173
- $ nodeData = $ this ->getNodeData ($ node );
168
+ // Extract data from both nodes
169
+ $ newNodeData = $ this ->getNodeData ($ node );
174
170
$ existingNodeData = $ this ->getNodeData ($ existingNode );
171
+ /* echo "\n New Node\n";
172
+ print_r($newNodeData);
173
+ echo "\n~~~~~~~~~~~~~~~\n";
174
+ echo "\n Existing Node\n";
175
+ print_r($existingNodeData);*/
176
+ // Remove 'id' from both nodes for comparison, including from the path
177
+ unset($ newNodeData ['id ' ], $ existingNodeData ['id ' ]);
178
+ $ newNodePath = $ this ->removeLastPart ($ newNodeData ['path ' ]);
179
+ $ existingNodePath = $ this ->removeLastPart ($ existingNodeData ['path ' ]);
180
+
181
+ // print_r($newNodeData());
182
+
183
+ // Set the modified paths without the 'id'
184
+ $ newNodeData ['path ' ] = $ newNodePath ;
185
+ $ existingNodeData ['path ' ] = $ existingNodePath ;
186
+
187
+ // Compare the remaining data (skip source_model since it's not provided)
188
+ foreach ($ newNodeData as $ key => $ newValue ) {
189
+ if (isset ($ existingNodeData [$ key ])) {
190
+ $ existingValue = $ existingNodeData [$ key ];
191
+ echo "\nNew Value " .$ newValue ." !== Existing Value " . $ existingValue ."\n" ;
192
+ if (trim ($ newValue ) == trim ($ existingValue )) {
193
+ echo "\nCame in condition. \n" ;
194
+ echo "Property ' $ key' does not match between nodes. \n" ;
195
+ return true ;
196
+ }
197
+ } else {
198
+ echo "Property ' $ key' missing in the existing node. \n" ;
199
+ return false ;
200
+ }
201
+ }
175
202
176
- echo "\nnddata \n" ;
177
- print_r ($ nodeData );
178
- echo "\nexisting node \n" ;
179
- print_r ($ existingNodeData );
180
- // Compare the remaining parts of the nodes
181
- return $ nodeData == $ existingNodeData ;
203
+ // If all properties match (except 'id'), the nodes are duplicates
204
+ echo "Nodes are duplicates based on their content. \n" ;
205
+ return false ;
206
+ }
207
+
208
+ /* private function getNodeData($node)
209
+ {
210
+ return [
211
+ 'path' => $node->getPath(),
212
+ 'uniqueKey' => $node->getUniqueKey(),
213
+ // Add more properties to compare if available, but exclude 'source_model'
214
+ ];
215
+ }*/
216
+
217
+ private function removeLastPart ($ path )
218
+ {
219
+ // Remove the last part of the path (usually the 'id') to compare node structure without it
220
+ $ pathParts = explode ('/ ' , $ path );
221
+ array_pop ($ pathParts ); // Remove the last part
222
+ return implode ('/ ' , $ pathParts ); // Return the path without the 'id'
182
223
}
183
224
184
225
private function getNodeData ($ node )
@@ -203,22 +244,6 @@ private function getNodeData($node)
203
244
return $ data ;
204
245
}
205
246
206
- /**
207
- * Simplifies the reflection to get property
208
- *
209
- * @param $object
210
- * @param $propertyName
211
- * @return mixed
212
- * @throws \ReflectionException
213
- */
214
- private function getPrivateProperty ($ object , $ propertyName )
215
- {
216
- $ reflection = new \ReflectionClass ($ object );
217
- $ property = $ reflection ->getProperty ($ propertyName );
218
- $ property ->setAccessible (true );
219
- return $ property ->getValue ($ object );
220
- }
221
-
222
247
/**
223
248
* Extracts the node from <var>$registry</var> as an associative array.
224
249
*
@@ -293,7 +318,6 @@ private function reportDuplicateNodes(string $file, array $nodes)
293
318
{
294
319
print_r ('Duplicate Nodes switch case ' );
295
320
foreach ($ nodes as $ node ) {
296
- echo "<br/> $ node ->getPath () <br/> " ;
297
321
switch (true ) {
298
322
case $ node instanceof Field:
299
323
$ this ->report ->add ('system ' , new FieldDuplicated ($ file , $ node ->getPath ()));
0 commit comments