Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('/home/gauntlet/webapps/d7/sites/all/modules/field_collection/field_collection.migrate.inc');
- function migrate_glegacy_migrate_api() {
- $api = array(
- 'api' => 2,
- );
- return $api;
- }
- function refresh_gauntlet_database() {
- exec('/home/gauntlet/gauntlet_a_to_gauntlet_d7.sh');
- }
- class GauntletStoriesMigration extends Migration {
- public function __construct() {
- parent::__construct();
- $this->description = 'Migrate stories first.';
- $this->map = new MigrateSQLMap($this->machineName,
- array(
- 'sid' => array(
- 'type' => 'int',
- 'length' => 15,
- 'unsigned' => FALSE,
- 'alias' => 's',
- 'not null' => FALSE
- )
- ),
- MigrateDestinationNode::getKeySchema()
- );
- $query = db_select('dbStory', 's');
- $query->leftJoin('dbBodytext', 'b', 's.sid = b.sid');
- // $query->leftJoin(array('dbBodytext', 'dbAuthors', 'dbImages'), array('bt', 'a', 'i'), array('s.SID=bt.SID', 's.SID=a.SID', 's.SID=i.SID')); //begin merging tables, start with BodyTexts...
- /* ->leftJoin('dbAuthors', 'a', 's.SID=a.SID') // Authors...
- ->leftJoin('dbImages', 'i', 's.SID=i.SID') // Images...
- */
- $query->fields('s',
- array(
- 'sid',
- 'Rank',
- 'Date',
- 'Section',
- 'GID',
- 'headline',
- 'Deck',
- 'Tab',
- 'HideOnIndexes',
- 'Special',
- 'Locked',
- )
- );
- $query->fields('b', array('storytext'));
- /* ->fields('a', array('Author', 'Position'))
- ->fields('i', array('File', 'Caption', 'Credit', 'Source'));*/
- /* $query->addExpression('GROUP_CONCAT(DISTINCT a.Author)', 'authors');
- $query->addExpression('GROUP_CONCAT(DISTINCT a.Position)', 'positions');
- $query->addExpression('GROUP_CONCAT(DISTINCT i.File)', 'images');
- $query->addExpression('GROUP_CONCAT(DISTINCT i.Caption)', 'captions');
- $query->addExpression('GROUP_CONCAT(DISTINCT i.Credit)', 'credits');
- $query->addExpression('GROUP_CONCAT(DISTINCT i.Source)', 'sources');*/
- $query->groupBy('s.sid');
- $this->source = new MigrateSourceSQL($query);
- $this->destination = new MigrateDestinationNode('article');
- $this->addFieldMapping('title', 'headline')
- ->description('Import headlines');
- $this->addFieldMapping('nid', 'sid')
- ->description('Preserve old SID as Drupal NID.');
- $this->addFieldMapping('is_new')
- ->defaultValue(TRUE);
- $this->addFieldMapping('body', 'storytext')
- ->arguments(array('format' => 'full_html'));
- // Since the excerpt is mapped via an argument, add a null mapping so it's
- // not flagged as unmapped
- $this->addFieldMapping(NULL, 'excerpt');
- }
- }
- class GauntletBylinesMigration extends GauntletStoriesMigration {
- public function __construct() {
- parent::__construct();
- $this->dependencies = array('GauntletStories');
- $query = db_select('dbAuthors', 'l');
- $query->fields('l', array(
- 'aid',
- 'sid',
- 'author',
- 'position',
- ));
- $this->source = new MigrateSourceSQL($query);
- $this->destination = new MigrateDestinationFieldCollection('field_bylines', array('host_entity_type' => 'node')); //changed 'hostEntityType' to 'host_entity_type'. Seems to have eliminated an error.
- $this->map = new MigrateSQLMap(
- $this->machineName,
- array(
- 'aid' => array(
- 'type' => 'int',
- 'length' => 9,
- 'not null' => TRUE,
- 'alias' => 'l',
- ),
- ),
- MigrateDestinationFieldCollection::getKeySchema()
- );
- $this->addFieldMapping('host_entity_id', 'sid')->sourceMigration('GauntletStories');
- $this->addFieldMapping('field_byline_author', 'author');
- $this->addFieldMapping('field_byline_position', 'position');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement