public function __construct($arguments) { parent::__construct($arguments); // Make sure we can use it for node and term only. if (!in_array($this->entityType, array('node', 'taxonomy_term'))) { throw new Exception('\\SkeletonMigration supports only nodes and terms.'); } $this->description = t('Import @type - @bundle from SQL table', array('@type' => $this->entityType, '@bundle' => $this->bundle)); $this->fields = !empty($this->fields) ? $this->fields : array(); $sql_fields[] = '_unique_id'; if ($this->entityType == 'node') { $this->addFieldMapping('title', '_title'); $class_name = 'MigrateDestinationNode'; $sql_fields[] = '_title'; } elseif ($this->entityType == 'taxonomy_term') { $this->addFieldMapping('name', '_name'); $class_name = 'MigrateDestinationTerm'; $sql_fields[] = '_name'; } // Rebuild the csv columns array. $this->fields = array_merge($sql_fields, $this->fields); // Create a map object for tracking the relationships between source rows $key = array('_unique_id' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE)); $destination_handler = new MigrateDestinationEntityAPI($this->entityType, $this->bundle); $this->map = new MigrateSQLMap($this->machineName, $key, $destination_handler->getKeySchema($this->entityType)); // Create a MigrateSource object. $sql_table = isset($this->sqlTable) ? '_raw_' . $this->sqlTable : '_raw_' . $this->bundle; $query = db_select($sql_table, 't')->fields('t')->orderBy('__id'); $this->source = new MigrateSourceSQL($query, $this->fields); $this->destination = new $class_name($this->bundle, array('text_format' => 'filtered_html')); }
public function __construct() { parent::__construct(); // Map fields that don't need extra definitions. $field_names = array('id', 'weekday', 'hour_from', 'hour_to', 'cap'); $this->addSimpleMappings($field_names); $this->addFieldMapping('meter_nid', 'meter_nid')->sourceMigration(array('NegawattIecMeterMigrate', 'NegawattModbusMeterMigrate')); $this->description = t('Import @type - from CSV file.', array('@type' => $this->entityType)); // Create a map object for tracking the relationships between source rows $key = array('id' => array('type' => 'int', 'not null' => TRUE)); $destination_handler = new MigrateDestinationEntityAPI($this->entityType, $this->bundle); $this->map = new MigrateSQLMap($this->machineName, $key, $destination_handler->getKeySchema($this->entityType)); // Create a MigrateSource object. $sql_migrate = variable_get('negawatt_migrate_sql', FALSE); if ($sql_migrate) { // SQL migration. $query = db_select('_negawatt_power_cap_analyzer_info_migrate', $this->bundle)->fields($this->bundle, $field_names); $this->source = new MigrateSourceSQL($query); } else { // CSV migration. // Allow using variable to set path other than default. $csv_path = variable_get('negawatt_migrate_csv_path', drupal_get_path('module', 'negawatt_migrate') . '/csv'); $this->source = new MigrateSourceCSV($csv_path . '/normalizer/' . $this->entityType . '.csv', $this->csvColumns, array('header_rows' => 1)); } $this->destination = new MigrateDestinationEntityAPI($this->entityType, $this->bundle); }
public function __construct() { parent::__construct(); $this->description = t('Import @bundle terms from CSV file.', array('@bundle' => $this->bundle)); // Map fields that don't need extra definitions. $field_names = array('id', 'name', 'weight', 'description', 'field_icon_categories'); $this->addSimpleMappings($field_names); $this->addFieldMapping('account_id', 'account_id')->sourceMigration('NegawattAccountMigrate'); // Create a map object for tracking the relationships between source rows $key = array('id' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE)); $destination_handler = new MigrateDestinationEntityAPI('taxonomy_term', $this->bundle); $this->map = new MigrateSQLMap($this->machineName, $key, $destination_handler->getKeySchema('taxonomy_term')); // Create a MigrateSource object. $csv_file = 'taxonomy_term/' . $this->bundle . '.csv'; $this->source = new MigrateSourceCSV(drupal_get_path('module', 'negawatt_migrate') . '/csv/' . $csv_file, $this->csvColumns, array('header_rows' => 1)); $this->destination = new MigrateDestinationTerm($this->bundle); }
public function __construct($arguments = array()) { parent::__construct($arguments); // Make sure we can use it for node and term only. if (!in_array($this->entityType, array('node', 'taxonomy_term'))) { throw new Exception('\\NegawattMigration supports only nodes and terms.'); } $this->description = t('Import @type - @bundle from CSV file.', array('@type' => $this->entityType, '@bundle' => $this->bundle)); $this->csvColumns = !empty($this->csvColumns) ? $this->csvColumns : array(); $csv_cols[] = array('Unique_ID', 'Unique_ID'); if ($this->entityType == 'node') { $this->addFieldMapping('title', 'title'); $class_name = 'MigrateDestinationNode'; $csv_cols[] = array('title', 'Title'); } elseif ($this->entityType == 'taxonomy_term') { $this->addFieldMapping('name', 'name'); $class_name = 'MigrateDestinationTerm'; $csv_cols[] = array('name', 'Name'); } // Rebuild the csv columns array. $this->csvColumns = array_merge($csv_cols, $this->csvColumns); // Create a map object for tracking the relationships between source rows $key = array('Unique_ID' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE)); $destination_handler = new MigrateDestinationEntityAPI($this->entityType, $this->bundle); $this->map = new MigrateSQLMap($this->machineName, $key, $destination_handler->getKeySchema($this->entityType)); // Create a MigrateSource object. $sql_migrate = variable_get('negawatt_migrate_sql', FALSE); if ($sql_migrate) { // SQL migration. // Prepare sql column names from csvColumns $sqlColumns = array(); foreach ($this->csvColumns as $col) { $sqlColumns[] = $col[0]; } $query = db_select('_negawatt_' . $this->bundle . '_migrate', $this->bundle)->fields($this->bundle, $sqlColumns); $this->source = new MigrateSourceSQL($query); } else { // CSV migration. // Allow using variable to set path other than default. $csv_path = variable_get('negawatt_migrate_csv_path', drupal_get_path('module', 'negawatt_migrate') . '/csv'); $this->source = new MigrateSourceCSV($csv_path . '/' . $this->entityType . '/' . $this->bundle . '.csv', $this->csvColumns, array('header_rows' => 1)); } $this->destination = new $class_name($this->bundle, array('text_format' => 'filtered_html')); }