migrate_materio.admin.inc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. /**
  3. * MaterioIndustrialUserMigration
  4. *
  5. */
  6. class MaterioIndustrialAdminUserMigration extends MaterioBasicMigration {
  7. public function __construct() {
  8. parent::__construct();
  9. $this->description = t('Migrate Materio Industrials Admin 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_admin'))
  21. ->condition('email_admin', '', '<>')
  22. ->orderBy('iid.id_industrial', 'DESC');
  23. $query->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_admin');
  42. # NOTE : maybe if we provide only init mail, we wiil be able to ask email confirmation for users
  43. $this->addFieldMapping('init', 'email_admin');
  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_admin == "")
  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 = "#admin";
  68. return TRUE;
  69. // return FALSE if you wish to skip a particular row
  70. }
  71. }
  72. /**
  73. * MaterioIndustrialProfile2Migration
  74. */
  75. class MaterioIndustrialAdminProfile2Migration extends MaterioBasicMigration {
  76. public function __construct() {
  77. parent::__construct();
  78. global $user;
  79. $this->description = t('Migrate Materio Industrials Admin Profiles2');
  80. // provide better description for source fields
  81. // and add new field source not from sql
  82. $source_fields = array(
  83. 'id_industrial' => t('Industrial id from source'),
  84. 'admin_quality'=> t('en-fr admin quality implemented on prepare'),
  85. 'language'=> t('en-fr langauge description, used in prepare'),
  86. 'tels_admin' => '',
  87. 'ccodes_admin' => ''
  88. );
  89. $query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
  90. $query->join(MIG_MAT_SRC_DB .'.industrial_info', 'iinf', 'iid.id_industrial = iinf.id_industrial');
  91. $ilfr_select = db_select(MIG_MAT_SRC_DB .'.industrial_lang', 'ilfr_select')
  92. ->fields('ilfr_select')->condition('ilfr_select.id_locale',1)->orderBy('ilfr_select.id_industrial', 'DESC')->distinct();
  93. $query->join($ilfr_select, 'ilfr', 'iid.id_industrial = ilfr.id_industrial');
  94. $ilen_select = db_select(MIG_MAT_SRC_DB .'.industrial_lang', 'ilen_select')
  95. ->fields('ilen_select')->condition('ilen_select.id_locale',2)->orderBy('ilen_select.id_industrial', 'ASC')->distinct();
  96. $query->join($ilen_select, 'ilen', 'iid.id_industrial = ilen.id_industrial');
  97. $query
  98. ->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
  99. ->fields('iinf', array('admin', 'admin_title', 'email_admin', 'tel1_admin', 'ccode1_admin', 'tel2_admin', 'ccode2_admin'));
  100. $query->addField('ilfr', 'admin_quality', 'admin_quality_fr');
  101. $query->addField('ilen', 'admin_quality', 'admin_quality_en');
  102. $query
  103. ->condition('email_admin', '', '<>')
  104. ->groupBy('iid.id_industrial')
  105. ->orderBy('iid.id_industrial', 'DESC');
  106. $this->source = new MigrateSourceSQL($query, $source_fields);
  107. // $this->dependencies = array('MaterioIndustrialUser');
  108. $this->destination = new MigrateDestinationProfile2('contact_operationnel');
  109. $this->map = new MigrateSQLMap($this->machineName,
  110. array(
  111. 'id_industrial' => array(
  112. 'type' => 'int',
  113. 'unsigned' => TRUE,
  114. 'not null' => TRUE,
  115. 'description' => 'OLD Unique industrial ID',
  116. 'alias' => 'iid',
  117. )
  118. ),
  119. MigrateDestinationProfile2::getKeySchema()
  120. );
  121. // Connecting the profile2 to the user:
  122. $this->addFieldMapping('uid', 'id_industrial')
  123. ->sourceMigration('MaterioIndustrialAdminUser') // If your user migration class was named 'MyUserMigration', the string is 'MyUser'
  124. ->description(t('The assignment of profile2-items to the respective user'));
  125. $this->addFieldMapping('revision_uid', 'id_industrial')
  126. ->sourceMigration('MaterioIndustrialAdminUser');
  127. // Make the mappings
  128. $this->addFieldMapping('language')->defaultValue('');
  129. $this->addFieldMapping('field_private_name', 'admin');
  130. $this->addFieldMapping('field_private_name_title', 'admin_title');
  131. // see on prepareRow()
  132. $this->addFieldMapping('field_private_quality', 'admin_quality');
  133. $this->addFieldMapping('field_private_quality:language', 'language');
  134. $this->addFieldMapping(NULL, 'admin_quality_en');
  135. $this->addFieldMapping(NULL, 'admin_quality_fr');
  136. $this->addFieldMapping('field_private_email', 'email_admin'); // http://drupal.org/node/1232028
  137. $arguments = array(
  138. 'number' => array('source_field' => 'tel1_admin'),
  139. // 'extension' => array('source_field' => 'ccode1_admin'),
  140. );
  141. $this->addFieldMapping('field_private_phone', 'ccode1_admin')
  142. ->arguments($arguments);
  143. $this->addFieldMapping(NULL, 'tel1_admin');
  144. // $this->addFieldMapping(NULL, 'ccode1_admin');
  145. $this->addFieldMapping(NULL, 'tel2_admin');
  146. $this->addFieldMapping(NULL, 'ccode2_admin');
  147. $this->addFieldMapping('field_memo', 'memo');
  148. }
  149. public function prepareRow($cr) {
  150. if($cr->email_admin == "")
  151. return false;
  152. $cr->admin_quality = array($cr->admin_quality_en, $cr->admin_quality_fr);
  153. $cr->language = array('en', 'fr');
  154. $ccs = cck_phone_countrycodes();
  155. $match = 0;
  156. foreach ($ccs as $cc => $cc_values) {
  157. if('+'.preg_replace('/^\+/', '', $cr->ccode1_admin) == $cc_values['code']){
  158. $cr->ccode1_admin = $cc;
  159. $match++;
  160. }
  161. if('+'.preg_replace('/^\+/', '', $cr->ccode2_admin) == $cc_values['code']){
  162. $cr->ccode2_admin = $cc;
  163. $match++;
  164. }
  165. if($match == 2)
  166. break;
  167. }
  168. if($cr->tel2_admin != ''){
  169. $cc = cck_phone_countrycodes($cr->ccode2_admin);
  170. $cr->memo .= "\n".'tel2 admin : '. $cc['country'] . ' (' . $cc['code'] . ')' .' '. $cr->tel2_admin;
  171. }
  172. // dsm($cr, '- - - - $cr - - - -');
  173. return TRUE;
  174. // return FALSE if you wish to skip a particular row
  175. }
  176. public function prepare($node, stdClass $row) {
  177. // dsm('-- prepare --');
  178. // dsm($node, '$node');
  179. // dsm($row, '$row');
  180. // $node->field_public_email = array('und'=>array($row->email_admin));
  181. }
  182. }