Compare commits

..
9 Commits
Author SHA1 Message Date
bachy 4fc8e542c3 fixed i18n_taxonomy missing
added module_exists('i18n_taxonomy')

Signed-off-by: bachy <git@g-u-i.net>
2012-02-04 11:47:59 +01:00
bachy 8690f4a165 càrrectif bug : term created even if node form validation fail
- remove taxonomy term save from tod, let taxonomy handle the term
- move all toed process from hook_node_validate to hook_node_submit
- handle node creation with hook_node_presave
- handle node update (with term form) in hook_node_submit

Signed-off-by: bachy <git@g-u-i.net>
2012-02-02 18:48:13 +01:00
bachy 66ff837039 RC
Signed-off-by: bachy <git@g-u-i.net>
2012-01-17 16:14:17 +01:00
bachy 626ec7eabc Parent term options
Signed-off-by: bachy <git@g-u-i.net>
2012-01-07 22:59:15 +01:00
bachy 691ecd7d61 add gui icon
Signed-off-by: bachy <git@g-u-i.net>
2011-10-04 11:37:57 +02:00
bachy 930913e764 term is saved (created) and node tagged with, but then term name will not be updated yet. module can't add term form in the node form yet.
Signed-off-by: bachy <git@g-u-i.net>
2011-09-29 20:36:46 +02:00
bachy ad30a381f9 no message 2011-08-28 11:09:59 +02:00
bachy 951be207ab add readme 2011-08-25 21:32:15 +02:00
bachy 8ec280d5fa project creation 2011-08-25 21:26:47 +02:00
16 changed files with 1017 additions and 1177 deletions
+274
View File
@@ -0,0 +1,274 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave,
Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute
verbatim copies of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your freedom to
share and change it. By contrast, the GNU General Public License is
intended to guarantee your freedom to share and change free software--to
make sure the software is free for all its users. This General Public License
applies to most of the Free Software Foundation's software and to any other
program whose authors commit to using it. (Some other Free Software
Foundation software is covered by the GNU Library General Public License
instead.) You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our
General Public Licenses are designed to make sure that you have the
freedom to distribute copies of free software (and charge for this service if
you wish), that you receive source code or can get it if you want it, that you
can change the software or use pieces of it in new free programs; and that
you know you can do these things.
To protect your rights, we need to make restrictions that forbid anyone to
deny you these rights or to ask you to surrender the rights. These restrictions
translate to certain responsibilities for you if you distribute copies of the
software, or if you modify it.
For example, if you distribute copies of such a program, whether gratis or for
a fee, you must give the recipients all the rights that you have. You must make
sure that they, too, receive or can get the source code. And you must show
them these terms so they know their rights.
We protect your rights with two steps: (1) copyright the software, and (2)
offer you this license which gives you legal permission to copy, distribute
and/or modify the software.
Also, for each author's protection and ours, we want to make certain that
everyone understands that there is no warranty for this free software. If the
software is modified by someone else and passed on, we want its recipients
to know that what they have is not the original, so that any problems
introduced by others will not reflect on the original authors' reputations.
Finally, any free program is threatened constantly by software patents. We
wish to avoid the danger that redistributors of a free program will individually
obtain patent licenses, in effect making the program proprietary. To prevent
this, we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
The precise terms and conditions for copying, distribution and modification
follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND
MODIFICATION
0. This License applies to any program or other work which contains a notice
placed by the copyright holder saying it may be distributed under the terms
of this General Public License. The "Program", below, refers to any such
program or work, and a "work based on the Program" means either the
Program or any derivative work under copyright law: that is to say, a work
containing the Program or a portion of it, either verbatim or with
modifications and/or translated into another language. (Hereinafter, translation
is included without limitation in the term "modification".) Each licensee is
addressed as "you".
Activities other than copying, distribution and modification are not covered
by this License; they are outside its scope. The act of running the Program is
not restricted, and the output from the Program is covered only if its contents
constitute a work based on the Program (independent of having been made
by running the Program). Whether that is true depends on what the Program
does.
1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this License
and to the absence of any warranty; and give any other recipients of the
Program a copy of this License along with the Program.
You may charge a fee for the physical act of transferring a copy, and you
may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion of it,
thus forming a work based on the Program, and copy and distribute such
modifications or work under the terms of Section 1 above, provided that you
also meet all of these conditions:
a) You must cause the modified files to carry prominent notices stating that
you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in whole or in
part contains or is derived from the Program or any part thereof, to be
licensed as a whole at no charge to all third parties under the terms of this
License.
c) If the modified program normally reads commands interactively when run,
you must cause it, when started running for such interactive use in the most
ordinary way, to print or display an announcement including an appropriate
copyright notice and a notice that there is no warranty (or else, saying that
you provide a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this License.
(Exception: if the Program itself is interactive but does not normally print such
an announcement, your work based on the Program is not required to print
an announcement.)
These requirements apply to the modified work as a whole. If identifiable
sections of that work are not derived from the Program, and can be
reasonably considered independent and separate works in themselves, then
this License, and its terms, do not apply to those sections when you distribute
them as separate works. But when you distribute the same sections as part
of a whole which is a work based on the Program, the distribution of the
whole must be on the terms of this License, whose permissions for other
licensees extend to the entire whole, and thus to each and every part
regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your rights to
work written entirely by you; rather, the intent is to exercise the right to
control the distribution of derivative or collective works based on the
Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of a
storage or distribution medium does not bring the other work under the scope
of this License.
3. You may copy and distribute the Program (or a work based on it, under
Section 2) in object code or executable form under the terms of Sections 1
and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable source
code, which must be distributed under the terms of Sections 1 and 2 above
on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three years, to give
any third party, for a charge no more than your cost of physically performing
source distribution, a complete machine-readable copy of the corresponding
source code, to be distributed under the terms of Sections 1 and 2 above on
a medium customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer to distribute
corresponding source code. (This alternative is allowed only for
noncommercial distribution and only if you received the program in object
code or executable form with such an offer, in accord with Subsection b
above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source code
means all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation and
installation of the executable. However, as a special exception, the source
code distributed need not include anything that is normally distributed (in
either source or binary form) with the major components (compiler, kernel,
and so on) of the operating system on which the executable runs, unless that
component itself accompanies the executable.
If distribution of executable or object code is made by offering access to
copy from a designated place, then offering equivalent access to copy the
source code from the same place counts as distribution of the source code,
even though third parties are not compelled to copy the source along with the
object code.
4. You may not copy, modify, sublicense, or distribute the Program except as
expressly provided under this License. Any attempt otherwise to copy,
modify, sublicense or distribute the Program is void, and will automatically
terminate your rights under this License. However, parties who have received
copies, or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
5. You are not required to accept this License, since you have not signed it.
However, nothing else grants you permission to modify or distribute the
Program or its derivative works. These actions are prohibited by law if you
do not accept this License. Therefore, by modifying or distributing the
Program (or any work based on the Program), you indicate your acceptance
of this License to do so, and all its terms and conditions for copying,
distributing or modifying the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these terms and
conditions. You may not impose any further restrictions on the recipients'
exercise of the rights granted herein. You are not responsible for enforcing
compliance by third parties to this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues), conditions
are imposed on you (whether by court order, agreement or otherwise) that
contradict the conditions of this License, they do not excuse you from the
conditions of this License. If you cannot distribute so as to satisfy
simultaneously your obligations under this License and any other pertinent
obligations, then as a consequence you may not distribute the Program at all.
For example, if a patent license would not permit royalty-free redistribution
of the Program by all those who receive copies directly or indirectly through
you, then the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply and
the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or
other property right claims or to contest validity of any such claims; this
section has the sole purpose of protecting the integrity of the free software
distribution system, which is implemented by public license practices. Many
people have made generous contributions to the wide range of software
distributed through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing to
distribute software through any other system and a licensee cannot impose
that choice.
This section is intended to make thoroughly clear what is believed to be a
consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in certain
countries either by patents or by copyrighted interfaces, the original copyright
holder who places the Program under this License may add an explicit
geographical distribution limitation excluding those countries, so that
distribution is permitted only in or among countries not thus excluded. In such
case, this License incorporates the limitation as if written in the body of this
License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will be
similar in spirit to the present version, but may differ in detail to address new
problems or concerns.
Each version is given a distinguishing version number. If the Program specifies
a version number of this License which applies to it and "any later version",
you have the option of following the terms and conditions either of that
version or of any later version published by the Free Software Foundation. If
the Program does not specify a version number of this License, you may
choose any version ever published by the Free Software Foundation.
10. If you wish to incorporate parts of the Program into other free programs
whose distribution conditions are different, write to the author to ask for
permission. For software which is copyrighted by the Free Software
Foundation, write to the Free Software Foundation; we sometimes make
exceptions for this. Our decision will be guided by the two goals of
preserving the free status of all derivatives of our free software and of
promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE,
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT
PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR
AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR
ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL,
SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OR INABILITY TO USE THE
PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA
OR DATA BEING RENDERED INACCURATE OR LOSSES
SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE
PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN
IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF
THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
+1
View File
@@ -0,0 +1 @@
!!! this module is not ready tu use !!!
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 690 B

-85
View File
@@ -1,85 +0,0 @@
<?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
}
}
-235
View File
@@ -1,235 +0,0 @@
<?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);
$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('+'.$cr->ccode1_admin == $cc_values['code']){
$cr->ccode1_admin = $cc;
$match++;
}
if('+'.$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));
}
}
-11
View File
@@ -1,11 +0,0 @@
<?php
/**
* MaterioBasicMigration
*
*/
abstract class MaterioBasicMigration extends Migration {
public function __construct(){
$this->description = t('Migrate Materio Basic Class');
parent::__construct(MigrateGroup::getInstance('MaterioMigrate'));
}
}
-229
View File
@@ -1,229 +0,0 @@
<?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'=>t('premise'),
'sub_premise'=>t('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('');
$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(
// 'name_line' => array('source_field' => 'name'),
'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'),
// 'extension' => array('source_field' => 'ccode1_contact'),
);
$this->addFieldMapping('field_public_phone', 'ccode1')
->arguments($arguments);
$this->addFieldMapping(NULL, 'tel1');
// $this->addFieldMapping(NULL, 'ccode1_contact');
$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 : '';
}
$cr->city = preg_replace('/\\n/', ' ', $cr->city);
$cr->department = array($cr->department_en, $cr->department_fr);
// $cr->contact_quality = array($cr->contact_quality_en, $cr->contact_quality_fr);
// $cr->admin_quality = array($cr->admin_quality_en, $cr->admin_quality_fr);
$cr->language = array('en', 'fr');
$cr->web_title = str_replace('http://', '', $cr->web);
$cr->web = 'http://' . $cr->web_title;
$cr->company = trim($cr->company);
// if($cr->email_general != "")
// $cr->email_sample .= ','.$cr->email_general;
$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));
}
}
-240
View File
@@ -1,240 +0,0 @@
<?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);
$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('+'.$cr->ccode1_contact == $cc_values['code']){
$cr->ccode1_contact = $cc;
$match++;
}
if('+'.$cr->ccode2_contact == $cc_values['code']){
$cr->ccode2_contact = $cc;
$match++;
}
if($match == 2)
break;
}
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));
//
// }
}
-42
View File
@@ -1,42 +0,0 @@
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.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
; 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
; Configuration page
; configure = admin/config/migrate_materio
; For further information about configuration options, see
; - http://drupal.org/node/542202
-186
View File
@@ -1,186 +0,0 @@
<?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'),
);
$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('fr');
$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);
}
public function prepareRow($cr){
// dsm($cr);
# parse product infos
$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;
$infos['fr']->description .= "<br />technical : ".$infos['fr']->technical; // . "<br />usage".$infos['fr']->usage
$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;
$infos['en']->description .= "<br />technical : ".$infos['en']->technical; // . "<br />usage".$infos['en']->usage
$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('company'))
->condition('iif.id_industrial', $industrials[$i])
->distinct()->execute();
foreach ($result as $record) {
// dsm($record);
$company = trim($record->company);
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);
//
return TRUE;
}
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));
}
}
-64
View File
@@ -1,64 +0,0 @@
<?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', ''));
/**
* 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['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);
}
-85
View File
@@ -1,85 +0,0 @@
<?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);
$cr->memo = "#sample";
return TRUE;
// return FALSE if you wish to skip a particular row
}
}
+1
View File
@@ -0,0 +1 @@
!!! this module is not ready tu use !!!
+3
View File
@@ -0,0 +1,3 @@
.ctu-term-edit-form-box{border: 1px solid #ddd; padding:0.5em;}
#node-form fieldset.tcu-advanced-options,
#node-form fieldset.tcu-term-fields{width:45%; display:inline-block; vertical-align: top;}
+9
View File
@@ -0,0 +1,9 @@
name = Tode
description = First time this field will be used, it will create a new term with the value inserted in the textfield, after that, the term (tid) will always be the same, just update term name by updating the value of the field. You can keep synchronized a fixe term with a node, you can set an auto title from this field, The required, number of value at 1 and term_node synch of global field are required
project = "Tode"
dependencies[] = taxonomy
dependencies[] = field
package = gui
version = "7.x-0.dev"
core = "7.x"
+729
View File
@@ -0,0 +1,729 @@
<?php
/**
* developed by www.g-u-i.net
* 2011
* First time this field will be used, it will create a new term with the value inserted in the textfield,
* after that, the term (tid) will always be the same, just update term name by updating the value of the field.
* You can keep synchronized a fixe term with a node,
* you can set an auto title from this field, The required,
* number of value at 1 and term_node synch of global field are required
*
*
*/
/**
* Implementation of hook_menu().
*/
/*
function tode_menu() {
$items = array();
// $items['node/%node/tode/%term'] = array(
// 'title' => 'Taxonomy Term',
// 'type' => MENU_LOCAL_TASK,
// 'access callback' => 'tode_node_tab_access',
// 'access arguments' => array(2),
// 'page callback' => 'tode_tab_page',
// 'page arguments' => array(2),
// 'file' => 'tode.pages.inc',
// 'weight' => 2,
// );
return $items;
}
*/
/**
* Implementation of hook_theme().
*/
function tode_theme() {
return array(
'tode' => array(
'arguments' => array('element' => NULL),
),
);
}
/**
* Implementation of hook_init().
*/
function tode_init() {
// File hooks and callbacks may be used by any module.
drupal_add_css(drupal_get_path('module', 'tode') .'/tode.css');
}
/**
* Implementation of hook_field_widget_info().
*/
function tode_field_widget_info() {
return array(
'tode' => array(
'label' => t('Tode (create then update one unique term)'),
'field types' => array('taxonomy_term_reference'),
'behaviors' => array(
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
'default value' => FIELD_BEHAVIOR_NONE,
),
'settings' => array(
'size' => 60,
'show_term_form'=> -1,
'choose_term_parent'=> -1,
'maxlength'=> 255,
),
),
);
}
/**
* Implementation of hook_widget_settings
*/
function tode_field_widget_settings_form($field, $instance){
// dsm($instance, 'tode_field_widget_settings_form : $instance');
// dsm($field, 'field');
$widget = $instance['widget'];
$settings = $widget['settings'];
// '#description' => t('First time this field will be used, it will create a new term with the value inserted in the textfield, after that, the term (tid) will always be the same, just update term name by updating the value of the field. You can keep synchronized a fixe term with a node, you can set an auto title from this field, The required, number of value at 1 and term_node synch of global field are required')
$form['maxlength'] = array(
'#type' => 'textfield',
'#title' => t('Maximum length of term'),
'#default_value' => $settings['maxlength'],
'#element_validate' => array('_tode_widget_settings_maxlength_validate'),
'#required' => TRUE,
'#description' => t('Defines how many characters can be typed into the text field. For values higher than 255, remember that one term name can not be longer than 255 (would be cutted).'),
);
/*
TODO complete the all flow of this
*/
$form['show_term_form'] = array(
'#type' => 'checkbox',
'#title' => t('Show taxonomy term edit form ?'),
'#default_value' => $settings['show_term_form'],
);
$form['choose_term_parent'] = array(
'#type' => 'checkbox',
'#title' => t('Enable taxonomy term parent selection ?'),
'#default_value' => $settings['choose_term_parent'],
);
return $form;
}
function _tode_widget_settings_maxlength_validate($element, &$form_state) {
// dsm('_tode_widget_settings_maxlength_validate');
// dsm($element, '$element');
// dsm($form_state, '$form_state');
$widget = $form_state['values']['instance']['widget'];
$value = $widget['settings']['maxlength'];
if (!is_numeric($value) || intval($value) != $value || $value <= 0) {
form_error($element, t('"Maximum length" must be a positive integer.'));
}
}
/**
* Implementation of FAPI hook_elements().
*
* Any FAPI callbacks needed for individual widgets can be declared here,
* and the element will be passed to those callbacks for processing.
*
* Drupal will automatically theme the element using a theme with
* the same name as the hook_elements key.
*
* Autocomplete_path is not used by text_widget but other widgets can use it
* (see nodereference and userreference).
*
* http://drupal.org/node/224333#hook_element_info
*
*/
#hook_element_info() WHY ??
/*
function tode_element_info(){
return array(
'tode' => array(
'#input' => TRUE,
'#columns' => array('value'),
'#delta' => 0,
'#process' => array('tode_element_process'),
),
);
}
*/
/**
* Implementation of hook_field_widget_form().
*/
function tode_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
// dsm('- - - - tode_field_widget_form');
// dsm($form, '&$form');
// dsm($form_state, '&$form_state');
// dsm($items, 'items');
// dsm($element, '$element');
// dsm($field, '$field');
// dsm($instance, '$instance');
$node = $form_state['node'];
// dsm($node, '$node');
if(isset($items[$delta])){
$term = taxonomy_term_load($items[$delta]['tid']);
// $term = i18n_taxonomy_term_get_translation($term, $node->language); // marche pas avec localized term
// dsm($term, '$term');
$term_parents = taxonomy_get_parents($term->tid);
// dsm($term_parents, '$term_parents');
$term_parent = array_pop($term_parents);
}
# no need of $node->translation_source because with node translation (not entity fields translation) tid remains
# just have to translate term name on submit
// if( !isset($node->id) && isset($node->translation_source) ){
// }
$form['tode_tid'] = array('#type' => 'hidden', '#value' => isset($term) ? $term->tid : 0,'#delta' => $element['#delta'],);
# parent
if( $instance['widget']['settings']['choose_term_parent'] ){
// add parent form autocomplete if activated
$vocabularies = array();
foreach ($field['settings']['allowed_values'] as $tree)
if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary']))
$vocabularies[$vocabulary->vid] = $vocabulary;
$vocabulary = reset($vocabularies);
// dsm($vocabulary, '$vocabulary');
$form['tode_vid'] = array('#type' => 'hidden', '#value' => $vocabulary->vid,'#delta' => $element['#delta'],);
$form['tode_parent_term'] = array(
'#title' => 'Parent ' . $vocabulary->name . ' (optional)',
'#type' => 'textfield',
'#default_value' => isset($term_parent) ? $term_parent->name : '',
'#autocomplete_path' => 'taxonomy/autocomplete' . '/' . $field['field_name'],
'#size' => 60,
'#maxlength' => 1024,
'#element_validate' => array('tode_parent_autocomplete_validate'),
);
}else{
// if parent selection not enabled set the current parent as hidden input
$form['tode_parent_term'] = array(
'#type' => 'hidden',
'#value' => isset($term_parent) ? $term_parent->name : '',
'#delta' => $element['#delta'],
);
}
// set element form item
$element += array(
'#type' => 'textfield',
'#default_value' => isset($term) ? ( if(module_exists('i18n_taxonomy')) ? i18n_taxonomy_term_name($term, $node->language) : $term->name ) : '',
'#size' => $instance['widget']['settings']['size'],
'#maxlength' => $instance['widget']['settings']['maxlength'],
'#element_validate' => array('tode_widget_validate'),
// '#element_submit' => array('tode_widget_submit'),
);
# add the term edit form
if(isset($term))
_tode_add_term_form($form, $term, $instance, $element['#delta']);
// dsm($form, 'end tode_field_widget_form :: $form');
return $element;
}
/**
* _tode_add_term_form($term)
*
* show the complete taxonomy term form if feature is enabled
*
*/
function _tode_add_term_form(&$form, $term, $instance, $delta){
// dsm('- - - - _tode_add_term_form');
module_load_include('inc', 'taxonomy', 'taxonomy.admin');
$term_form = _tode_term_form($term);
// dsm($term_form, 'term_form');
if($term_form){
unset($term_form['actions']);
unset($term_form['#action']);
unset($term_form['#method']);
#unset vid info 'cause is in conflict with the node's vid field
unset($term_form['vid']);
$term_form = _tode_clean_form($term_form);
$prefix = 'tode_termform_'.$instance['field_name'];
$term_form = _tode_prefix_form($term_form, $prefix.'_');
$visible = $instance['widget']['settings']['show_term_form'];
$form[$prefix] = array(
'#type' => 'fieldset',
'#title' => t('Term edit'),
'#tree' => TRUE,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight'=>1,
// '#group'=>'additional_settings',
'#prefix' => $visible ? null : '<div style="display:none;">',
'#suffix' => $visible ? null : '</div>',
);
$form[$prefix] += $term_form;
// $form['tode_termform'] = array('#type' => 'hidden', '#value' => 'true','#delta' => $delta,);
}
}
/**
* Form element validate handler for tode parent term autocomplete element.
*/
function tode_parent_autocomplete_validate($element, &$form_state) {
// dsm('- - - - tode_autocomplete_validate');
// dsm($element, '$element');
// dsm($form_state, '$form_state');
$value = array();
if ($typed_term = $element['#value']) {
// Translate term names into actual terms.
// See if the term exists in the chosen vocabulary and return the tid;
// otherwise, set error.
if ($possibilities = taxonomy_term_load_multiple(array(), array('name' => trim($typed_term), 'vid' => $form_state['values']['tode_vid']))) {
$term = array_pop($possibilities);
$value = (array)$term;
}
else {
form_error($element, t('Parent term can only be an existing term.'));
}
}
//
// dsm('form_set_value');
form_set_value($element, $value, $form_state);
}
/**
* Validation function for the tode element
*
* parses input and sets the values as needed (tid) for storing the data
*/
function tode_widget_validate($element, &$form_state){
// dsm('- - - - tode_widget_validate');
// dsm($form_state, 'form_state');
// dsm($element, 'element');
$node = $form_state['node'];
$value = array();
if ($typed_term = $element['#value']) {
$field = field_widget_field($element, $form_state);
// dsm($field, 'field');
$vocabularies = array();
foreach ($field['settings']['allowed_values'] as $tree) {
if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) {
$vocabularies[$vocabulary->vid] = $vocabulary;
}
}
// get the parent term tid or 0 (no parents)
$parent_tid = isset($form_state['values']['tode_parent_term']['tid']) ? $form_state['values']['tode_parent_term']['tid'] : 0;
// See if the term already exists and load the term
// otherwise, create a new 'autocreate' term for insert.
if($tid = $form_state['values']['tode_tid']){
$term = taxonomy_term_load($tid);
$term->name = $typed_term;
$term->parent = $parent_tid;
}else{
$vocabulary = reset($vocabularies);
$term = (object)array(
'tid' => 'autocreate', // autocreate not needed with direct taxonomy_term_save [EDIT] autocreate needed because of the hook_submit insted of hook_validate
'vid' => $vocabulary->vid,
'name' => $typed_term,
'vocabulary_machine_name' => $vocabulary->machine_name,
'parent' => $parent_tid,
);
// taxonomy_term_save($term); // save here the new term to directly get the tid on hook_node_validate
// [EDIT] do not save the term here because it will be save even if node form is not validate
// results term without node or mutiple orfan term
// moving all process on node submit
}
// dsm($term, '$term');
$value = (array)$term;
}
// dsm($value, '$value');
form_set_value($element, $value, $form_state);
}
/**
* Implements hook_field_widget_error().
*/
function tode_field_widget_error($element, $error, $form, &$form_state) {
# use this to set errors
form_error($element['value'], $error['message']);
}
/**
* Implements hook_node_submit().
*/
function tode_node_submit($node, $form, &$form_state) {
// dsm('- - - tode_node_submit');
// dsm($node, '$node');
// dsm($form, '$form');
// dsm($form_state, '$form_state');
module_load_include('inc', 'taxonomy', 'taxonomy.admin');
// module_load_include('inc', 'i18n_string', 'i18n_string.pages');
//
$tode_fields = _tode_get_tode_fields_def($node);
// dsm($tode_fields, '$tode_fields');
if(!count($tode_fields))
return;
$language = $node->language;
$default_language = language_default('language');
// dsm($default_language, '$default_language');
foreach ($tode_fields as $field_name => $field) {
// retreive the prefixed termfom values (hidden or visible)
$prefix = 'tode_termform_'.$field_name;
// if term_form is not available
// it meens that we are on the creation of a node
// hook_node_presave will handle this case
if( !isset($form_state['values'][$prefix]) )
continue;
// else
// we are on the update or on the translation (from initial node)
// so we can go forward
// retreive the initial tode_field language
$init_language = $form[$field_name]['#language'];
// retreive the value of term field, to get the typed term name
$tode_field_term_value = $form_state['values'][$field_name][$init_language][0];
// dsm($tode_field_term_value, '$tode_field_term_value');
$values = _tode_prefix_form($form_state['values'][$prefix], $prefix.'_', FALSE);
// dsm($values, 'values');
if(!module_exists('i18n_taxonomy') || $language == 'und' || $language == $default_language){
// define the form_state for term_form submit
$new_term_form_state = array(
'build_info'=>array(
'args'=>array(0=>(object)$tode_field_term_value),
),
"values"=>array(
'name'=> $tode_field_term_value['name'], // replace the original (hidden) term name value by the typed in the the entity field
'op'=> t('Save'),
)
);
// add new values to form_state
$new_term_form_state['values'] += $values;
// dsm($new_term_form_state, 'form_state');
drupal_form_submit('taxonomy_form_term', $new_term_form_state);
}else{
$context= array('term',$values['tid'],'name');
i18n_string_textgroup('taxonomy')->update_translation($context, $language, $tode_field_term_value['name']);
}
}
}
/**
* Implements hook_node_presave().
*/
function tode_node_presave($node) {
// dsm('- - - tode_node_presave');
// dsm($node, 'node');
if($node->nid)
return;
$tode_fields = _tode_get_tode_fields_def($node);
if(!count($tode_fields))
return;
$default_language = language_default('language');
// purpose of that is to directly atribute the right language to the term
foreach ($tode_fields as $field_name => $field){
$tode_field = $node->$field_name;
$tode_field_term = $tode_field[$node->language][0]; // on node creation field language is always to und (sure ?)
// // test the language, if not default language create the term name translation
if( module_exists('i18n_taxonomy') && ( $node->language != 'und' || $node->language != $default_language ) ){
$context= array('term',$tode_field_term['tid'],'name');
i18n_string_textgroup('taxonomy')->update_translation($context, $node->language, $tode_field_term['name']);
}
}
}
/*
TODO Sélectionner une traduction pour test tode fr
merge two terms when translation is made by selecting a node whiche already exists
*/
/**
* Implementation of hook_form_alter().
*
* node deletion to delete also the tode term
*
*/
function tode_form_alter(&$form, $form_state, $form_id){
/*
TODO block the deletion if tode term has children !! because this will delete them to …
*/
if (stripos($form_id, 'node_delete_confirm') !== false){
// dsm($form_id, 'tode form_alter form_id');
_tode_node_delete_form_alter($form, $form_state);
// dsm($form);
}else if(stripos($form_id, 'node_admin_content') !== false){
if(isset($form['operation']) && $form['operation']['#value'] == 'delete'){
// dsm($form, 'node_admin_content form');
// dsm($form_state, 'form_state');
_tode_nodes_delete_form_alter($form, $form_state);
}
}
}
function _tode_node_delete_form_alter(&$form, $form_state){
// dsm($form, '_tode_node_delete_form_alter : form');
// get the node
$node = $form['#node'];
// dsm($node, '$node');
#get the fields defenition of node type
$tode_fields = _tode_get_tode_fields_def($node);
// dsm($tode_fields);
if(count($tode_fields) == 0)
return;
#get the terms value
$terms = array('names'=>array(), 'tids'=>array());
foreach ($tode_fields as $field_name => $field)
_tode_populate_terms_node_delete($terms, $node->$field_name);
_tode_node_delete_prepare_form($form, $terms);
}
function _tode_nodes_delete_form_alter(&$form, $form_state){
// dsm($form, '_tode_nodes_delete_form_alter : form');
$nodes = array();
foreach ($form_state['values']['nodes'] as $nid => $actif)
if($actif)
$nodes[] = node_load($nid);
#get the terms value
$terms = array('names'=>array(), 'tids'=>array());
foreach ($nodes as $node) {
#get the fields definition of node type
$tode_fields = _tode_get_tode_fields_def($node);
//dsm($tode_fields);
if(count($tode_fields) == 0)
continue;
foreach ($tode_fields as $field_name => $field)
_tode_populate_terms_node_delete($terms, $node->$field_name);
}
_tode_node_delete_prepare_form($form, $terms);
}
function _tode_populate_terms_node_delete(&$terms, $tode_field){
foreach ($tode_field as $language) {
foreach ($language as $term) {
$term = taxonomy_term_load($term['tid']);
if(!in_array($term->tid, $terms['tids'])){
$terms['names'][] = $term->name;
$terms['tids'][] = $term->tid;
}
}
}
}
function _tode_node_delete_prepare_form(&$form, $terms){
if(count($terms)){
/*
TODO add here a checkbox to select terms to delete
*/
#add some warning in form description
$form['description']['#markup'] .= '<br />'.t('this will also delete taxonomy terms : %terms', array('%terms'=>implode(', ', $terms['names'])));
$form['tode_delete'] = array( '#type' => 'hidden', '#value' => serialize($terms['tids']),);
$form['tode_terms'] = array('#type' => 'hidden', '#value' => serialize($terms['names']),);
$form['#submit'][] = 'tode_delete_submit';
}
}
function tode_delete_submit($form, &$form_state){
$tids = unserialize($form['tode_delete']['#value']);
foreach ($tids as $tid)
taxonomy_term_delete($tid);
$terms = unserialize($form['tode_terms']['#value']);
drupal_set_message(t('Following Taxonomy terms have been deleted : %terms', array('%terms' => implode(', ', $terms) )), 'status');
}
/**
* HELPERS
*/
function _tode_clean_form($form, $level = 0){
foreach ($form as $key => $value) {
if(strpos($key,'#') !== false || $key == 'form_build_id' || $key == 'form_id' || $key == 'form_token'){
if( $level == 0 || $key == "#element_validate")
unset($form[$key]);
}elseif(is_array($value)){
$form[$key] = _tode_clean_form($value, $level+1);
}
}
return $form;
}
function _tode_prefix_form($form, $prefix = '', $add = TRUE){
foreach ($form as $key => $value) {
if(strpos($key,'#') === false){
if((isset($value['#type']) && $value['#type'] == 'fieldset') || (!$add && is_array($value)))
$value = _tode_prefix_form($value, $prefix, $add);
if($add){
$form[$prefix.$key] = $value;
unset($form[$key]);
}elseif(strpos($key, $prefix) !== false ){
$form[str_replace($prefix, '', $key)] = $value;
unset($form[$key]);
}
}
}
return $form;
}
/**
* _tode_term_form($tid)
*
*/
function _tode_term_form($term){
// dsm('_tode_term_form');
if ($term) {
$form_state = array(
'build_info'=>array(
'args'=>array(0=>$term)
),
'method'=>'post',
);
// function taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary = NULL) {
$term_form = drupal_retrieve_form('taxonomy_form_term', $form_state);
drupal_prepare_form('taxonomy_form_term', $term_form, $form_state);
return $term_form;
}else{
return false;
}
}
/**
* _tode_trim_options(&$form, $element)
*
*/
function _tode_trim_options(&$form, $item){
foreach ($form[$item] as $field_name => $field) {
if(((is_array($field)) && $field['#type'] == 'select') && $field['#multiple']){
$options = $field['#options'];
for ($i=0; $i < count($options); $i++) {
if(!isset($options[$i]->option))
continue;
$op = array();
foreach ($options[$i]->option as $key => $value)
$op[$key] = strlen($value) > 25 ? substr_replace ($value, ' [...] ', 15, -10) : $value; // affiche 'abc...xyz'
$options[$i]->option = $op;
}
$field['#options'] = $options;
$form[$item][$field_name] = $field;
}
}
}
/**
* OK OK OK
*/
function _tode_get_tode_fields_def($node){
// dsm($node, '_tode_get_fields_def');
#get the fields defenition of node type
$type_fields = field_info_instances('node');
// dsm($type_fields, 'type_fields definition');
#get the tode node fields
$tode_fields = array();
foreach ($type_fields[$node->type] as $field_name => $field) {
if($field['widget']['type'] == 'tode')
$tode_fields[$field_name] = $field;
}
return $tode_fields;
}