Bene has uploaded a new change for review.
https://gerrit.wikimedia.org/r/273063
Change subject: Use EntityDocument::copy over unserialize
......................................................................
Use EntityDocument::copy over unserialize
Change-Id: Ibb882edf4f71adde89f3bac820d7b3ed8fc41d67
---
M client/tests/phpunit/includes/ClientParserOutputDataUpdaterTest.php
M lib/tests/phpunit/MockRepository.php
M repo/includes/ChangeOp/ChangeOps.php
M repo/includes/EditEntity.php
M repo/includes/content/DeferredCopyEntityHolder.php
M repo/includes/content/EntityContent.php
6 files changed, 13 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/63/273063/1
diff --git
a/client/tests/phpunit/includes/ClientParserOutputDataUpdaterTest.php
b/client/tests/phpunit/includes/ClientParserOutputDataUpdaterTest.php
index cbc3bc4..a5d144d 100644
--- a/client/tests/phpunit/includes/ClientParserOutputDataUpdaterTest.php
+++ b/client/tests/phpunit/includes/ClientParserOutputDataUpdaterTest.php
@@ -33,6 +33,9 @@
*/
private $mockRepo = null;
+ /**
+ * @return Item[]
+ */
private function getItems() {
$items = array();
@@ -227,7 +230,7 @@
foreach ( $this->getItems() as $item ) {
$siteLinkLookup->putEntity( $item );
- $itemNoSiteLinks = unserialize( serialize( $item ) );
+ $itemNoSiteLinks = $item->copy();
$itemNoSiteLinks->setSiteLinkList( new SiteLinkList() );
$mockRepoNoSiteLinks->putEntity( $itemNoSiteLinks );
diff --git a/lib/tests/phpunit/MockRepository.php
b/lib/tests/phpunit/MockRepository.php
index 3cecaa5..ed92862 100644
--- a/lib/tests/phpunit/MockRepository.php
+++ b/lib/tests/phpunit/MockRepository.php
@@ -111,7 +111,7 @@
public function getEntity( EntityId $entityId ) {
$revision = $this->getEntityRevision( $entityId );
- return $revision === null ? null : unserialize( serialize(
$revision->getEntity() ) );
+ return $revision === null ? null :
$revision->getEntity()->copy();
}
/**
@@ -161,7 +161,7 @@
$revision = $revisions[$revisionId];
$revision = new EntityRevision( // return a copy!
- unserialize( serialize( $revision->getEntity() ) ), //
return a copy!
+ $revision->getEntity()->copy(), // return a copy!
$revision->getRevisionId(),
$revision->getTimestamp()
);
@@ -260,7 +260,7 @@
$this->maxRevisionId = max( $this->maxRevisionId, $revisionId );
$revision = new EntityRevision(
- unserialize( serialize( $entity ) ), // note: always
clone
+ $entity->copy(), // note: always clone
$revisionId,
wfTimestamp( TS_MW, $timestamp )
);
@@ -309,7 +309,7 @@
$this->maxRevisionId = max( $this->maxRevisionId, $revisionId );
$this->redirects[$key] = new RedirectRevision(
- unserialize( serialize( $redirect ) ),
+ $redirect, // EntityRedirect is immutable
$revisionId,
wfTimestamp( TS_MW, $timestamp )
);
diff --git a/repo/includes/ChangeOp/ChangeOps.php
b/repo/includes/ChangeOp/ChangeOps.php
index a846b0d..f87a370 100644
--- a/repo/includes/ChangeOp/ChangeOps.php
+++ b/repo/includes/ChangeOp/ChangeOps.php
@@ -98,7 +98,7 @@
public function validate( EntityDocument $entity ) {
$result = Result::newSuccess();
// deep clone of $entity to avoid side-effects
- $entity = unserialize( serialize( $entity ) );
+ $entity = $entity->copy();
foreach ( $this->changeOps as $changeOp ) {
$result = $changeOp->validate( $entity );
diff --git a/repo/includes/EditEntity.php b/repo/includes/EditEntity.php
index 3386537..0f39dc8 100644
--- a/repo/includes/EditEntity.php
+++ b/repo/includes/EditEntity.php
@@ -434,12 +434,12 @@
if ( $patch->isEmpty() ) {
// we didn't technically fix anything, but if there is
nothing to change,
// so just keep the current content as it is.
- $this->newEntity = unserialize( serialize(
$latestRev->getEntity() ) );
+ $this->newEntity = $latestRev->getEntity()->copy();
return true;
}
// apply the patch( base -> new ) to the latest revision.
- $patchedLatest = unserialize( serialize(
$latestRev->getEntity() ) );
+ $patchedLatest = $latestRev->getEntity()->copy();
$entityPatcher->patchEntity( $patchedLatest, $patch );
// detect conflicts against latest revision
diff --git a/repo/includes/content/DeferredCopyEntityHolder.php
b/repo/includes/content/DeferredCopyEntityHolder.php
index 1d3dbd4..128d612 100644
--- a/repo/includes/content/DeferredCopyEntityHolder.php
+++ b/repo/includes/content/DeferredCopyEntityHolder.php
@@ -48,7 +48,7 @@
public function getEntity( $expectedClass =
'Wikibase\DataModel\Entity\EntityDocument' ) {
if ( !$this->entity ) {
$entity = $this->entityHolder->getEntity(
$expectedClass );
- $this->entity = unserialize( serialize( $entity ) );
+ $this->entity = $entity->copy();
}
return $this->entity;
diff --git a/repo/includes/content/EntityContent.php
b/repo/includes/content/EntityContent.php
index b4ef640..0df7347 100644
--- a/repo/includes/content/EntityContent.php
+++ b/repo/includes/content/EntityContent.php
@@ -590,7 +590,7 @@
if ( $this->isRedirect() ) {
$entityAfterPatch = $this->makeEmptyEntity();
} else {
- $entityAfterPatch = unserialize( serialize(
$this->getEntity() ) );
+ $entityAfterPatch = $this->getEntity()->copy();
}
// FIXME: this should either be done in the derivatives, or the
patcher
--
To view, visit https://gerrit.wikimedia.org/r/273063
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibb882edf4f71adde89f3bac820d7b3ed8fc41d67
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Bene <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits