Last active
October 22, 2016 05:37
-
-
Save szeidler/2ea06b66bf79d774a67e to your computer and use it in GitHub Desktop.
Drupal Migration example class of geofield fields.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class HotelMigration extends Migration { | |
public function __construct(array $arguments) { | |
parent::__construct($arguments); | |
$this->description = t('Import of hotels'); | |
$columns = array( | |
0 => array('StreetId', 'StreetId'), | |
1 => array('StreetName', 'StreetName'), | |
2 => array('PostAddressId', 'PostAddressId'), | |
4 => array('Area', 'Area'), | |
6 => array('ZoneNo', 'ZoneNo'), | |
11 => array('Longitude', 'Longitude'), | |
12 => array('Latitude', 'Latitude'), | |
); | |
$this->source = new MigrateSourceCSV(drupal_realpath('public://') . '/migrate/hotell_sorensen.csv', $columns, array( | |
'delimiter' => ',', | |
'header_rows' => 1 | |
)); | |
$this->destination = new MigrateDestinationNode('hotel'); | |
$this->map = new MigrateSQLMap( | |
$this->machineName, | |
array( | |
'StreetId' => array( | |
'type' => 'int', | |
'unsigned' => TRUE, | |
'not null' => TRUE, | |
) | |
), | |
MigrateDestinationNode::getKeySchema() | |
); | |
$this->addFieldMapping('title', 'StreetName'); | |
$this->addFieldMapping('field_street_id', 'StreetId'); | |
$this->addFieldMapping('field_address')->defaultValue('NO'); | |
$this->addFieldMapping('field_address:thoroughfare', 'Area'); | |
$this->addFieldMapping('field_address:postal_code', 'PostAddressId'); | |
$this->addFieldMapping('field_address:locality')->defaultValue('Tromsø'); | |
$this->addFieldMapping('field_zone_no', 'ZoneNo'); | |
$this->addFieldMapping('field_geofield')->defaultValue('Point'); | |
$this->addFieldMapping('field_geofield:input_format')->defaultValue('lat/lon'); | |
$this->addFieldMapping('field_geofield:geo_type')->defaultValue('point'); | |
$this->addFieldMapping('field_geofield:lat', 'Latitude'); | |
$this->addFieldMapping('field_geofield:lon', 'Longitude'); | |
} | |
public function prepareRow($row) { | |
$row->Longitude = $row->Longitude / 100000; | |
$row->Latitude = $row->Latitude / 100000; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment