migrate_materio.sample.inc 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * MaterioIndustrialUserMigration
  4. *
  5. */
  6. class MaterioIndustrialSampleUserMigration extends MaterioBasicMigration {
  7. public function __construct() {
  8. parent::__construct();
  9. $this->description = t('Migrate Materio Industrials Email Sample Users');
  10. // provide better description for source fields
  11. // and add new field source not from sql
  12. $source_fields = array(
  13. 'id_industrial' => t('Industrial id from source'),
  14. 'memo' => t('memo'),
  15. );
  16. $query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
  17. $query->join(MIG_MAT_SRC_DB .'.industrial_info', 'iinf', 'iid.id_industrial = iinf.id_industrial');
  18. $query
  19. ->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
  20. ->fields('iinf', array('company', 'email_sample'))
  21. ->condition('email_sample', '', '<>')
  22. ->orderBy('iid.id_industrial', 'DESC')
  23. ->groupBy('iid.id_industrial');
  24. $this->source = new MigrateSourceSQL($query, $source_fields);
  25. $this->destination = new MigrateDestinationUser();
  26. $this->map = new MigrateSQLMap($this->machineName,
  27. array(
  28. 'id_industrial' => array(
  29. 'type' => 'int',
  30. 'unsigned' => TRUE,
  31. 'not null' => TRUE,
  32. 'description' => 'OLD Unique industrial ID',
  33. 'alias' => 'iid',
  34. )
  35. ),
  36. MigrateDestinationUser::getKeySchema()
  37. );
  38. // Make the mappings
  39. $this->addFieldMapping('name')->defaultValue('aname');
  40. $this->addFieldMapping('pass')->defaultValue(NULL);
  41. $this->addFieldMapping('mail', 'email_sample');
  42. # NOTE : maybe if we provide only init mail, we wiil be able to ask email confirmation for users
  43. $this->addFieldMapping('init', 'email_sample');
  44. $this->addFieldMapping('language')->defaultValue('');
  45. $this->addFieldMapping('theme')->defaultValue('');
  46. $this->addFieldMapping('signature')->defaultValue('');
  47. $this->addFieldMapping('signature_format')->defaultValue('filtered_html');
  48. $this->addFieldMapping('created', 'date_creation');
  49. $this->addFieldMapping('access', 'date_modif');
  50. $this->addFieldMapping('login')->defaultValue(0);
  51. $this->addFieldMapping('status')->defaultValue(0);
  52. $this->addFieldMapping('picture')->defaultValue(0);
  53. $this->addFieldMapping('timezone')->defaultValue(NULL);
  54. // $this->addFieldMapping('path')->issueGroup(t('DNM'));
  55. $this->addFieldMapping('pathauto')->defaultValue(1);
  56. $this->addFieldMapping('roles')->defaultValue(array(5));
  57. $this->addFieldMapping('is_new')->defaultValue(TRUE);
  58. $this->addFieldMapping('field_memo', 'memo');
  59. $this->addFieldMapping('field_company', 'company');
  60. }
  61. public function prepareRow($cr) {
  62. if($cr->email_sample == '')
  63. return false;
  64. $cr->company = trim($cr->company);
  65. if(count(taxonomy_get_term_by_name($cr->company.'-'.$cr->id_industrial)))
  66. $cr->company .= '-'.$cr->id_industrial;
  67. $cr->memo = "#sample";
  68. return TRUE;
  69. // return FALSE if you wish to skip a particular row
  70. }
  71. }