Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipping to clone Worksheet object when cloning DrawingCollection #613

Closed
wants to merge 5 commits into from

Conversation

wnasich
Copy link
Contributor

@wnasich wnasich commented Jul 24, 2018

This is:

- [x] a bugfix
- [ ] a new feature

Checklist:

Why this change is needed?

Fixing issue #437

Copy link
Member

@PowerKiKi PowerKiKi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this can be merged as is, because the worksheet should still be cloned somehow.

{
public function testCloningWorksheetWithImages()
{
$filename = './data/Reader/Xls/with_images.xls';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refrain from adding binary files to the repo and instead create them from scratch, in memory with PhpSpreadsheet.

$clonedWorksheet = clone $worksheet;
$clonedDrawingCount = count($clonedWorksheet->getDrawingCollection());
self::assertEquals($originDrawingCount, $clonedDrawingCount);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should assert that the drawing collection is not the exact same object and was indeed cloned. Probably with assertNotSame.

And same for worksheet, it must be cloned. So the patch might be too simple as it is now.

wnasich added 2 commits July 25, 2018 17:10
…seDrawing::

Iterating over a copy of Worksheet:: because the proper way to add BaseDrawing to a Worksheet already add it to their drawingCollection attribute and in this case the foreach got a infinte loop
…ng cloned objects exist and they are differents
@wnasich
Copy link
Contributor Author

wnasich commented Jul 28, 2018

@PowerKiKi thanks for your feedback, I completed your suggestions I think

@PowerKiKi PowerKiKi closed this in 048947e Aug 5, 2018
@PowerKiKi
Copy link
Member

Thanks ! it's been merged

Dfred pushed a commit to Dfred/PhpSpreadsheet that referenced this pull request Nov 20, 2018
When cloning `BaseDrawing`, its worksheet will be set as null and thus be
orphaned. But when cloning the worksheet, it will re-assign itself as the
new worksheet for the BaseDrawing.

That way we avoid recursive cloning of a Worksheet that would clone a
BaseDrawing that would clone a Worksheet etc.

Fixes PHPOffice#437
Fixes PHPOffice#613
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants