protected function SmartSqlTest::saveMap in Smart SQL ID Map 1.1.x
Same name and namespace in other branches
- 1.0.x tests/src/Unit/Plugin/migrate/id_map/SmartSqlTest.php \Drupal\Tests\smart_sql_idmap\Unit\Plugin\migrate\id_map\SmartSqlTest::saveMap()
Saves a single ID mapping row in the database.
Parameters
array $map: The row to save.
Overrides MigrateSqlIdMapTest::saveMap
File
- tests/
src/ Unit/ Plugin/ migrate/ id_map/ SmartSqlTest.php, line 56
Class
- SmartSqlTest
- Tests the Smart SQL ID map plugin.
Namespace
Drupal\Tests\smart_sql_idmap\Unit\Plugin\migrate\id_mapCode
protected function saveMap(array $map) {
$table = $this
->getIdMap()
->mapTableName();
$schema = $this->database
->schema();
// If the table already exists, add any columns which are in the map array,
// but don't yet exist in the table. Yay, flexibility!
if ($schema
->tableExists($table)) {
foreach (array_keys($map) as $field) {
if (!$schema
->fieldExists($table, $field)) {
$schema
->addField($table, $field, [
'type' => 'text',
]);
}
}
}
else {
$schema
->createTable($table, $this
->createSchemaFromRow($map));
}
$this->database
->insert($table)
->fields($map)
->execute();
}