Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.4.1

Bug #21246 File_MARC_Data_Field::deleteSubfield does not work as expected
Submitted: 2017-10-08 21:40 UTC
From: danmichaelo Assigned:
Status: Analyzed Package: File_MARC (version 1.1.5)
PHP Version: 5.6.31 OS: macOS 10.13
Roadmaps: (Not assigned)    
Subscription  


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 45 - 31 = ?

 
 [2017-10-08 21:40 UTC] danmichaelo (Dan Michael Heggø)
Description: ------------ Removing multiple subfields using deleteSubfield does not work as expected. The problem is that the method doesn't call $n->setPosition($pos) on the subfields that follow the removed field. I wasn't familiar with the SplDoublyLinkedList structure from before, but I tried cooking together a patch that at least solves my issue. Test script: --------------- require 'vendor/autoload.php'; require 'File/MARC/Data_Field.php'; $field = new File_MARC_Data_Field(650, [ new File_MARC_Subfield('9', 'test1'), new File_MARC_Subfield('9', 'test2'), new File_MARC_Subfield('0', 'test3'), new File_MARC_Subfield('9', 'test4'), ]); echo "--- Before: ---\n$field\n\n"; foreach ($field->getSubfields('9') as $subfield) { echo "Deleting subfield: $subfield\n"; $field->deleteSubfield($subfield); } echo "\n--- After: ---\n$field\n\n"; Expected result: ---------------- --- Before: --- 650 _9test1 _9test2 _0test3 _9test4 Deleting subfield: [9]: test1 Deleting subfield: [9]: test2 Deleting subfield: [9]: test4 --- After: --- 650 _0test3 Actual result: -------------- --- Before: --- 650 _9test1 _9test2 _0test3 _9test4 Deleting subfield: [9]: test1 Deleting subfield: [9]: test2 Deleting subfield: [9]: test4 --- After: --- 650 _9test2 _9test4

Comments

 [2017-10-08 21:43 UTC] danmichaelo (Dan Michael Heggø)
 [2017-12-04 09:55 UTC] dbs (Dan Scott)
Would you be willing to add a test script that shows the call not working until your patch is applied?
 [2017-12-04 10:00 UTC] dbs (Dan Scott)
-Status: Open +Status: Analyzed
Wait - I'll just adapt what you've put here into a test script. Thank you!