public function tag($table) { foreach ($this->sourceBucket as &$entry1) { if (is_null($entry1)) { continue; } foreach ($this->targetBucket as &$entry2) { if (is_null($entry2)) { continue; } if ($this->isKeyEqual($entry1, $entry2)) { // unset the fields to ignore $params = ParamsFactory::get(); if (isset($params->fieldsToIgnore[$table])) { foreach ($params->fieldsToIgnore[$table] as $fieldToIgnore) { unset($entry1[$fieldToIgnore]); unset($entry2[$fieldToIgnore]); } } $differ = new MapDiffer(); $diff = $differ->doDiff($entry2, $entry1); if (!empty($diff)) { $this->diffBucket[] = ['keys' => array_only($entry1, $this->key), 'diff' => $diff]; } $entry1 = null; $entry2 = null; } } } }
private function newDiffer() { $differ = new MapDiffer(); $differ->setComparisonCallback(function (Statement $fromStatement, Statement $toStatement) { return $fromStatement->equals($toStatement); }); return $differ; }
/** * Compares two revisions * * @param int $revision_id_from * @param int $revision_id_to * * @return array Key is the name of the column with changes. Value is an array * containing change type as well as new (revision to) and old (revision from) value. */ public function compareRevisions($revision_id_from, $revision_id_to) { $revision_from = $this->getRevision($revision_id_from); $revision_to = $this->getRevision($revision_id_to); $differ = new MapDiffer(); $diff = $differ->doDiff($revision_from->data, $revision_to->data); $out = []; foreach ($diff as $k => $v) { if ($k == 'created_at' || $k == 'updated_at') { continue; } $out[$k] = $v->toArray(); } return $out; }
public function tag() { foreach ($this->sourceBucket as &$entry1) { if (is_null($entry1)) { continue; } foreach ($this->targetBucket as &$entry2) { if (is_null($entry2)) { continue; } if ($this->isKeyEqual($entry1, $entry2)) { $differ = new MapDiffer(); $diff = $differ->doDiff($entry2, $entry1); if (!empty($diff)) { $this->diffBucket[] = ['keys' => array_only($entry1, $this->key), 'diff' => $diff]; } $entry1 = null; $entry2 = null; } } } }
public function testCallbackComparisonReturningNyanCat() { $differ = new MapDiffer(); $differ->setComparisonCallback(function ($foo, $bar) { return '~=[,,_,,]:3'; }); $this->setExpectedException('Exception'); $differ->doDiff(array(1, '2', 'baz'), array(1, 'foo', '2')); }
public function testEmptyElementsInRecursiveDiff() { $old = array('en' => array('a' => 'en-foo', 'b' => 'en-bar')); $new = array('en' => array('a' => 'en-foo', 'b' => 'en-bar')); $differ = new MapDiffer(true); $diff = new Diff($differ->doDiff($old, $new)); $this->assertTrue($diff->isEmpty()); $this->assertTrue($diff->getOperations() === array()); }
/** * @return \Diff\DiffOp\DiffOp[] */ protected function getDiff() { $oldModel = $this->oldModel ? $this->oldModel->toArray() : array(); $newModel = $this->newModel ? $this->newModel->toArray() : array(); return $this->differ->doDiff($oldModel, $newModel); }
public function getDiff($table) { Logger::info("Now calculating schema diff for table `{$table}`"); $diffSequence = []; $sourceSchema = $this->getSchema('source', $table); $targetSchema = $this->getSchema('target', $table); // Engine $sourceEngine = $sourceSchema['engine']; $targetEngine = $targetSchema['engine']; if ($sourceEngine != $targetEngine) { $diffSequence[] = new AlterTableEngine($table, $sourceEngine, $targetEngine); } // Collation $sourceCollation = $sourceSchema['collation']; $targetCollation = $targetSchema['collation']; if ($sourceCollation != $targetCollation) { $diffSequence[] = new AlterTableCollation($table, $sourceCollation, $targetCollation); } // Columns $sourceColumns = $sourceSchema['columns']; $targetColumns = $targetSchema['columns']; $differ = new MapDiffer(); $diffs = $differ->doDiff($targetColumns, $sourceColumns); foreach ($diffs as $column => $diff) { if ($diff instanceof \Diff\DiffOp\DiffOpRemove) { $diffSequence[] = new AlterTableDropColumn($table, $column, $diff); } else { if ($diff instanceof \Diff\DiffOp\DiffOpChange) { $diffSequence[] = new AlterTableChangeColumn($table, $column, $diff); } else { if ($diff instanceof \Diff\DiffOp\DiffOpAdd) { $diffSequence[] = new AlterTableAddColumn($table, $column, $diff); } } } } // Keys $sourceKeys = $sourceSchema['keys']; $targetKeys = $targetSchema['keys']; $differ = new MapDiffer(); $diffs = $differ->doDiff($targetKeys, $sourceKeys); foreach ($diffs as $key => $diff) { if ($diff instanceof \Diff\DiffOp\DiffOpRemove) { $diffSequence[] = new AlterTableDropKey($table, $key, $diff); } else { if ($diff instanceof \Diff\DiffOp\DiffOpChange) { $diffSequence[] = new AlterTableChangeKey($table, $key, $diff); } else { if ($diff instanceof \Diff\DiffOp\DiffOpAdd) { $diffSequence[] = new AlterTableAddKey($table, $key, $diff); } } } } // Constraints $sourceConstraints = $sourceSchema['constraints']; $targetConstraints = $targetSchema['constraints']; $differ = new MapDiffer(); $diffs = $differ->doDiff($targetConstraints, $sourceConstraints); foreach ($diffs as $name => $diff) { if ($diff instanceof \Diff\DiffOp\DiffOpRemove) { $diffSequence[] = new AlterTableDropConstraint($table, $name, $diff); } else { if ($diff instanceof \Diff\DiffOp\DiffOpChange) { $diffSequence[] = new AlterTableChangeConstraint($table, $name, $diff); } else { if ($diff instanceof \Diff\DiffOp\DiffOpAdd) { $diffSequence[] = new AlterTableAddConstraint($table, $name, $diff); } } } } return $diffSequence; }
public function diffItems(Item $from, Item $to) { $diffOps = $this->recursiveMapDiffer->doDiff($this->toDiffArray($from), $this->toDiffArray($to)); $diffOps['claim'] = $this->statementListDiffer->getDiff($from->getStatements(), $to->getStatements()); return new ItemDiff($diffOps); }
/** * Returns a diff between this EntityContent and the given EntityContent. * * @param EntityContent $toContent * * @return EntityContentDiff */ public function getDiff(EntityContent $toContent) { $fromContent = $this; $differ = new MapDiffer(); $redirectDiffOps = $differ->doDiff($fromContent->getRedirectData(), $toContent->getRedirectData()); $redirectDiff = new Diff($redirectDiffOps, true); $fromEntity = $fromContent->isRedirect() ? $this->makeEmptyEntity() : $fromContent->getEntity(); $toEntity = $toContent->isRedirect() ? $this->makeEmptyEntity() : $toContent->getEntity(); $entityDiffer = new EntityDiffer(); $entityDiff = $entityDiffer->diffEntities($fromEntity, $toEntity); return new EntityContentDiff($entityDiff, $redirectDiff); }
/** * @param array[] $from * @param array[] $to * * @return DiffOp[] */ private function diffPropertyArrays(array $from, array $to) { return $this->recursiveMapDiffer->doDiff($from, $to); }