Advertisement
Guest User

field_collection problem

a guest
Jan 30th, 2012
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.81 KB | None | 0 0
  1. <?php
  2. require_once('/home/gauntlet/webapps/d7/sites/all/modules/field_collection/field_collection.migrate.inc');
  3. function migrate_glegacy_migrate_api() {
  4.   $api = array(
  5.     'api' => 2,
  6.   );
  7.   return $api;
  8. }
  9.  
  10. function refresh_gauntlet_database() {
  11.     exec('/home/gauntlet/gauntlet_a_to_gauntlet_d7.sh');
  12. }
  13.  
  14. class GauntletStoriesMigration extends Migration {
  15.     public function __construct() {
  16.         parent::__construct();
  17.         $this->description = 'Migrate stories first.';
  18.        
  19.         $this->map = new MigrateSQLMap($this->machineName,
  20.             array(
  21.                 'sid' => array(
  22.                             'type' => 'int',
  23.                             'length' => 15,
  24.                             'unsigned' => FALSE,
  25.                             'alias' => 's',
  26.                             'not null' => FALSE
  27.                 )
  28.                
  29.             ),
  30.             MigrateDestinationNode::getKeySchema()
  31.         );     
  32.        
  33.        
  34.         $query = db_select('dbStory', 's');                
  35.         $query->leftJoin('dbBodytext', 'b', 's.sid = b.sid');
  36.                    
  37.     //  $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...
  38.                 /*  ->leftJoin('dbAuthors', 'a', 's.SID=a.SID') // Authors...
  39.                     ->leftJoin('dbImages', 'i', 's.SID=i.SID') // Images...
  40.                 */ 
  41.         $query->fields('s',
  42.                             array(
  43.                                 'sid',
  44.                                 'Rank',
  45.                                 'Date',
  46.                                 'Section',
  47.                                 'GID',
  48.                                 'headline',
  49.                                 'Deck',
  50.                                 'Tab',
  51.                                 'HideOnIndexes',
  52.                                 'Special',
  53.                                 'Locked',
  54.                                 )
  55.                             );
  56.         $query->fields('b', array('storytext'));                       
  57.     /*              ->fields('a', array('Author', 'Position'))
  58.                     ->fields('i', array('File', 'Caption', 'Credit', 'Source'));*/
  59. /*      $query->addExpression('GROUP_CONCAT(DISTINCT a.Author)', 'authors');
  60.         $query->addExpression('GROUP_CONCAT(DISTINCT a.Position)', 'positions');
  61.         $query->addExpression('GROUP_CONCAT(DISTINCT i.File)', 'images');
  62.         $query->addExpression('GROUP_CONCAT(DISTINCT i.Caption)', 'captions');
  63.         $query->addExpression('GROUP_CONCAT(DISTINCT i.Credit)', 'credits');
  64.         $query->addExpression('GROUP_CONCAT(DISTINCT i.Source)', 'sources');*/
  65.         $query->groupBy('s.sid');      
  66.        
  67.         $this->source = new MigrateSourceSQL($query);
  68.         $this->destination = new MigrateDestinationNode('article');
  69.  
  70.         $this->addFieldMapping('title', 'headline')    
  71.              ->description('Import headlines');
  72.         $this->addFieldMapping('nid', 'sid')
  73.              ->description('Preserve old SID as Drupal NID.');
  74.         $this->addFieldMapping('is_new')
  75.              ->defaultValue(TRUE);   
  76.  
  77.         $this->addFieldMapping('body', 'storytext')
  78.              ->arguments(array('format' => 'full_html'));
  79.         // Since the excerpt is mapped via an argument, add a null mapping so it's
  80.         // not flagged as unmapped
  81.         $this->addFieldMapping(NULL, 'excerpt');       
  82.     }
  83. }
  84.  
  85.  
  86. class GauntletBylinesMigration extends GauntletStoriesMigration {  
  87.   public function __construct() {
  88.     parent::__construct();
  89.     $this->dependencies = array('GauntletStories');    
  90.     $query = db_select('dbAuthors', 'l');
  91.     $query->fields('l', array(
  92.       'aid',
  93.       'sid',
  94.       'author',
  95.       'position',
  96.     ));
  97.  
  98.     $this->source = new MigrateSourceSQL($query);
  99.     $this->destination = new MigrateDestinationFieldCollection('field_bylines', array('host_entity_type' => 'node')); //changed 'hostEntityType' to 'host_entity_type'. Seems to have eliminated an error.
  100.     $this->map = new MigrateSQLMap(
  101.       $this->machineName,
  102.       array(
  103.         'aid' => array(
  104.           'type' => 'int',
  105.           'length' => 9,
  106.           'not null' => TRUE,
  107.           'alias' => 'l',
  108.         ),
  109.       ),
  110.       MigrateDestinationFieldCollection::getKeySchema()
  111.     );
  112.  
  113.     $this->addFieldMapping('host_entity_id', 'sid')->sourceMigration('GauntletStories');
  114.  
  115.     $this->addFieldMapping('field_byline_author', 'author');
  116.  
  117.     $this->addFieldMapping('field_byline_position', 'position');
  118.   }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement