@@ -98,7 +98,7 @@ public function analyze($registryBefore, $registryAfter)
9898 if ($ addedNodes ) {
9999 $ afterFile = $ registryAfter ->mapping [XmlRegistry::NODES_KEY ][$ moduleName ];
100100 $ duplicateNode = $ this ->reportAddedNodesWithDuplicateCheck ($ afterFile , $ addedNodes , $ moduleNodesBefore );
101- print_r ('Duplicate node ' . $ duplicateNode. ' found ' );
101+ print_r ('Duplicate node ' . ( $ duplicateNode ? ' found ' : ' not found ') );
102102 print_r ("After file " . $ afterFile );
103103 if ($ duplicateNode ) {
104104 $ this ->reportDuplicateNodes ($ afterFile , $ addedNodes );
@@ -126,9 +126,6 @@ private function reportAddedNodesWithDuplicateCheck($afterFile, $addedNodes, $mo
126126 foreach ($ addedNodes as $ nodeId => $ node ) {
127127 $ this ->inspectObject ($ node );
128128
129- print_r ('Modulesfsdfsfdsf node before in reportAddedNodesWithDuplicateCheck method ' );
130- print_r ($ moduleNodesBefore );
131-
132129 // Check for duplicates by comparing node content except for 'id'
133130 foreach ($ moduleNodesBefore as $ existingNodeId => $ existingNode ) {
134131 if ($ this ->isDuplicateNode ($ node , $ existingNode )) {
@@ -150,12 +147,12 @@ private function inspectObject($object)
150147
151148 echo "\nProperties: \n" ;
152149 foreach ($ properties as $ property ) {
153- echo $ property ->getName () . "\n" ;
150+ // echo $property->getName() . "\n";
154151 }
155152
156153 echo "\nMethods: \n" ;
157154 foreach ($ methods as $ method ) {
158- echo $ method ->getName () . "\n" ;
155+ // echo $method->getName() . "\n";
159156 }
160157 }
161158
@@ -168,17 +165,61 @@ private function inspectObject($object)
168165 */
169166 private function isDuplicateNode ($ node , $ existingNode )
170167 {
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 );
174170 $ 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+ }
175202
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'
182223 }
183224
184225 private function getNodeData ($ node )
@@ -203,22 +244,6 @@ private function getNodeData($node)
203244 return $ data ;
204245 }
205246
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-
222247 /**
223248 * Extracts the node from <var>$registry</var> as an associative array.
224249 *
@@ -293,7 +318,6 @@ private function reportDuplicateNodes(string $file, array $nodes)
293318 {
294319 print_r ('Duplicate Nodes switch case ' );
295320 foreach ($ nodes as $ node ) {
296- echo "<br/> $ node ->getPath () <br/> " ;
297321 switch (true ) {
298322 case $ node instanceof Field:
299323 $ this ->report ->add ('system ' , new FieldDuplicated ($ file , $ node ->getPath ()));
0 commit comments