General : Fixed copying bug when presentation had multiple slides #786
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If in the original code you would add a dump of the slide collection like the example below and try to copy a presentation with three slides you'll get an exception:
The code:
The dump output:
Because of the
rebindParent()
which is being called on the copied slide, the copied presentation's original$slideCollection
is being edited. This causes the code to break. This PR fixes that problem by saving the original$slideCollection
before starting the slide copying process. Afterwards we set the new slide collection to the new copied presentation and also revert the original contact of the old presentation which is being copied.I've also updated the unit test so that a presentation with multiple slides is being copied. If you test the unit test without the changes in
PhpOffice\PhpPresentation\PhpPresentation
you can also see the exception being thrown: