本文整理汇总了PHP中Drupal\migrate\Row::getHash方法的典型用法代码示例。如果您正苦于以下问题:PHP Row::getHash方法的具体用法?PHP Row::getHash怎么用?PHP Row::getHash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\migrate\Row
的用法示例。
在下文中一共展示了Row::getHash方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveIdMapping
/**
* {@inheritdoc}
*/
public function saveIdMapping(Row $row, array $destination_id_values, $source_row_status = MigrateIdMapInterface::STATUS_IMPORTED, $rollback_action = MigrateIdMapInterface::ROLLBACK_DELETE)
{
// Construct the source key.
$source_id_values = $row->getSourceIdValues();
// Construct the source key and initialize to empty variable keys.
$keys = array();
foreach ($this->sourceIdFields() as $field_name => $key_name) {
// A NULL key value will fail.
if (!isset($source_id_values[$field_name])) {
$this->message->display(t('Could not save to map table due to NULL value for key field @field', array('@field' => $field_name)), 'error');
return;
}
$keys[$key_name] = $source_id_values[$field_name];
}
$fields = array('source_row_status' => (int) $source_row_status, 'rollback_action' => (int) $rollback_action, 'hash' => $row->getHash());
$count = 0;
foreach ($destination_id_values as $dest_id) {
$fields['destid' . ++$count] = $dest_id;
}
if ($count && $count != count($this->destinationIdFields())) {
$this->message->display(t('Could not save to map table due to missing destination id values'), 'error');
return;
}
if ($this->migration->get('trackLastImported')) {
$fields['last_imported'] = time();
}
if ($keys) {
// Notify anyone listening of the map row we're about to save.
$this->eventDispatcher->dispatch(MigrateEvents::MAP_SAVE, new MigrateMapSaveEvent($this, $keys + $fields));
$this->getDatabase()->merge($this->mapTableName())->key($keys)->fields($fields)->execute();
}
}
示例2: testHashing
/**
* Tests hashing.
*/
public function testHashing()
{
$row = new Row($this->testValues, $this->testSourceIds);
$this->assertSame('', $row->getHash(), 'No hash at creation');
$row->rehash();
$this->assertSame($this->testHash, $row->getHash(), 'Correct hash.');
$row->rehash();
$this->assertSame($this->testHash, $row->getHash(), 'Correct hash even doing it twice.');
// Set the map to needs update.
$test_id_map = array('original_hash' => '', 'hash' => '', 'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE);
$row->setIdMap($test_id_map);
$this->assertTrue($row->needsUpdate());
$row->rehash();
$this->assertSame($this->testHash, $row->getHash(), 'Correct hash even if id_mpa have changed.');
$row->setSourceProperty('title', 'new title');
$row->rehash();
$this->assertSame($this->testHashMod, $row->getHash(), 'Hash changed correctly.');
// Check hash calculation algorithm.
$hash = hash('sha256', serialize($row->getSource()));
$this->assertSame($hash, $row->getHash());
// Check length of generated hash used for mapping schema.
$this->assertSame(64, strlen($row->getHash()));
// Set the map to successfully imported.
$test_id_map = array('original_hash' => '', 'hash' => '', 'source_row_status' => MigrateIdMapInterface::STATUS_IMPORTED);
$row->setIdMap($test_id_map);
$this->assertFalse($row->needsUpdate());
// Set the same hash value and ensure it was not changed.
$random = $this->randomMachineName();
$test_id_map = array('original_hash' => $random, 'hash' => $random, 'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE);
$row->setIdMap($test_id_map);
$this->assertFalse($row->changed());
// Set different has values to ensure it is marked as changed.
$test_id_map = array('original_hash' => $this->randomMachineName(), 'hash' => $this->randomMachineName(), 'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE);
$row->setIdMap($test_id_map);
$this->assertTrue($row->changed());
}