merged migrate_materio submodule
This commit is contained in:
commit
b285de8b3a
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* MaterioIndustrialUserMigration
|
||||
*
|
||||
*/
|
||||
class MaterioIndustrialAccountUserMigration extends MaterioBasicMigration {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->description = t('Migrate Materio Industrials Account Users');
|
||||
|
||||
// provide better description for source fields
|
||||
// and add new field source not from sql
|
||||
$source_fields = array(
|
||||
'id_industrial' => t('Industrial id from source'),
|
||||
'memo' => t('memo'),
|
||||
);
|
||||
|
||||
$query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
|
||||
$query->join(MIG_MAT_SRC_DB .'.industrial_account', 'ind_ac', 'iid.id_industrial = ind_ac.id_industrial');
|
||||
$query->join(MIG_MAT_SRC_DB .'.industrial_info', 'iinf', 'iid.id_industrial = iinf.id_industrial');
|
||||
$query
|
||||
->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
|
||||
->fields('ind_ac', array('login', 'password'))
|
||||
->fields('iinf', array('company', 'email_general'))
|
||||
->condition('email_general', '', '<>')
|
||||
->orderBy('iid.id_industrial', 'DESC');
|
||||
|
||||
$query->groupBy('iid.id_industrial');
|
||||
|
||||
$this->source = new MigrateSourceSQL($query, $source_fields);
|
||||
$this->destination = new MigrateDestinationUser();
|
||||
$this->map = new MigrateSQLMap($this->machineName,
|
||||
array(
|
||||
'id_industrial' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'OLD Unique industrial ID',
|
||||
'alias' => 'iid',
|
||||
)
|
||||
),
|
||||
MigrateDestinationUser::getKeySchema()
|
||||
);
|
||||
|
||||
// Make the mappings
|
||||
$this->addFieldMapping('name', 'login');
|
||||
$this->addFieldMapping('pass', 'password');//->defaultValue(NULL);
|
||||
$this->addFieldMapping('mail', 'email_general');
|
||||
# NOTE : maybe if we provide only init mail, we wiil be able to ask email confirmation for users
|
||||
$this->addFieldMapping('init', 'email_general');
|
||||
$this->addFieldMapping('language')->defaultValue('');
|
||||
$this->addFieldMapping('theme')->defaultValue('');
|
||||
$this->addFieldMapping('signature')->defaultValue('');
|
||||
$this->addFieldMapping('signature_format')->defaultValue('filtered_html');
|
||||
$this->addFieldMapping('created', 'date_creation');
|
||||
$this->addFieldMapping('access', 'date_modif');
|
||||
$this->addFieldMapping('login')->defaultValue(0);
|
||||
$this->addFieldMapping('status')->defaultValue(0);
|
||||
$this->addFieldMapping('picture')->defaultValue(0);
|
||||
$this->addFieldMapping('timezone')->defaultValue(NULL);
|
||||
// $this->addFieldMapping('path')->issueGroup(t('DNM'));
|
||||
$this->addFieldMapping('pathauto')->defaultValue(1);
|
||||
$this->addFieldMapping('roles')->defaultValue(array(5));
|
||||
$this->addFieldMapping('is_new')->defaultValue(TRUE);
|
||||
|
||||
$this->addFieldMapping('field_memo', 'memo');
|
||||
|
||||
$this->addFieldMapping('field_company', 'company');
|
||||
|
||||
}
|
||||
|
||||
public function prepareRow($cr) {
|
||||
if($cr->email_general == '')
|
||||
return false;
|
||||
|
||||
$cr->company = trim($cr->company);
|
||||
|
||||
$cr->memo = $cr->login .' | '. $cr->password;
|
||||
|
||||
return TRUE;
|
||||
// return FALSE if you wish to skip a particular row
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,422 @@
|
||||
<?php
|
||||
/**
|
||||
* MaterioIndustrialUserMigration
|
||||
*
|
||||
*/
|
||||
class MaterioAdherentUserMigration extends MaterioBasicMigration {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->description = t('Migrate Materio Members Account Users');
|
||||
|
||||
// provide better description for source fields
|
||||
// and add new field source not from sql
|
||||
$source_fields = array(
|
||||
'id_login' => t('Member id from source'),
|
||||
'memo'=>t('memo'),
|
||||
'roles'=>t('roles'),
|
||||
'user_name' => 'User name',
|
||||
);
|
||||
|
||||
$query = db_select(MIG_MAT_SRC_DB .'.login_id', 'lid');
|
||||
$query->join(MIG_MAT_SRC_DB .'.member_id', 'mid', 'mid.id_member = lid.id_member');
|
||||
// $query->join(MIG_MAT_SRC_DB .'.locale_id', 'locid', 'lid.def_locale = locid.id_locale');
|
||||
$query->join(MIG_MAT_SRC_DB .'.member_info', 'minf', 'mid.id_member = minf.id_member');
|
||||
$query
|
||||
->fields('lid', array('id_login', 'status', 'date_creation', 'date_modif', 'date_end', 'type', 'email', 'news_letter', 'def_locale'))
|
||||
->fields('mid', array('memo'))
|
||||
// ->fields('locid', array('name', 'short_name', 'suffix'))
|
||||
->fields('minf', array('activity'))
|
||||
// ->condition('email_general', '', '<>')
|
||||
->orderBy('lid.id_login', 'DESC');
|
||||
|
||||
// $query->groupBy('lid.id_member');
|
||||
|
||||
$this->source = new MigrateSourceSQL($query, $source_fields);
|
||||
$this->destination = new MigrateDestinationUser();
|
||||
$this->map = new MigrateSQLMap($this->machineName,
|
||||
array(
|
||||
'id_login' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'OLD Unique member ID',
|
||||
'alias' => 'lid',
|
||||
)
|
||||
),
|
||||
MigrateDestinationUser::getKeySchema()
|
||||
);
|
||||
|
||||
// Make the mappings
|
||||
$this->addFieldMapping('name', 'user_name');
|
||||
$this->addFieldMapping('pass')->defaultValue(NULL);
|
||||
$this->addFieldMapping('mail', 'email');
|
||||
# NOTE : maybe if we provide only init mail, we wiil be able to ask email confirmation for users
|
||||
$this->addFieldMapping('init', 'email');
|
||||
$this->addFieldMapping('language', 'def_locale');
|
||||
$this->addFieldMapping('theme')->defaultValue('');
|
||||
$this->addFieldMapping('signature')->defaultValue('');
|
||||
$this->addFieldMapping('signature_format')->defaultValue('filtered_html');
|
||||
$this->addFieldMapping('created', 'date_creation');
|
||||
$this->addFieldMapping('access')->defaultValue(0);//, 'date_modif');
|
||||
$this->addFieldMapping('login')->defaultValue(0);
|
||||
$this->addFieldMapping('status')->defaultValue(0);
|
||||
$this->addFieldMapping('picture')->defaultValue(0);
|
||||
$this->addFieldMapping('timezone')->defaultValue(NULL);
|
||||
// $this->addFieldMapping('path')->issueGroup(t('DNM'));
|
||||
$this->addFieldMapping('pathauto')->defaultValue(1);
|
||||
$this->addFieldMapping('roles', 'roles');// 7 = utilisateur, 6 = adherent, 8 = premium; ->defaultValue(array(6)); // adhérent
|
||||
$this->addFieldMapping('is_new')->defaultValue(TRUE);
|
||||
|
||||
$this->addFieldMapping('field_newsletter', 'news_letter');
|
||||
|
||||
$this->addFieldMapping('field_memo', 'memo');
|
||||
|
||||
$this->addFieldMapping(NULL, 'activity');
|
||||
|
||||
$this->addUnmigratedDestinations(array(
|
||||
'role_names', 'data', 'field_memo:language',
|
||||
'field_company', 'field_company:source_type', 'field_company:create_term', 'field_company:ignore_case',
|
||||
'path',
|
||||
));
|
||||
|
||||
$this->addUnmigratedSources(array(
|
||||
'status', 'date_end', 'type',
|
||||
));
|
||||
}
|
||||
|
||||
public function prepareRow($cr) {
|
||||
|
||||
# change roles by end date
|
||||
if($cr->date_end == ''){
|
||||
$roles[] = 7;
|
||||
}else{
|
||||
$today = time();
|
||||
$time_end = strtotime($cr->date_end);
|
||||
// dsm($time_end, 'time_end');
|
||||
|
||||
$roles = array();
|
||||
if($time_end > $today){
|
||||
$roles[] = 6;
|
||||
}else{
|
||||
$roles[] = 7;
|
||||
}
|
||||
}
|
||||
// dsm($roles, 'roles');
|
||||
$cr->roles = $roles;
|
||||
|
||||
#user name
|
||||
$cr->user_name = $this->getUserName($cr->email);
|
||||
// TODO: set role expiration
|
||||
|
||||
#duplicate email
|
||||
if($this->checkDupEmail($cr->email)){
|
||||
$memo[] = "@dup-email : ".$cr->email;
|
||||
}
|
||||
|
||||
#language
|
||||
$cr->def_locale = $cr->def_locale == 1 ? 'en' : 'fr';
|
||||
|
||||
#memo
|
||||
$memo[] = "@imported";
|
||||
|
||||
#statuts
|
||||
$memo[] = "statut : ".$cr->status;
|
||||
|
||||
#statuts
|
||||
$memo[] = "type : ".$cr->type;
|
||||
|
||||
#statuts
|
||||
$memo[] = "activity : ".$cr->activity;
|
||||
|
||||
#memo
|
||||
$cr->memo = implode("\n", $memo) ."\n\n". $cr->memo;
|
||||
|
||||
return true;
|
||||
// return FALSE if you wish to skip a particular row
|
||||
}
|
||||
|
||||
public function prepare($user, stdClass $row) {
|
||||
// dsm('-- prepare --');
|
||||
// dsm($user, '$user');
|
||||
// dsm($row, '$row');
|
||||
|
||||
// $node->field_private_email = array('und'=>array($row->email_contact));
|
||||
|
||||
}
|
||||
|
||||
public function complete($user, $row) {
|
||||
// dsm('-- complete --');
|
||||
// Do what you need to do to
|
||||
// dsm($row, '$row');
|
||||
// dsm($user, '$user');
|
||||
|
||||
if(in_array(6, $user->roles)){
|
||||
$time_end = strtotime($row->date_end);
|
||||
$min = strtotime('2013 01 30');
|
||||
if($time_end < $min)
|
||||
$time_end = $min;
|
||||
|
||||
uc_roles_grant($user, 6, $time_end, FALSE, TRUE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* helpers
|
||||
*/
|
||||
|
||||
|
||||
private function getUserName($email){
|
||||
// Default implementation of name generation.
|
||||
$new_name = preg_replace('/@.*$/', '', $email);
|
||||
// Remove unwanted characters.
|
||||
$new_name = preg_replace('/[^a-zA-Z0-9.-]/', '', $new_name);
|
||||
|
||||
// if username generated from email record already exists, append underscore and number eg:(chris_123)
|
||||
if ((bool) db_query("SELECT 1 FROM {users} WHERE LOWER(name) = LOWER(:new_name)", array(':new_name' => $new_name))->fetchField()) {
|
||||
$name_idx = db_query_range("SELECT SUBSTRING_INDEX(name,'_',-1) FROM {users} WHERE name REGEXP :search ORDER BY CAST(SUBSTRING_INDEX(name,'_',-1) AS UNSIGNED) DESC", 0, 1, array(':search' => '^' . $new_name . '_[0-9]+$'))->fetchField();
|
||||
|
||||
$new_name .= '_' . ($name_idx + 1);
|
||||
}
|
||||
|
||||
return $new_name;
|
||||
}
|
||||
|
||||
private function checkDupEmail($email){
|
||||
if ((bool) db_query("SELECT 1 FROM {users} WHERE mail = :email", array(':email' => $email))->fetchField()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MaterioIndustrialProfile2Migration
|
||||
*/
|
||||
class MaterioAdherentProfile2Migration extends MaterioBasicMigration {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
global $user;
|
||||
$this->description = t('Migrate Materio Member Profiles2');
|
||||
|
||||
// provide better description for source fields
|
||||
// and add new field source not from sql
|
||||
$source_fields = array(
|
||||
'id_login' => t('Member id from source'),
|
||||
'member_name' => t('Main member name'),
|
||||
'member_firstname' => t('Main member first name'),
|
||||
'premise'=>'',
|
||||
'sub_premise'=>'',
|
||||
);
|
||||
|
||||
|
||||
$query = db_select(MIG_MAT_SRC_DB .'.login_id', 'lid');
|
||||
$query->join(MIG_MAT_SRC_DB .'.member_id', 'mid', 'mid.id_member = lid.id_member');
|
||||
$query->join(MIG_MAT_SRC_DB .'.member_info', 'minf', 'mid.id_member = minf.id_member');
|
||||
|
||||
$query
|
||||
->fields('lid', array('id_login', 'status', 'name',))
|
||||
// ->fields('mid', array('memo', 'cgv'))
|
||||
->fields('minf', array(
|
||||
'con_title', 'con_name1', 'con_name2', 'con_quality', 'con_service', 'con_ccode1', 'con_tel1',
|
||||
'organization', 'employee', 'naf', 'siret', 'web', 'address', 'city', 'zip', 'country', )
|
||||
)
|
||||
// ->condition('status', 'A')
|
||||
->orderBy('lid.id_login', 'DESC');
|
||||
|
||||
// $query->groupBy('lid.id_member');
|
||||
|
||||
|
||||
$this->source = new MigrateSourceSQL($query, $source_fields);
|
||||
// $this->dependencies = array('MaterioIndustrialUser');
|
||||
$this->destination = new MigrateDestinationProfile2('adherent');
|
||||
|
||||
$this->map = new MigrateSQLMap($this->machineName,
|
||||
array(
|
||||
'id_login' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'OLD Unique Member ID',
|
||||
'alias' => 'lid',
|
||||
)
|
||||
),
|
||||
MigrateDestinationProfile2::getKeySchema()
|
||||
);
|
||||
|
||||
// Connecting the profile2 to the user:
|
||||
$this->addFieldMapping('uid', 'id_login')
|
||||
->sourceMigration('MaterioAdherentUser') // If your user migration class was named 'MyUserMigration', the string is 'MyUser'
|
||||
->description(t('The assignment of profile2-items to the respective Adherent user'));
|
||||
|
||||
$this->addFieldMapping('revision_uid', 'id_login')
|
||||
->sourceMigration('MaterioAdherentUser');
|
||||
|
||||
// Make the mappings
|
||||
$this->addFieldMapping('language')->defaultValue('');
|
||||
|
||||
$this->addFieldMapping('field_name', 'member_name');
|
||||
$this->addFieldMapping('field_first_name', 'member_firstname');
|
||||
$this->addFieldMapping(NULL, 'con_name1');
|
||||
$this->addFieldMapping(NULL, 'con_name2');
|
||||
$this->addFieldMapping(NULL, 'name');
|
||||
|
||||
|
||||
$this->addFieldMapping('field_private_quality', 'con_quality'); // http://drupal.org/node/1232028
|
||||
$this->addFieldMapping('field_private_name_title', 'con_title');
|
||||
|
||||
$arguments = array(
|
||||
'number' => array('source_field' => 'con_tel1'),
|
||||
);
|
||||
$this->addFieldMapping('field_private_phone', 'con_ccode1')
|
||||
->arguments($arguments);
|
||||
// field_private_phone:number
|
||||
// field_private_phone:extension
|
||||
$this->addFieldMapping(NULL, 'con_tel1');
|
||||
|
||||
$this->addFieldMapping(NULL, 'status');
|
||||
|
||||
$arguments = array(
|
||||
'thoroughfare' => array('source_field' => 'address'),
|
||||
'premise' => array('source_field' => 'premise'),
|
||||
'sub_premise' => array('source_field' => 'sub_premise'),
|
||||
'locality' => array('source_field' => 'city'),
|
||||
'postal_code' => array('source_field' => 'zip'),
|
||||
);
|
||||
$this->addFieldMapping('field_adresse', 'country')
|
||||
->arguments($arguments);
|
||||
|
||||
$this->addFieldMapping(NULL, 'address');
|
||||
$this->addFieldMapping(NULL, 'premise');
|
||||
$this->addFieldMapping(NULL, 'sub_premise');
|
||||
$this->addFieldMapping(NULL, 'city');
|
||||
$this->addFieldMapping(NULL, 'zip');
|
||||
$this->addFieldMapping(NULL, 'country');
|
||||
|
||||
$this->addFieldMapping('field_organization', 'organization');
|
||||
$this->addFieldMapping('field_service', 'con_service');
|
||||
$this->addFieldMapping('field_employee', 'employee');
|
||||
$this->addFieldMapping('field_naf', 'naf');
|
||||
$this->addFieldMapping('field_siret', 'siret');
|
||||
|
||||
|
||||
$this->addFieldMapping('field_user_website', 'web');
|
||||
|
||||
$this->addUnmigratedDestinations(array(
|
||||
'field_private_quality:language', 'field_first_name:language', 'field_name:language',
|
||||
'field_organization:language', 'field_activity:language', 'field_service:language', 'field_naf:language', 'field_siret:language',
|
||||
'field_private_phone:number', 'field_private_phone:extension',
|
||||
|
||||
));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function prepareRow($cr) {
|
||||
|
||||
if($cr->status == 'A'){
|
||||
# nom prenom
|
||||
$cr->member_name = $cr->con_name1;
|
||||
$cr->member_firstname = $cr->con_name2;
|
||||
|
||||
#telephone
|
||||
if($cr->con_ccode1 != ''){
|
||||
$ccs = cck_phone_countrycodes();
|
||||
$cc_founded = false;
|
||||
foreach ($ccs as $cc => $cc_values) {
|
||||
if('+'.preg_replace('/^\+/', '', trim($cr->con_ccode1)) == $cc_values['code']){
|
||||
$cr->con_ccode1 = $cc;
|
||||
$cc_founded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!$cc_founded){
|
||||
// dsm($cr->con_ccode1, '$cr->con_ccode1');
|
||||
$cr->con_ccode1 = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
$name = explode(' ', $cr->name);
|
||||
$cr->member_name = array_shift($name);
|
||||
$cr->member_firstname = implode(' ', $name);
|
||||
$cr->con_quality = '';
|
||||
$cr->con_title = '';
|
||||
$cr->con_ccode1 = '';
|
||||
$cr->con_tel1 = '';
|
||||
}
|
||||
|
||||
$cr->organization = trim($cr->organization);
|
||||
|
||||
|
||||
$cr->address = preg_replace('/\\n/', ', ', $cr->address);
|
||||
if(strlen($cr->address) > 255){
|
||||
$adress = $cr->address;
|
||||
$cr->address = substr($adress, 0, 250);
|
||||
$cr->premise = substr($adress, 250, 500);
|
||||
$sub = substr($adress, 500, 750);
|
||||
$cr->sub_premise = $sub ? $sub : '';
|
||||
}else{
|
||||
$cr->premise = '';
|
||||
$cr->sub_premise = '';
|
||||
}
|
||||
|
||||
$cr->city = preg_replace('/\\n/', ' ', $cr->city);
|
||||
|
||||
if($cr->country != ''){
|
||||
require_once DRUPAL_ROOT . '/includes/locale.inc';
|
||||
$countries = country_get_list();
|
||||
|
||||
$c_founded = false;
|
||||
foreach ($countries as $cc => $c) {
|
||||
if(stristr($cr->country, $c)){
|
||||
$cr->country = $cc;
|
||||
$c_founded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$c_founded){
|
||||
$nonISO_cc = array(
|
||||
'liban' => 'LB',
|
||||
'uk' => 'GB',
|
||||
'usa' => 'US',
|
||||
'korea, south' => 'KR',
|
||||
'brésil' => 'BR',
|
||||
);
|
||||
foreach ($nonISO_cc as $n => $cc) {
|
||||
if(stristr($cr->country, $n)){
|
||||
$cr->country = $cc;
|
||||
$c_founded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$c_founded){
|
||||
// dsm($cr->country, '$cr->country');
|
||||
$cr->country = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return TRUE;
|
||||
// return FALSE if you wish to skip a particular row
|
||||
}
|
||||
|
||||
|
||||
|
||||
// public function prepare($node, stdClass $row) {
|
||||
// // dsm('-- prepare --');
|
||||
// // dsm($node, '$node');
|
||||
// // dsm($row, '$row');
|
||||
//
|
||||
// // $node->field_private_email = array('und'=>array($row->email_contact));
|
||||
//
|
||||
// }
|
||||
}
|
237
sites/all/modules/gui/migrate_materio/migrate_materio.admin.inc
Normal file
237
sites/all/modules/gui/migrate_materio/migrate_materio.admin.inc
Normal file
@ -0,0 +1,237 @@
|
||||
<?php
|
||||
/**
|
||||
* MaterioIndustrialUserMigration
|
||||
*
|
||||
*/
|
||||
class MaterioIndustrialAdminUserMigration extends MaterioBasicMigration {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->description = t('Migrate Materio Industrials Admin Users');
|
||||
|
||||
// provide better description for source fields
|
||||
// and add new field source not from sql
|
||||
$source_fields = array(
|
||||
'id_industrial' => t('Industrial id from source'),
|
||||
'memo' => t('memo'),
|
||||
);
|
||||
|
||||
$query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
|
||||
$query->join(MIG_MAT_SRC_DB .'.industrial_info', 'iinf', 'iid.id_industrial = iinf.id_industrial');
|
||||
|
||||
$query
|
||||
->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
|
||||
->fields('iinf', array('company', 'email_admin'))
|
||||
->condition('email_admin', '', '<>')
|
||||
->orderBy('iid.id_industrial', 'DESC');
|
||||
|
||||
$query->groupBy('iid.id_industrial');
|
||||
|
||||
$this->source = new MigrateSourceSQL($query, $source_fields);
|
||||
$this->destination = new MigrateDestinationUser();
|
||||
|
||||
$this->map = new MigrateSQLMap($this->machineName,
|
||||
array(
|
||||
'id_industrial' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'OLD Unique industrial ID',
|
||||
'alias' => 'iid',
|
||||
)
|
||||
),
|
||||
MigrateDestinationUser::getKeySchema()
|
||||
);
|
||||
|
||||
// Make the mappings
|
||||
$this->addFieldMapping('name')->defaultValue('aname');
|
||||
$this->addFieldMapping('pass')->defaultValue(NULL);
|
||||
$this->addFieldMapping('mail', 'email_admin');
|
||||
# NOTE : maybe if we provide only init mail, we wiil be able to ask email confirmation for users
|
||||
$this->addFieldMapping('init', 'email_admin');
|
||||
$this->addFieldMapping('language')->defaultValue('');
|
||||
$this->addFieldMapping('theme')->defaultValue('');
|
||||
$this->addFieldMapping('signature')->defaultValue('');
|
||||
$this->addFieldMapping('signature_format')->defaultValue('filtered_html');
|
||||
$this->addFieldMapping('created', 'date_creation');
|
||||
$this->addFieldMapping('access', 'date_modif');
|
||||
$this->addFieldMapping('login')->defaultValue(0);
|
||||
$this->addFieldMapping('status')->defaultValue(0);
|
||||
$this->addFieldMapping('picture')->defaultValue(0);
|
||||
$this->addFieldMapping('timezone')->defaultValue(NULL);
|
||||
// $this->addFieldMapping('path')->issueGroup(t('DNM'));
|
||||
$this->addFieldMapping('pathauto')->defaultValue(1);
|
||||
$this->addFieldMapping('roles')->defaultValue(array(5));
|
||||
$this->addFieldMapping('is_new')->defaultValue(TRUE);
|
||||
|
||||
$this->addFieldMapping('field_memo', 'memo');
|
||||
|
||||
$this->addFieldMapping('field_company', 'company');
|
||||
|
||||
}
|
||||
|
||||
public function prepareRow($cr) {
|
||||
|
||||
if($cr->email_admin == "")
|
||||
return false;
|
||||
|
||||
$cr->company = trim($cr->company);
|
||||
if(count(taxonomy_get_term_by_name($cr->company.'-'.$cr->id_industrial)))
|
||||
$cr->company .= '-'.$cr->id_industrial;
|
||||
|
||||
$cr->memo = "#admin";
|
||||
|
||||
return TRUE;
|
||||
// return FALSE if you wish to skip a particular row
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* MaterioIndustrialProfile2Migration
|
||||
*/
|
||||
class MaterioIndustrialAdminProfile2Migration extends MaterioBasicMigration {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
global $user;
|
||||
$this->description = t('Migrate Materio Industrials Admin Profiles2');
|
||||
|
||||
// provide better description for source fields
|
||||
// and add new field source not from sql
|
||||
$source_fields = array(
|
||||
'id_industrial' => t('Industrial id from source'),
|
||||
'admin_quality'=> t('en-fr admin quality implemented on prepare'),
|
||||
'language'=> t('en-fr langauge description, used in prepare'),
|
||||
'tels_admin' => '',
|
||||
'ccodes_admin' => ''
|
||||
);
|
||||
|
||||
$query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
|
||||
$query->join(MIG_MAT_SRC_DB .'.industrial_info', 'iinf', 'iid.id_industrial = iinf.id_industrial');
|
||||
|
||||
$ilfr_select = db_select(MIG_MAT_SRC_DB .'.industrial_lang', 'ilfr_select')
|
||||
->fields('ilfr_select')->condition('ilfr_select.id_locale',1)->orderBy('ilfr_select.id_industrial', 'DESC')->distinct();
|
||||
$query->join($ilfr_select, 'ilfr', 'iid.id_industrial = ilfr.id_industrial');
|
||||
|
||||
|
||||
$ilen_select = db_select(MIG_MAT_SRC_DB .'.industrial_lang', 'ilen_select')
|
||||
->fields('ilen_select')->condition('ilen_select.id_locale',2)->orderBy('ilen_select.id_industrial', 'ASC')->distinct();
|
||||
$query->join($ilen_select, 'ilen', 'iid.id_industrial = ilen.id_industrial');
|
||||
|
||||
$query
|
||||
->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
|
||||
->fields('iinf', array('admin', 'admin_title', 'email_admin', 'tel1_admin', 'ccode1_admin', 'tel2_admin', 'ccode2_admin'));
|
||||
|
||||
$query->addField('ilfr', 'admin_quality', 'admin_quality_fr');
|
||||
$query->addField('ilen', 'admin_quality', 'admin_quality_en');
|
||||
|
||||
$query
|
||||
->condition('email_admin', '', '<>')
|
||||
->groupBy('iid.id_industrial')
|
||||
->orderBy('iid.id_industrial', 'DESC');
|
||||
|
||||
|
||||
$this->source = new MigrateSourceSQL($query, $source_fields);
|
||||
// $this->dependencies = array('MaterioIndustrialUser');
|
||||
$this->destination = new MigrateDestinationProfile2('contact_operationnel');
|
||||
|
||||
$this->map = new MigrateSQLMap($this->machineName,
|
||||
array(
|
||||
'id_industrial' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'OLD Unique industrial ID',
|
||||
'alias' => 'iid',
|
||||
)
|
||||
),
|
||||
MigrateDestinationProfile2::getKeySchema()
|
||||
);
|
||||
|
||||
// Connecting the profile2 to the user:
|
||||
$this->addFieldMapping('uid', 'id_industrial')
|
||||
->sourceMigration('MaterioIndustrialAdminUser') // If your user migration class was named 'MyUserMigration', the string is 'MyUser'
|
||||
->description(t('The assignment of profile2-items to the respective user'));
|
||||
|
||||
$this->addFieldMapping('revision_uid', 'id_industrial')
|
||||
->sourceMigration('MaterioIndustrialAdminUser');
|
||||
|
||||
// Make the mappings
|
||||
$this->addFieldMapping('language')->defaultValue('');
|
||||
|
||||
$this->addFieldMapping('field_private_name', 'admin');
|
||||
$this->addFieldMapping('field_private_name_title', 'admin_title');
|
||||
|
||||
// see on prepareRow()
|
||||
$this->addFieldMapping('field_private_quality', 'admin_quality');
|
||||
$this->addFieldMapping('field_private_quality:language', 'language');
|
||||
$this->addFieldMapping(NULL, 'admin_quality_en');
|
||||
$this->addFieldMapping(NULL, 'admin_quality_fr');
|
||||
|
||||
|
||||
$this->addFieldMapping('field_private_email', 'email_admin'); // http://drupal.org/node/1232028
|
||||
|
||||
$arguments = array(
|
||||
'number' => array('source_field' => 'tel1_admin'),
|
||||
// 'extension' => array('source_field' => 'ccode1_admin'),
|
||||
);
|
||||
$this->addFieldMapping('field_private_phone', 'ccode1_admin')
|
||||
->arguments($arguments);
|
||||
|
||||
$this->addFieldMapping(NULL, 'tel1_admin');
|
||||
// $this->addFieldMapping(NULL, 'ccode1_admin');
|
||||
$this->addFieldMapping(NULL, 'tel2_admin');
|
||||
$this->addFieldMapping(NULL, 'ccode2_admin');
|
||||
|
||||
$this->addFieldMapping('field_memo', 'memo');
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function prepareRow($cr) {
|
||||
if($cr->email_admin == "")
|
||||
return false;
|
||||
|
||||
$cr->admin_quality = array($cr->admin_quality_en, $cr->admin_quality_fr);
|
||||
$cr->language = array('en', 'fr');
|
||||
|
||||
$ccs = cck_phone_countrycodes();
|
||||
$match = 0;
|
||||
foreach ($ccs as $cc => $cc_values) {
|
||||
if('+'.preg_replace('/^\+/', '', $cr->ccode1_admin) == $cc_values['code']){
|
||||
$cr->ccode1_admin = $cc;
|
||||
$match++;
|
||||
}
|
||||
if('+'.preg_replace('/^\+/', '', $cr->ccode2_admin) == $cc_values['code']){
|
||||
$cr->ccode2_admin = $cc;
|
||||
$match++;
|
||||
}
|
||||
if($match == 2)
|
||||
break;
|
||||
}
|
||||
|
||||
if($cr->tel2_admin != ''){
|
||||
$cc = cck_phone_countrycodes($cr->ccode2_admin);
|
||||
$cr->memo .= "\n".'tel2 admin : '. $cc['country'] . ' (' . $cc['code'] . ')' .' '. $cr->tel2_admin;
|
||||
}
|
||||
|
||||
// dsm($cr, '- - - - $cr - - - -');
|
||||
|
||||
return TRUE;
|
||||
// return FALSE if you wish to skip a particular row
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function prepare($node, stdClass $row) {
|
||||
// dsm('-- prepare --');
|
||||
// dsm($node, '$node');
|
||||
// dsm($row, '$row');
|
||||
|
||||
// $node->field_public_email = array('und'=>array($row->email_admin));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* MaterioBasicMigration
|
||||
*
|
||||
*/
|
||||
abstract class MaterioBasicMigration extends Migration {
|
||||
public function __construct(){
|
||||
$this->description = t('Migrate Materio Basic Class');
|
||||
parent::__construct(MigrateGroup::getInstance('MaterioMigrate'));
|
||||
}
|
||||
}
|
229
sites/all/modules/gui/migrate_materio/migrate_materio.breves.inc
Normal file
229
sites/all/modules/gui/migrate_materio/migrate_materio.breves.inc
Normal file
@ -0,0 +1,229 @@
|
||||
<?php
|
||||
/**
|
||||
* MaterioMateriauNodeMigration
|
||||
*
|
||||
*/
|
||||
class MaterioBrevesNodeMigration extends MaterioBasicMigration {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->description = t('Migrate Materio Materiau nodes');
|
||||
|
||||
// provide better description for source fields
|
||||
// and add new field source not from sql
|
||||
$source_fields = array(
|
||||
'titlefield'=>t('title field'),
|
||||
'languages'=> t('languages'),
|
||||
'memo' => t('memo'),
|
||||
'images'=>t('images'),
|
||||
'images_titles'=>t('images titles'),
|
||||
'images_alts'=>t('images alts'),
|
||||
// 'source'=>t("source"),
|
||||
// 'materiau'=>t('materiau ref'),
|
||||
'video'=>t('video'),
|
||||
);
|
||||
|
||||
$query = db_select(MIG_MAT_SRC_DB_D6 .'.fr_i18n_node', 'i');
|
||||
|
||||
$query->join(MIG_MAT_SRC_DB_D6 .'.fr_node', 'n', 'n.nid = i.nid');
|
||||
$query->join(MIG_MAT_SRC_DB_D6 .'.fr_node_revisions', 'nr', 'nr.nid = n.nid');
|
||||
// $query->join(MIG_MAT_SRC_DB_D6 .'.fr_content_field_imago', 'im', 'im.nid = n.nid');
|
||||
|
||||
$query
|
||||
->condition('i.status', "0", "=")
|
||||
->condition('n.type',"actu")
|
||||
->fields('i', array('trid'))
|
||||
->fields('n', array('nid', 'status', 'promote', 'sticky', 'created', 'changed', 'language', 'tnid'))
|
||||
->fields('nr', array('title', 'body', 'teaser', 'format'));
|
||||
// ->fields('im', array('title', 'body', 'teaser', 'format'));
|
||||
|
||||
// print "\n\n- - - - - - \n\n";
|
||||
// print_r($query->__toString());
|
||||
// print "\n\n- - - - - - \n\n";
|
||||
|
||||
|
||||
$this->source = new MigrateSourceSQL($query, $source_fields);
|
||||
$this->destination = new MigrateDestinationNode('breve');
|
||||
|
||||
$this->map = new MigrateSQLMap($this->machineName,
|
||||
array(
|
||||
'nid' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'OLD Unique Materiau NID',
|
||||
'alias' => 'i',
|
||||
)
|
||||
),
|
||||
MigrateDestinationNode::getKeySchema()
|
||||
);
|
||||
|
||||
$this->addFieldMapping('is_new')->defaultValue(TRUE);
|
||||
|
||||
$this->addSimpleMappings(array('created', 'changed', 'status', 'promote', 'sticky', 'language', 'title'));
|
||||
|
||||
$this->addFieldMapping('field_memo', 'memo');
|
||||
|
||||
$this->addFieldMapping('title_field', 'titlefield');
|
||||
$this->addFieldMapping('title_field:language', 'languages');
|
||||
|
||||
$this->addFieldMapping('body', 'body');
|
||||
$this->addFieldMapping('body:language', 'languages');
|
||||
$this->addFieldMapping('body:format')->defaultValue('filtred_html');
|
||||
|
||||
|
||||
$this->addFieldMapping('field_visuel', 'images');
|
||||
$this->addFieldMapping('field_visuel:source_dir')->defaultValue('public://SRC_imago');
|
||||
$this->addFieldMapping('field_visuel:title', 'images_titles');
|
||||
$this->addFieldMapping('field_visuel:alt', 'images_alts');
|
||||
|
||||
$this->addFieldMapping('field_video_filter', 'video');
|
||||
|
||||
// $this->addFieldMapping('field_tags_libres', 'tags');
|
||||
// $this->addFieldMapping('field_tags_libres:create_term')->defaultValue(TRUE);
|
||||
|
||||
$this->addUnmigratedDestinations(array('revision', 'revision_uid', 'log', 'tnid', 'comment', 'uid', 'path', 'pathauto',
|
||||
'title_field:format',
|
||||
'body:summary',
|
||||
'field_source',
|
||||
// 'field_video_filter',
|
||||
'field_materiau_ref',
|
||||
'field_memo:format', 'field_memo:language',
|
||||
'field_onthologie', 'field_onthologie:source_type', 'field_onthologie:create_term',
|
||||
'field_visuel:file_class','field_visuel:language','field_visuel:destination_dir','field_visuel:destination_file','field_visuel:file_replace','field_visuel:preserve_files',
|
||||
'field_tags_libres', 'field_tags_libres:source_type', 'field_tags_libres:create_term',
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
public function prepareRow($cr){
|
||||
// dsm($cr);
|
||||
// print "\n- - - - - - - - \n";
|
||||
// print $cr->nid . "\n";
|
||||
// print $cr->title . "\n";
|
||||
|
||||
$body = $cr->body;
|
||||
|
||||
$cr->memo = '';
|
||||
|
||||
if($cr->trid){
|
||||
$query = db_select(MIG_MAT_SRC_DB_D6 .'.fr_i18n_node', 'i');
|
||||
|
||||
$query->join(MIG_MAT_SRC_DB_D6 .'.fr_node', 'n', 'n.nid = i.nid');
|
||||
$query->join(MIG_MAT_SRC_DB_D6 .'.fr_node_revisions', 'nr', 'nr.nid = n.nid');
|
||||
|
||||
$query
|
||||
->condition('i.status', "0", "<>")
|
||||
->condition('i.trid', $cr->trid, "=")
|
||||
->fields('i', array('trid'))
|
||||
->fields('n', array('nid', 'status', 'promote', 'sticky', 'created', 'changed', 'language', 'tnid'))
|
||||
->fields('nr', array('title', 'body', 'teaser', 'format'));
|
||||
|
||||
$result = $query->execute();
|
||||
|
||||
foreach ($result as $record) {
|
||||
$tr = $record;
|
||||
}
|
||||
|
||||
// print $cr->title . "\n";
|
||||
// print $tr->title . "\n";
|
||||
|
||||
$cr->titlefield = array($cr->title, $tr->title);
|
||||
|
||||
$cr->body = array($cr->body, $tr->body);
|
||||
// $cr->teaser = array($cr->teaser, $cr->tnr_teaser);
|
||||
|
||||
$cr->languages = array($cr->language, $tr->language);
|
||||
}else{
|
||||
$cr->languages = $cr->language;
|
||||
$cr->titlefield = $cr->title;
|
||||
// $cr->teaser = htmlspecialchars_decode($cr->teaser);
|
||||
}
|
||||
|
||||
/* IMAGES */
|
||||
$query = db_select(MIG_MAT_SRC_DB_D6.'.fr_content_field_imago', 'im');
|
||||
$query->join(MIG_MAT_SRC_DB_D6.'.fr_files', 'f', 'f.fid = im.field_imago_fid');
|
||||
$query
|
||||
->condition('im.nid', $cr->nid, "=")
|
||||
// ->condition('f.fid', $cr->nid, "=")
|
||||
->fields('im', array('field_imago_list', 'field_imago_data'))
|
||||
->fields('f', array('filename'));
|
||||
|
||||
$images = $query->execute();
|
||||
$cr->images = array();
|
||||
$cr->images_titles = array();
|
||||
$cr->images_alts = array();
|
||||
|
||||
foreach ($images as $image) {
|
||||
// print_r($image);
|
||||
$cr->images[] = $image->filename;
|
||||
$data = unserialize($image->field_imago_data);
|
||||
$cr->images_alts[] = $data['alt'];
|
||||
$cr->images_titles[] = $data['title'];
|
||||
}
|
||||
|
||||
|
||||
/* source */
|
||||
//Source : <a href="http://ucsdnews.ucsd.edu/pressreleases/researchers_create_living_neon_signs_composed_of_millions_of_glowing_bacter/" target="_blank">UCSanDiego</a>
|
||||
// preg_match('/Source\s:\s<a\shref="([^"]*)"[^>]*>([^<]*)<\/a>/', $body, $matches);
|
||||
// if(count($matches)){
|
||||
// print_r($matches);
|
||||
// $cr->source = str_replace('http://', '', $matches[1]);
|
||||
// }
|
||||
|
||||
/* materio */
|
||||
// (matériO P0059)
|
||||
preg_match('/\(matériO\s([^\)]*)\)/', $body, $matches);
|
||||
if(count($matches)){
|
||||
// print_r($matches);
|
||||
$cr->memo .= "ref materio : ".$matches[1]."\n";
|
||||
}
|
||||
|
||||
/* video */
|
||||
//[video:http://www.youtube.com/watch?v=3Fzu2Av6BmE align:center autoplay:1]
|
||||
preg_match('/\[video:([^\s]*)[^\]]*]/', $body, $matches);
|
||||
if(count($matches)){
|
||||
// print_r($matches);
|
||||
$cr->video = $matches[1];
|
||||
}
|
||||
|
||||
|
||||
$query = db_select(MIG_MAT_SRC_DB_D6 .'.fr_term_node', 'tn');
|
||||
$query->join(MIG_MAT_SRC_DB_D6 .'.fr_term_data', 'td', 'td.tid = tn.tid');
|
||||
|
||||
$query
|
||||
->condition('tn.nid', $cr->nid, "=")
|
||||
->fields('td', array('name'));
|
||||
|
||||
$result = $query->execute();
|
||||
$terms = array();
|
||||
foreach ($result as $record) {
|
||||
$terms[] = $record->name;
|
||||
}
|
||||
$cr->memo .= 'terms : '.implode(', ', $terms)."\n";
|
||||
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
public function prepare($node, stdClass $row) {
|
||||
// dsm('-- prepare --');
|
||||
// dsm($node, '$node');
|
||||
// dsm($row, '$row');
|
||||
|
||||
$node->workflow = 4;
|
||||
|
||||
}
|
||||
|
||||
// public function complete($node, $row) {
|
||||
// // dsm('-- complete --');
|
||||
// // // Do what you need to do to
|
||||
// // dsm($row, '$row');
|
||||
// // dsm($node, '$node');
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,233 @@
|
||||
<?php
|
||||
/**
|
||||
* MaterioIndustrialUserMigration
|
||||
*
|
||||
*/
|
||||
class MaterioCompanyMigration extends MaterioBasicMigration {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->description = t('Migrate Materio Company Node');
|
||||
|
||||
// provide better description for source fields
|
||||
// and add new field source not from sql
|
||||
$source_fields = array(
|
||||
'id_industrial' => t('Industrial id from source'),
|
||||
'department'=> t('en-fr department implemented on prepare'),
|
||||
'language'=> t('en-fr langauge description, used in prepare'),
|
||||
'premise'=>'',
|
||||
'sub_premise'=>'',
|
||||
);
|
||||
|
||||
$query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
|
||||
$query->join(MIG_MAT_SRC_DB .'.industrial_info', 'iinf', 'iid.id_industrial = iinf.id_industrial');
|
||||
|
||||
$ilfr_select = db_select(MIG_MAT_SRC_DB .'.industrial_lang', 'ilfr_select')
|
||||
->fields('ilfr_select')->condition('ilfr_select.id_locale',1)->orderBy('ilfr_select.id_industrial', 'DESC')->distinct();
|
||||
$query->join($ilfr_select, 'ilfr', 'iid.id_industrial = ilfr.id_industrial');
|
||||
|
||||
$ilen_select = db_select(MIG_MAT_SRC_DB .'.industrial_lang', 'ilen_select')
|
||||
->fields('ilen_select')->condition('ilen_select.id_locale',2)->orderBy('ilen_select.id_industrial', 'ASC')->distinct();
|
||||
$query->join($ilen_select, 'ilen', 'iid.id_industrial = ilen.id_industrial');
|
||||
|
||||
$query
|
||||
->fields('iid', array('id_industrial', 'date_creation', 'date_modif', 'memo'))
|
||||
->fields('iinf', array('company', 'address', 'city', 'zip', 'web', 'ccode1', 'tel1', 'ccode2', 'tel2', 'ccode3', 'tel3'))
|
||||
->orderBy('id_industrial', 'DESC');
|
||||
|
||||
$query->addField('ilfr', 'department', 'department_fr');
|
||||
$query->addField('ilfr', 'country', 'country_fr');
|
||||
|
||||
$query->addField('ilen', 'department', 'department_en');
|
||||
$query->addField('ilen', 'country', 'country_en');
|
||||
|
||||
$query->groupBy('id_industrial')
|
||||
->orderBy('id_industrial', 'DESC');
|
||||
|
||||
|
||||
$this->source = new MigrateSourceSQL($query, $source_fields);
|
||||
$this->destination = new MigrateDestinationNode('company');
|
||||
|
||||
$this->map = new MigrateSQLMap($this->machineName,
|
||||
array(
|
||||
'id_industrial' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'OLD Unique industrial ID',
|
||||
'alias' => 'iid',
|
||||
)
|
||||
),
|
||||
MigrateDestinationNode::getKeySchema()
|
||||
);
|
||||
|
||||
// Make the mappings
|
||||
$this->addFieldMapping('language')->defaultValue('en');
|
||||
$this->addFieldMapping('is_new')->defaultValue(TRUE);
|
||||
$this->addFieldMapping('created', 'date_creation');
|
||||
$this->addFieldMapping('changed', 'date_modif');
|
||||
$this->addFieldMapping('status')->defaultValue(1);
|
||||
$this->addFieldMapping('promote')->defaultValue(0);
|
||||
$this->addFieldMapping('sticky')->defaultValue(0);
|
||||
|
||||
$this->addFieldMapping('field_tode_company', 'company')
|
||||
->arguments(array('create_term' => TRUE));
|
||||
|
||||
// see on prepareRow()
|
||||
$this->addFieldMapping('field_department', 'department');
|
||||
$this->addFieldMapping('field_department:language', 'language');
|
||||
$this->addFieldMapping(NULL, 'department_en');
|
||||
$this->addFieldMapping(NULL, 'department_fr');
|
||||
|
||||
$arguments = array(
|
||||
'thoroughfare' => array('source_field' => 'address'),
|
||||
'premise' => array('source_field' => 'premise'),
|
||||
'sub_premise' => array('source_field' => 'sub_premise'),
|
||||
'locality' => array('source_field' => 'city'),
|
||||
'postal_code' => array('source_field' => 'zip'),
|
||||
);
|
||||
$this->addFieldMapping('field_public_address', 'country_en')
|
||||
->arguments($arguments);
|
||||
|
||||
$this->addFieldMapping(NULL, 'address');
|
||||
$this->addFieldMapping(NULL, 'premise');
|
||||
$this->addFieldMapping(NULL, 'sub_premise');
|
||||
$this->addFieldMapping(NULL, 'city');
|
||||
$this->addFieldMapping(NULL, 'zip');
|
||||
$this->addFieldMapping(NULL, 'country_fr');
|
||||
|
||||
// $arguments = MigrateLinkFieldHandler::arguments(array('source_field' => 'web_title'));
|
||||
$this->addFieldMapping('field_website', 'web');
|
||||
// ->arguments($arguments);
|
||||
|
||||
$this->addFieldMapping('body')->defaultValue('');
|
||||
$this->addFieldMapping('field_infos_from_company')->defaultValue('');
|
||||
|
||||
|
||||
$arguments = array(
|
||||
'number' => array('source_field' => 'tel1'),
|
||||
);
|
||||
$this->addFieldMapping('field_public_phone', 'ccode1')
|
||||
->arguments($arguments);
|
||||
|
||||
$this->addFieldMapping(NULL, 'tel1');
|
||||
$this->addFieldMapping(NULL, 'tel2');
|
||||
$this->addFieldMapping(NULL, 'ccode2');
|
||||
$this->addFieldMapping(NULL, 'tel3');
|
||||
$this->addFieldMapping(NULL, 'ccode3');
|
||||
/*
|
||||
TODO
|
||||
multiple field phone number ?? tel2 ccode2 tel3 ccode3
|
||||
for now added to memo
|
||||
*/
|
||||
|
||||
|
||||
$this->addFieldMapping('field_note')->defaultValue(2);
|
||||
$this->addFieldMapping('field_memo', 'memo');
|
||||
|
||||
$this->addFieldMapping('pathauto')->defaultValue(1);
|
||||
$this->addFieldMapping('comment')->defaultValue(0);
|
||||
$this->addFieldMapping('revision')->defaultValue(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function prepareRow($cr) {
|
||||
$cr->address = preg_replace('/\\n/', ', ', $cr->address);
|
||||
if(strlen($cr->address) > 255){
|
||||
$adress = $cr->address;
|
||||
$cr->address = substr($adress, 0, 250);
|
||||
$cr->premise = substr($adress, 250, 500);
|
||||
$sub = substr($adress, 500, 750);
|
||||
$cr->sub_premise = $sub ? $sub : '';
|
||||
}else{
|
||||
$cr->premise = '';
|
||||
$cr->sub_premise = '';
|
||||
}
|
||||
|
||||
$cr->city = preg_replace('/\\n/', ' ', $cr->city);
|
||||
|
||||
$cr->department = array($cr->department_en, $cr->department_fr);
|
||||
$cr->language = array('en', 'fr');
|
||||
|
||||
$cr->web = str_replace('http://', '', $cr->web);
|
||||
|
||||
/*
|
||||
TODO multiple company with same name
|
||||
how to force new term creation ?
|
||||
then how to recognize the right comp. with materieaux ?
|
||||
*/
|
||||
$cr->company = trim($cr->company);
|
||||
$same_comp = taxonomy_get_term_by_name($cr->company);
|
||||
if(count($same_comp)){
|
||||
$cr->company .= '-'.$cr->id_industrial;
|
||||
$cr->memo .= "\n".'#multiple-term';
|
||||
}
|
||||
|
||||
|
||||
$ccs = cck_phone_countrycodes();
|
||||
$match = 0;
|
||||
$ccode1 = '';
|
||||
foreach ($ccs as $cc => $cc_values) {
|
||||
if('+'.$cr->ccode1 == $cc_values['code']){
|
||||
$cr->ccode1 = $cc;
|
||||
$ccode1 = $ccs[$cc];
|
||||
$match++;
|
||||
}
|
||||
if('+'.$cr->ccode2 == $cc_values['code']){
|
||||
$cr->ccode2 = $ccs[$cc];
|
||||
$match++;
|
||||
}
|
||||
if('+'.$cr->ccode3 == $cc_values['code']){
|
||||
$cr->ccode3 = $ccs[$cc];
|
||||
$match++;
|
||||
}
|
||||
|
||||
if($match == 3)
|
||||
break;
|
||||
}
|
||||
|
||||
$cr->ccode1 = strlen($cr->ccode1) == 2 ? $cr->ccode1 : false;
|
||||
|
||||
if(($cr->tel1 != '' && !$cr->ccode1) || strlen($cr->tel1) > 15){
|
||||
$cr->tel1 = '';
|
||||
|
||||
$cc = is_array($ccode1) ? $ccode1['country'] . ' (' . $ccode1['code'] . ')' : '';
|
||||
$cr->memo .= "\n".'tel1 : '. $cc .' '. $cr->tel1;
|
||||
}
|
||||
|
||||
// do this because i don't know how to insert multiple phone fields
|
||||
if($cr->tel2 != ''){
|
||||
$cc = is_array($cr->ccode2) ? $cr->ccode2['country'] . ' (' . $cr->ccode2['code'] . ')' : '';
|
||||
$cr->memo .= "\n".'tel2 : '. $cc .' '. $cr->tel2;
|
||||
}
|
||||
if($cr->tel3 != ''){
|
||||
$cc = is_array($cr->ccode3) ? $cr->ccode3['country'] . ' (' . $cr->ccode3['code'] . ')' : '';
|
||||
$cr->memo .= "\n".'tel3 : '. $cc .' '. $cr->tel3;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// dsm($cr, '- - - - $cr - - - -');
|
||||
|
||||
return TRUE;
|
||||
// return FALSE if you wish to skip a particular row
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function prepare($node, stdClass $row) {
|
||||
// dsm('-- prepare --');
|
||||
// dsm($node, '$node');
|
||||
// dsm($row, '$row');
|
||||
|
||||
|
||||
|
||||
$node->workflow = 4;
|
||||
|
||||
// $node->field_public_email = array('und'=>array($row->email_contact));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,255 @@
|
||||
<?php
|
||||
/**
|
||||
* MaterioIndustrialUserMigration
|
||||
*
|
||||
*/
|
||||
class MaterioIndustrialContactUserMigration extends MaterioBasicMigration {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->description = t('Migrate Materio Industrials Contact Users');
|
||||
|
||||
// provide better description for source fields
|
||||
// and add new field source not from sql
|
||||
$source_fields = array(
|
||||
'id_industrial' => t('Industrial id from source'),
|
||||
'memo'=>t('memo'),
|
||||
);
|
||||
|
||||
$query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
|
||||
$query->join(MIG_MAT_SRC_DB .'.industrial_info', 'iinf', 'iid.id_industrial = iinf.id_industrial');
|
||||
|
||||
$query
|
||||
->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
|
||||
->fields('iinf', array('company', 'email_contact'))
|
||||
->condition('email_contact', '', '<>')
|
||||
->orderBy('iid.id_industrial', 'DESC');
|
||||
|
||||
$query->groupBy('iid.id_industrial');
|
||||
|
||||
$this->source = new MigrateSourceSQL($query, $source_fields);
|
||||
$this->destination = new MigrateDestinationUser();
|
||||
|
||||
$this->map = new MigrateSQLMap($this->machineName,
|
||||
array(
|
||||
'id_industrial' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'OLD Unique industrial ID',
|
||||
'alias' => 'iid',
|
||||
)
|
||||
),
|
||||
MigrateDestinationUser::getKeySchema()
|
||||
);
|
||||
|
||||
// Make the mappings
|
||||
$this->addFieldMapping('name')->defaultValue('aname');
|
||||
$this->addFieldMapping('pass')->defaultValue(NULL);
|
||||
$this->addFieldMapping('mail', 'email_contact');
|
||||
# NOTE : maybe if we provide only init mail, we wiil be able to ask email confirmation for users
|
||||
$this->addFieldMapping('init', 'email_contact');
|
||||
$this->addFieldMapping('language')->defaultValue('');
|
||||
$this->addFieldMapping('theme')->defaultValue('');
|
||||
$this->addFieldMapping('signature')->defaultValue('');
|
||||
$this->addFieldMapping('signature_format')->defaultValue('filtered_html');
|
||||
$this->addFieldMapping('created', 'date_creation');
|
||||
$this->addFieldMapping('access', 'date_modif');
|
||||
$this->addFieldMapping('login')->defaultValue(0);
|
||||
$this->addFieldMapping('status')->defaultValue(0);
|
||||
$this->addFieldMapping('picture')->defaultValue(0);
|
||||
$this->addFieldMapping('timezone')->defaultValue(NULL);
|
||||
// $this->addFieldMapping('path')->issueGroup(t('DNM'));
|
||||
$this->addFieldMapping('pathauto')->defaultValue(1);
|
||||
$this->addFieldMapping('roles')->defaultValue(array(5));
|
||||
$this->addFieldMapping('is_new')->defaultValue(TRUE);
|
||||
|
||||
$this->addFieldMapping('field_memo', 'memo');
|
||||
|
||||
$this->addFieldMapping('field_company', 'company');
|
||||
|
||||
}
|
||||
|
||||
public function prepareRow($cr) {
|
||||
|
||||
if($cr->email_contact == "")
|
||||
return false;
|
||||
|
||||
$cr->company = trim($cr->company);
|
||||
if(count(taxonomy_get_term_by_name($cr->company.'-'.$cr->id_industrial)))
|
||||
$cr->company .= '-'.$cr->id_industrial;
|
||||
|
||||
$cr->memo = "#contact";
|
||||
|
||||
return TRUE;
|
||||
// return FALSE if you wish to skip a particular row
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* MaterioIndustrialProfile2Migration
|
||||
*/
|
||||
class MaterioIndustrialContactProfile2Migration extends MaterioBasicMigration {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
global $user;
|
||||
$this->description = t('Migrate Materio Industrials Contact Profiles2');
|
||||
|
||||
// provide better description for source fields
|
||||
// and add new field source not from sql
|
||||
$source_fields = array(
|
||||
'id_industrial' => t('Industrial id from source'),
|
||||
'contact_quality'=> t('en-fr contat quality implemented on prepare'),
|
||||
'language'=> t('en-fr langauge description, used in prepare'),
|
||||
'tels_contact'=>'',
|
||||
'ccodes_contact'=>'',
|
||||
'memo' => ','
|
||||
);
|
||||
|
||||
|
||||
$query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
|
||||
$query->join(MIG_MAT_SRC_DB .'.industrial_info', 'iinf', 'iid.id_industrial = iinf.id_industrial');
|
||||
|
||||
$ilfr_select = db_select(MIG_MAT_SRC_DB .'.industrial_lang', 'ilfr_select')
|
||||
->fields('ilfr_select')->condition('ilfr_select.id_locale',1)->orderBy('ilfr_select.id_industrial', 'DESC')->distinct();
|
||||
$query->join($ilfr_select, 'ilfr', 'iid.id_industrial = ilfr.id_industrial');
|
||||
|
||||
$ilen_select = db_select(MIG_MAT_SRC_DB .'.industrial_lang', 'ilen_select')
|
||||
->fields('ilen_select')->condition('ilen_select.id_locale',2)->orderBy('ilen_select.id_industrial', 'ASC')->distinct();
|
||||
$query->join($ilen_select, 'ilen', 'iid.id_industrial = ilen.id_industrial');
|
||||
|
||||
|
||||
$query
|
||||
->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
|
||||
->fields('iinf', array('contact', 'contact_title', 'email_contact', 'tel1_contact', 'ccode1_contact', 'tel2_contact', 'ccode2_contact'));
|
||||
|
||||
$query->addField('ilfr', 'contact_quality', 'contact_quality_fr');
|
||||
|
||||
$query->addField('ilen', 'contact_quality', 'contact_quality_en');
|
||||
|
||||
$query
|
||||
->condition('email_contact', '', '<>')
|
||||
->groupBy('iid.id_industrial')
|
||||
->orderBy('iid.id_industrial', 'DESC');
|
||||
|
||||
|
||||
$this->source = new MigrateSourceSQL($query, $source_fields);
|
||||
// $this->dependencies = array('MaterioIndustrialUser');
|
||||
$this->destination = new MigrateDestinationProfile2('contact_operationnel');
|
||||
|
||||
$this->map = new MigrateSQLMap($this->machineName,
|
||||
array(
|
||||
'id_industrial' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'OLD Unique industrial ID',
|
||||
'alias' => 'iid',
|
||||
)
|
||||
),
|
||||
MigrateDestinationProfile2::getKeySchema()
|
||||
);
|
||||
|
||||
// Connecting the profile2 to the user:
|
||||
$this->addFieldMapping('uid', 'id_industrial')
|
||||
->sourceMigration('MaterioIndustrialContactUser') // If your user migration class was named 'MyUserMigration', the string is 'MyUser'
|
||||
->description(t('The assignment of profile2-items to the respective Contact user'));
|
||||
|
||||
$this->addFieldMapping('revision_uid', 'id_industrial')
|
||||
->sourceMigration('MaterioIndustrialContactUser');
|
||||
|
||||
// Make the mappings
|
||||
$this->addFieldMapping('language')->defaultValue('');
|
||||
|
||||
$this->addFieldMapping('field_private_name', 'contact');
|
||||
$this->addFieldMapping('field_private_name_title', 'contact_title');
|
||||
|
||||
// see on prepareRow()
|
||||
$this->addFieldMapping('field_private_quality', 'contact_quality');
|
||||
$this->addFieldMapping('field_private_quality:language', 'language');
|
||||
$this->addFieldMapping(NULL, 'contact_quality_en');
|
||||
$this->addFieldMapping(NULL, 'contact_quality_fr');
|
||||
|
||||
|
||||
|
||||
$this->addFieldMapping('field_private_email', 'email_contact'); // http://drupal.org/node/1232028
|
||||
|
||||
$arguments = array(
|
||||
'number' => array('source_field' => 'tel1_contact'),
|
||||
// 'extension' => array('source_field' => 'ccode1_contact'),
|
||||
);
|
||||
$this->addFieldMapping('field_private_phone', 'ccode1_contact')
|
||||
->arguments($arguments);
|
||||
|
||||
$this->addFieldMapping(NULL, 'tel1_contact');
|
||||
// $this->addFieldMapping(NULL, 'ccode1_contact');
|
||||
$this->addFieldMapping(NULL, 'tel2_contact');
|
||||
$this->addFieldMapping(NULL, 'ccode2_contact');
|
||||
|
||||
$this->addFieldMapping('field_memo', 'memo');
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function prepareRow($cr) {
|
||||
if($cr->email_contact == "")
|
||||
return false;
|
||||
|
||||
|
||||
$cr->contact_quality = array($cr->contact_quality_en, $cr->contact_quality_fr);
|
||||
$cr->language = array('en', 'fr');
|
||||
|
||||
$ccs = cck_phone_countrycodes();
|
||||
$match = 0;
|
||||
foreach ($ccs as $cc => $cc_values) {
|
||||
if('+'.preg_replace('/^\+/', '', $cr->ccode1_contact) == $cc_values['code']){
|
||||
$cr->ccode1_contact = $cc;
|
||||
$match++;
|
||||
}
|
||||
if('+'.preg_replace('/^\+/', '', $cr->ccode2_contact) == $cc_values['code']){
|
||||
$cr->ccode2_contact = $cc;
|
||||
$match++;
|
||||
}
|
||||
if($match == 2)
|
||||
break;
|
||||
}
|
||||
|
||||
if(strlen($cr->ccode1_contact) > 2 && $cr->tel1_contact != "" ){
|
||||
$cr->memo .= "\n".'tel1 contact : '. $cr->ccode1_contact .' '. $cr->tel1_contact;
|
||||
$cr->tel1_contact = NULL;
|
||||
$cr->ccode1_contact = NULL;
|
||||
}
|
||||
|
||||
if(strlen($cr->tel1_contact) > 15){
|
||||
$cc = cck_phone_countrycodes($cr->ccode1_contact);
|
||||
$cr->memo .= "\n".'tel1 contact : '. $cc['country'] . ' (' . $cc['code'] . ')' .' '. $cr->tel1_contact;
|
||||
$cr->tel1_contact = NULL;
|
||||
$cr->ccode1_contact = NULL;
|
||||
}
|
||||
|
||||
if($cr->tel2_contact != ''){
|
||||
$cc = cck_phone_countrycodes($cr->ccode2_contact);
|
||||
$cr->memo .= "\n".'tel2 contact : '. $cc['country'] . ' (' . $cc['code'] . ')' .' '. $cr->tel2_contact;
|
||||
}
|
||||
|
||||
// dsm($cr, '- - - - $cr - - - -');
|
||||
|
||||
return TRUE;
|
||||
// return FALSE if you wish to skip a particular row
|
||||
}
|
||||
|
||||
|
||||
|
||||
// public function prepare($node, stdClass $row) {
|
||||
// // dsm('-- prepare --');
|
||||
// // dsm($node, '$node');
|
||||
// // dsm($row, '$row');
|
||||
//
|
||||
// // $node->field_private_email = array('und'=>array($row->email_contact));
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
46
sites/all/modules/gui/migrate_materio/migrate_materio.info
Normal file
46
sites/all/modules/gui/migrate_materio/migrate_materio.info
Normal file
@ -0,0 +1,46 @@
|
||||
name = Migrate Materio
|
||||
description = "Migrate module to migrate the old materio base to drupal"
|
||||
|
||||
; Core version (required)
|
||||
core = 7.x
|
||||
|
||||
; Package name (see http://drupal.org/node/542202 for a list of names)
|
||||
; package =
|
||||
|
||||
; PHP version requirement (optional)
|
||||
; php = 5.2
|
||||
|
||||
; Loadable code files
|
||||
files[] = migrate_materio.module
|
||||
files[] = migrate_materio.basic.inc
|
||||
files[] = migrate_materio.adherent.inc
|
||||
files[] = migrate_materio.company.inc
|
||||
files[] = migrate_materio.account.inc
|
||||
files[] = migrate_materio.contact.inc
|
||||
files[] = migrate_materio.admin.inc
|
||||
files[] = migrate_materio.sample.inc
|
||||
files[] = migrate_materio.materiau.inc
|
||||
files[] = migrate_materio.breves.inc
|
||||
|
||||
; Module dependencies
|
||||
dependencies[] = migrate
|
||||
dependencies[] = migrate_extras
|
||||
dependencies[] = field
|
||||
; dependencies[] = file
|
||||
; dependencies[] = image
|
||||
dependencies[] = number
|
||||
dependencies[] = text
|
||||
dependencies[] = options
|
||||
dependencies[] = taxonomy
|
||||
; dependencies[] = date
|
||||
dependencies[] = link
|
||||
; dependencies[] = media
|
||||
dependencies[] = uc_store
|
||||
dependencies[] = uc_roles
|
||||
|
||||
; Configuration page
|
||||
; configure = admin/config/migrate_materio
|
||||
|
||||
|
||||
; For further information about configuration options, see
|
||||
; - http://drupal.org/node/542202
|
@ -0,0 +1,203 @@
|
||||
<?php
|
||||
/**
|
||||
* MaterioMateriauNodeMigration
|
||||
*
|
||||
*/
|
||||
class MaterioMateriauNodeMigration extends MaterioBasicMigration {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->description = t('Migrate Materio Materiau nodes');
|
||||
|
||||
// provide better description for source fields
|
||||
// and add new field source not from sql
|
||||
$source_fields = array(
|
||||
'id_product' => t('Materiau id from source'),
|
||||
'company_fab'=>t('company_fab'),
|
||||
'company_distrib'=>t('company_distrib'),
|
||||
'title'=>t('title'),
|
||||
'name'=> t('en-fr name implemented on prepare'),
|
||||
'description'=> t('en-fr description implemented on prepare'),
|
||||
'nature'=> t('en-fr nature implemented on prepare'),
|
||||
'language'=> t('en-fr langauge description, used in prepare'),
|
||||
'family' => '',
|
||||
'localisation' => '',
|
||||
'identifiant' => '',
|
||||
);
|
||||
|
||||
$query = db_select(MIG_MAT_SRC_DB .'.product_id', 'pid');
|
||||
|
||||
$query->join(MIG_MAT_SRC_DB .'.product_industrial', 'pind', 'pind.id_product = pid.id_product');
|
||||
|
||||
$query
|
||||
->fields('pid', array('id_product', 'id_materio', 'status', 'memo', 'source', 'date_creation', 'date_modif'))
|
||||
->fields('pind', array('id_industrial', 'quarity'));
|
||||
|
||||
$query->addExpression('GROUP_CONCAT(DISTINCT pind.id_industrial)','list_industrial');
|
||||
$query->addExpression('GROUP_CONCAT(pind.quarity)','list_quarity');
|
||||
|
||||
$query
|
||||
->orderBy('pid.id_product', 'DESC')
|
||||
->groupBy('pid.id_product');
|
||||
|
||||
$this->source = new MigrateSourceSQL($query, $source_fields);
|
||||
$this->destination = new MigrateDestinationNode('materiau');
|
||||
|
||||
$this->map = new MigrateSQLMap($this->machineName,
|
||||
array(
|
||||
'id_product' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'OLD Unique Materiau ID',
|
||||
'alias' => 'pid',
|
||||
)
|
||||
),
|
||||
MigrateDestinationNode::getKeySchema()
|
||||
);
|
||||
|
||||
$this->addFieldMapping('is_new')->defaultValue(TRUE);
|
||||
$this->addFieldMapping('created', 'date_creation');
|
||||
$this->addFieldMapping('changed', 'date_modif');
|
||||
$this->addFieldMapping('status')->defaultValue(1);
|
||||
$this->addFieldMapping('promote')->defaultValue(0);
|
||||
$this->addFieldMapping('sticky')->defaultValue(0);
|
||||
$this->addFieldMapping('language')->defaultValue('en');
|
||||
|
||||
$this->addFieldMapping('title', 'title');
|
||||
$this->addFieldMapping('field_memo', 'memo');
|
||||
|
||||
$this->addFieldMapping('title_field', 'name');
|
||||
$this->addFieldMapping('title_field:language', 'language');
|
||||
|
||||
$this->addFieldMapping('field_description', 'description');
|
||||
$this->addFieldMapping('field_description:language', 'language');
|
||||
$this->addFieldMapping('field_description:format')->defaultValue('filtred_html');
|
||||
|
||||
$this->addFieldMapping('field_nature_titre', 'nature');
|
||||
$this->addFieldMapping('field_nature_titre:language', 'language');
|
||||
|
||||
$this->addFieldMapping('field_company_fab', 'company_fab');
|
||||
$this->addFieldMapping('field_company_fab:create_term')->defaultValue(false);
|
||||
$this->addFieldMapping('field_company_distrib', 'company_distrib');
|
||||
$this->addFieldMapping('field_company_distrib:create_term')->defaultValue(false);
|
||||
|
||||
$this->addFieldMapping('pathauto')->defaultValue(1);
|
||||
$this->addFieldMapping('comment')->defaultValue(0);
|
||||
$this->addFieldMapping('revision')->defaultValue(0);
|
||||
|
||||
$this->addFieldMapping(null, 'id_industrial');
|
||||
$this->addFieldMapping(null, 'quarity');
|
||||
|
||||
$this->addFieldMapping('field_onthologie')->defaultValue(null);
|
||||
|
||||
$this->addFieldMapping('field_famille', 'family');
|
||||
$this->addFieldMapping('field_localisation', 'localisation');
|
||||
$this->addFieldMapping('field_identifiant', 'identifiant');
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function prepareRow($cr){
|
||||
// dsm($cr);
|
||||
|
||||
# get product infos FR
|
||||
$infos_fr = db_select(MIG_MAT_SRC_DB .'.product_info', 'pif_fr')
|
||||
->condition('pif_fr.id_locale', 2)
|
||||
->condition('pif_fr.id_product', $cr->id_product)
|
||||
->fields('pif_fr' , array('name', 'nature', 'description', 'technical', 'keywords'))//, 'usage'
|
||||
->distinct()->execute();
|
||||
|
||||
foreach ($infos_fr as $record)
|
||||
$infos['fr'] = $record;
|
||||
|
||||
if($infos['fr']->technical != '')
|
||||
$infos['fr']->description .= "<br />technical : ".$infos['fr']->technical; // . "<br />usage".$infos['fr']->usage
|
||||
|
||||
# get product infos EN
|
||||
$infos_en = db_select(MIG_MAT_SRC_DB .'.product_info', 'pif_en')
|
||||
->condition('pif_en.id_locale', 1)
|
||||
->condition('pif_en.id_product', $cr->id_product)
|
||||
->fields('pif_en' , array('name', 'nature', 'description', 'technical', 'keywords'))//, 'usage' , 'keywords'
|
||||
->distinct()->execute();
|
||||
|
||||
foreach ($infos_en as $record)
|
||||
$infos['en'] = $record;
|
||||
|
||||
if($infos['en']->technical != '')
|
||||
$infos['en']->description .= "<br />technical : ".$infos['en']->technical; // . "<br />usage".$infos['en']->usage
|
||||
|
||||
# set product infos
|
||||
$cr->title = $infos['fr']->name;
|
||||
$cr->name = array($infos['en']->name, $infos['fr']->name);
|
||||
$cr->description = array($infos['en']->description, $infos['fr']->description);
|
||||
$cr->nature = array($infos['en']->nature, $infos['fr']->nature);
|
||||
$cr->language = array('en', 'fr');
|
||||
|
||||
# record keywords on memo
|
||||
$cr->memo .= ($cr->memo != '' ? "\n\n" : '') . $infos['fr']->keywords;
|
||||
|
||||
# parse companies
|
||||
// dsm($cr->list_industrial, '-- $cr->list_industrial');
|
||||
// dsm($cr->list_quarity, '$cr->list_quarity');
|
||||
$industrials = explode(',', $cr->list_industrial);
|
||||
$quarities = explode(',', $cr->list_quarity);
|
||||
|
||||
$companies_fab = array();
|
||||
$companies_distrib = array();
|
||||
|
||||
$l = count($industrials);
|
||||
for ($i=0; $i < $l; $i++) {
|
||||
$result = db_select(MIG_MAT_SRC_DB .'.industrial_info', 'iif')
|
||||
->fields('iif', array('id_industrial', 'company'))
|
||||
->condition('iif.id_industrial', $industrials[$i])
|
||||
->distinct()->execute();
|
||||
|
||||
foreach ($result as $record) {
|
||||
// dsm($record);
|
||||
$company = trim($record->company);
|
||||
if(count(taxonomy_get_term_by_name($company.'-'.$record->id_industrial)))
|
||||
$company .= '-'.$record->id_industrial;
|
||||
|
||||
if($quarities[$i] == 'M'){
|
||||
$companies_fab[] = $company;
|
||||
}else{
|
||||
$companies_distrib[] = $company;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$cr->company_fab = implode(',', $companies_fab);
|
||||
$cr->company_distrib = implode(',', $companies_distrib);
|
||||
|
||||
|
||||
preg_match('/^(\w)([^-]+)-(\d+)$/', $cr->id_materio, $matches);
|
||||
// dsm($matches);
|
||||
$cr->family = $matches[1];
|
||||
$cr->localisation = $matches[2];
|
||||
$cr->identifiant = $matches[3];
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
public function prepare($node, stdClass $row) {
|
||||
// dsm('-- prepare --');
|
||||
// dsm($node, '$node');
|
||||
// dsm($row, '$row');
|
||||
|
||||
$node->workflow = 4;
|
||||
|
||||
$node->field_identifiant['und'][0]['value'] = $row->identifiant;
|
||||
}
|
||||
|
||||
// public function complete($node, $row) {
|
||||
// // dsm('-- complete --');
|
||||
// // // Do what you need to do to
|
||||
// // dsm($row, '$row');
|
||||
// // dsm($node, '$node');
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
72
sites/all/modules/gui/migrate_materio/migrate_materio.module
Normal file
72
sites/all/modules/gui/migrate_materio/migrate_materio.module
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* This is the file description for Migrate Materio module.
|
||||
*
|
||||
* In this more verbose, multi-line description, you can specify what this
|
||||
* file does exactly. Make sure to wrap your documentation in column 78 so
|
||||
* that the file can be displayed nicely in default-sized consoles.
|
||||
*/
|
||||
define('MIG_MAT_SRC_DB', variable_get('migrate_materio_database', ''));
|
||||
define('MIG_MAT_SRC_DB_D6', variable_get('migrate_materio_database_drupal6', ''));
|
||||
|
||||
/**
|
||||
* You must implement hook_migrate_api(), setting the API level to 2, for
|
||||
* your migration classes to be recognized by the Migrate module (for the 7.x-2.x branch).
|
||||
*/
|
||||
function migrate_materio_migrate_api() {
|
||||
$api = array(
|
||||
'api' => 2,
|
||||
);
|
||||
return $api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function migrate_materio_menu() {
|
||||
$items = array();
|
||||
|
||||
$items['admin/config/development/migrate_materio'] = array(
|
||||
'title' => 'Materio Migration Settings',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('migrate_materio_settings'),
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('administer site configuration'),
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Form to setting up the database name and migration file path for migration of data.
|
||||
*/
|
||||
function migrate_materio_settings($form, &$form_state) {
|
||||
$form['migrate_materio_database'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => 'Database name',
|
||||
'#default_value' => variable_get('migrate_materio_database', ''),
|
||||
'#description' => t('Please enter the name of the database. Note that the database must be accessible by current website db user and must reside on the same db server.'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
$form['migrate_materio_database_drupal6'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => 'Drupal 6 Database name',
|
||||
'#default_value' => variable_get('migrate_materio_database_drupal6', ''),
|
||||
'#description' => t('Please enter the name of the drupal 6 database. Note that the database must be accessible by current website db user and must reside on the same db server.'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
// $form['redcat_migration_file_path'] = array(
|
||||
// '#type' => 'textfield',
|
||||
// '#title' => 'Migrated Files Path',
|
||||
// '#default_value' => variable_get('redcat_migration_file_path', '/Users/amodi/Sites/redcat.org/sites/redcat.org/files'),
|
||||
// '#description' => t('Please enter the full path to get to the home directory of the migrating site - the files will be found through the base'),
|
||||
// '#required' => TRUE,
|
||||
// );
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* MaterioIndustrialUserMigration
|
||||
*
|
||||
*/
|
||||
class MaterioIndustrialSampleUserMigration extends MaterioBasicMigration {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->description = t('Migrate Materio Industrials Email Sample Users');
|
||||
|
||||
// provide better description for source fields
|
||||
// and add new field source not from sql
|
||||
$source_fields = array(
|
||||
'id_industrial' => t('Industrial id from source'),
|
||||
'memo' => t('memo'),
|
||||
);
|
||||
|
||||
$query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
|
||||
$query->join(MIG_MAT_SRC_DB .'.industrial_info', 'iinf', 'iid.id_industrial = iinf.id_industrial');
|
||||
|
||||
$query
|
||||
->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
|
||||
->fields('iinf', array('company', 'email_sample'))
|
||||
->condition('email_sample', '', '<>')
|
||||
->orderBy('iid.id_industrial', 'DESC')
|
||||
->groupBy('iid.id_industrial');
|
||||
|
||||
$this->source = new MigrateSourceSQL($query, $source_fields);
|
||||
$this->destination = new MigrateDestinationUser();
|
||||
|
||||
$this->map = new MigrateSQLMap($this->machineName,
|
||||
array(
|
||||
'id_industrial' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'OLD Unique industrial ID',
|
||||
'alias' => 'iid',
|
||||
)
|
||||
),
|
||||
MigrateDestinationUser::getKeySchema()
|
||||
);
|
||||
|
||||
// Make the mappings
|
||||
$this->addFieldMapping('name')->defaultValue('aname');
|
||||
$this->addFieldMapping('pass')->defaultValue(NULL);
|
||||
$this->addFieldMapping('mail', 'email_sample');
|
||||
# NOTE : maybe if we provide only init mail, we wiil be able to ask email confirmation for users
|
||||
$this->addFieldMapping('init', 'email_sample');
|
||||
$this->addFieldMapping('language')->defaultValue('');
|
||||
$this->addFieldMapping('theme')->defaultValue('');
|
||||
$this->addFieldMapping('signature')->defaultValue('');
|
||||
$this->addFieldMapping('signature_format')->defaultValue('filtered_html');
|
||||
$this->addFieldMapping('created', 'date_creation');
|
||||
$this->addFieldMapping('access', 'date_modif');
|
||||
$this->addFieldMapping('login')->defaultValue(0);
|
||||
$this->addFieldMapping('status')->defaultValue(0);
|
||||
$this->addFieldMapping('picture')->defaultValue(0);
|
||||
$this->addFieldMapping('timezone')->defaultValue(NULL);
|
||||
// $this->addFieldMapping('path')->issueGroup(t('DNM'));
|
||||
$this->addFieldMapping('pathauto')->defaultValue(1);
|
||||
$this->addFieldMapping('roles')->defaultValue(array(5));
|
||||
$this->addFieldMapping('is_new')->defaultValue(TRUE);
|
||||
|
||||
$this->addFieldMapping('field_memo', 'memo');
|
||||
|
||||
$this->addFieldMapping('field_company', 'company');
|
||||
|
||||
}
|
||||
|
||||
public function prepareRow($cr) {
|
||||
if($cr->email_sample == '')
|
||||
return false;
|
||||
|
||||
$cr->company = trim($cr->company);
|
||||
if(count(taxonomy_get_term_by_name($cr->company.'-'.$cr->id_industrial)))
|
||||
$cr->company .= '-'.$cr->id_industrial;
|
||||
|
||||
$cr->memo = "#sample";
|
||||
|
||||
return TRUE;
|
||||
// return FALSE if you wish to skip a particular row
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user