migrate_materio.account.inc 2.9 KB

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