Guest User

Untitled

a guest
May 27th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. class IntervenantMigration extends Migration {
  2. public function __construct() {
  3. parent::__construct();
  4.  
  5. $import_path = variable_get('df_import_path','/home/dev/dalloz/dallozformation/ftp/');
  6.  
  7. //On ne definie pas les columns on se base sur les intitulés de la premiere colonne
  8. $columns = array();
  9.  
  10. $this->source = new MigrateSourceCSV($import_path.'intervenants.csv', $columns, array('header_rows' => 1));
  11.  
  12. $this->destination = new MigrateDestinationNode('df_intervenant');
  13. $this->map = new MigrateSQLMap(
  14. $this->machineName,
  15. array(
  16. 'NumIntervenant' => array(
  17. 'type' => 'varchar',
  18. 'length' => 255,
  19. 'size' => 'normal'
  20. )
  21. ),
  22. MigrateDestinationNode::getKeySchema()
  23. );
  24.  
  25. $this->addFieldMapping('field_intervenant_num', 'NumIntervenant');
  26. $this->addFieldMapping('field_intervenant_nom', 'NomIntervenant');
  27. $this->addFieldMapping('field_intervenant_prenom', 'PrenomIntervenant');
  28. $this->addFieldMapping('field_intervenant_qualite', 'Qualite');
  29. $this->addFieldMapping('field_intervenant_civilite', 'NumTitre');
  30. }
  31.  
  32. //Permet de faire des traitements sur les donnés recup depuis le csv
  33. public function prepareRow($values) {
  34.  
  35. //Si pas de nom on insere pas l'intervenant
  36. if($values->NomIntervenant == '') {
  37. // dsm($values);
  38. // $this->saveMessage("L'intervenant ".$values->NumIntervenant." n'a pas été importé car son nom n'est pas rempli", MIGRATION::MESSAGE_NOTICE);
  39. // watchdog('debug import', print_r($values, TRUE));
  40. $this->saveMessage("L'intervenant ".$values->NumIntervenant." n'a pas été importé car son nom n'est pas rempli");
  41. return FALSE;
  42. }
  43. else {
  44. //On met le civilité à NULL si non rempli
  45. if(!$values->NumTitre) {
  46. $values->NumTitre = NULL;
  47. }
  48. }
  49. }
  50.  
  51. //Permet de faire des traitements sur le node juste avant qu il ne soit save
  52. // public function prepare($entity, $row) {
  53. // }
  54.  
  55. }
Add Comment
Please, Sign In to add comment