migrate_materio.materiau.inc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * MaterioMateriauNodeMigration
  4. *
  5. */
  6. class MaterioMateriauNodeMigration extends MaterioBasicMigration {
  7. public function __construct() {
  8. parent::__construct();
  9. $this->description = t('Migrate Materio Materiau nodes');
  10. // provide better description for source fields
  11. // and add new field source not from sql
  12. $source_fields = array(
  13. 'id_product' => t('Materiau id from source')
  14. );
  15. $query = db_select(MIG_MAT_SRC_DB .'.product_id', 'prod_id');
  16. // WARNING ! product_info is double langauge + duplicate -> 4 rows each product
  17. $query->join(MIG_MAT_SRC_DB .'.product_info', 'prod_info', 'prod_id.id_product = prod_info.id_product');
  18. $query
  19. ->fields('pod_id', array('id_product', 'id_materio', 'status', 'temp_flag', 'sample_status', 'memo', 'source', 'date_creation', 'date_modif'))
  20. ->fields('prod_info', array('name', 'nature', 'description', 'usage', 'technical', 'keywords'))
  21. ->orderBy('id_product', 'DESC');
  22. $query->groupBy('prod_id.id_product');
  23. $this->source = new MigrateSourceSQL($query, $source_fields);
  24. $this->destination = new MigrateDestinationNode('materiau');
  25. $this->map = new MigrateSQLMap($this->machineName,
  26. array(
  27. 'id_product' => array(
  28. 'type' => 'int',
  29. 'unsigned' => TRUE,
  30. 'not null' => TRUE,
  31. 'description' => 'OLD Unique Materiau ID',
  32. 'alias' => 'prod_id',
  33. )
  34. ),
  35. MigrateDestinationNode::getKeySchema()
  36. );
  37. $this->addFieldMapping('is_new')->defaultValue(TRUE);
  38. $this->addFieldMapping('created', 'date_creation');
  39. $this->addFieldMapping('changed', 'date_modif');
  40. $this->addFieldMapping('status')->defaultValue(1);
  41. $this->addFieldMapping('promote')->defaultValue(0);
  42. $this->addFieldMapping('sticky')->defaultValue(0);
  43. $this->addFieldMapping('title', 'name');
  44. $this->addFieldMapping('field_memo', 'memo');
  45. /*
  46. TODO translate node
  47. */
  48. //$this->addFieldMapping('language');
  49. //$this->addFieldMapping('field_nature_titre', 'nature');
  50. }
  51. }