migrate_materio.admin.inc 7.7 KB

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