migrate_materio.account.inc 3.0 KB

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