On several trials, I noticed that despite using $phpWord->getSettings()->setUpdateFields(true);, when the generated file was first opened, the chapter index only updated the page numbers and not the list as well, thus losing the references to any paragraphs (H2 and H3) in the document.
On subsequent openings of the file, Word requests the updating of the table of contents fields, but requires the user to specifically select the "update entire table of contents" option, so in the case of a different choice ("update page numbers only") the references to the paragraphs present in each chapter are lost, as mentioned above.
The change made in PhpWord/Writer/Word2007/Element/TOC.php on line 116 allows the entire table of contents to be automatically updated by only requiring the generic update of the fields, but without requiring the second step, whatever the number of file openings.
Fixes #1691 #1396
Checklist:
[x] I have run composer run-script check --timeout=0 and no errors were reported
[x] The new code is covered by unit tests (check build/coverage for coverage report)
[x] I have updated the documentation to describe the changes
coverage: 97.217%. remained the same
when pulling 79effbe7108625e9e5c88e3f7999357e9c20c2a6 on jgiacomello:TOC_numbers_fix
into 2f4da6e491643c88f3c5d2892f5a63febb66b313 on PHPOffice:master.
Description
On several trials, I noticed that despite using
$phpWord->getSettings()->setUpdateFields(true);
, when the generated file was first opened, the chapter index only updated the page numbers and not the list as well, thus losing the references to any paragraphs (H2 and H3) in the document. On subsequent openings of the file, Word requests the updating of the table of contents fields, but requires the user to specifically select the "update entire table of contents" option, so in the case of a different choice ("update page numbers only") the references to the paragraphs present in each chapter are lost, as mentioned above.The change made in
PhpWord/Writer/Word2007/Element/TOC.php
on line116
allows the entire table of contents to be automatically updated by only requiring the generic update of the fields, but without requiring the second step, whatever the number of file openings.Fixes #1691 #1396
Checklist:
composer run-script check --timeout=0
and no errors were reported