/** * @param string $action * @param EntityId $entityId * @param Diff $diff * @param array $fields * * @return EntityChange */ private function newEntityChange($action, EntityId $entityId, Diff $diff, array $fields) { /** @var EntityChange $instance */ $instance = new ItemChange($fields); if (!$instance->hasField('object_id')) { $instance->setField('object_id', $entityId->getSerialization()); } if (!$instance->hasField('info')) { $instance->setField('info', array()); } // Note: the change type determines how the client will // instantiate and handle the change $type = 'wikibase-' . $entityId->getEntityType() . '~' . $action; $instance->setField('type', $type); $instance->setDiff($diff); return $instance; }
public function changeBackwardsCompatProvider() { global $wgDevelopmentWarnings; //NOTE: Disable developer warnings that may get triggered by // the B/C code path. $wgDevelopmentWarnings = false; \MediaWiki\suppressWarnings(); try { $cases = array(); // -------- // We may hit a plain diff generated by old code. // Make sure we can deal with that. $diff = new Diff(); $change = new ItemChange(array('type' => 'test')); $change->setDiff($diff); $cases['plain-diff'] = array($change); // -------- // Bug T53363: As of commit ff65735a125e, MapDiffer may generate atomic diffs for // substructures even in recursive mode. Make sure we can handle them // if we happen to load them from the database or such. $diff = new ItemDiff(array('links' => new DiffOpChange(array('foowiki' => 'X', 'barwiki' => 'Y'), array('barwiki' => 'Y', 'foowiki' => 'X')))); // make sure we got the right key for sitelinks assert($diff->getSiteLinkDiff() !== null); //NOTE: ItemChange's constructor may or may not already fix the bad diff. $change = new ItemChange(array('type' => 'test')); $change->setDiff($diff); $cases['atomic-sitelink-diff'] = array($change); $wgDevelopmentWarnings = true; \MediaWiki\restoreWarnings(); return $cases; } catch (Exception $ex) { $wgDevelopmentWarnings = true; \MediaWiki\restoreWarnings(); throw $ex; } }