Issue #1945294 by naught101, mikran: Fixed Minimum & maximum arity settings are not...
[project/relation.git] / relation_migrate / relation_migrate.migration.inc
1 <?php
2
3 /**
4 * @file
5 * Migration for entityreference fields.
6 */
7
8 abstract class RelationMigrateReference extends Migration {
9
10 /**
11 * Constructor.
12 *
13 * @param $field_type Field type machine name.
14 */
15 public function __construct($field_type) {
16 parent::__construct();
17 $this->fields = array_filter(variable_get('relation_migrate_' . $field_type . '_fields', array()));
18 $this->relation_type = variable_get('relation_migrate_' . $field_type . '_relation_type', NULL);
19 $this->dependencies = array();
20 $this->description = 'Copy the contents from the ' . $field_type . ' fields to relation entities.';
21 $this->map = new MigrateSQLMap($this->machineName,
22 array(
23 'source_type' => array(
24 'type' => 'varchar',
25 'length' => 128,
26 'not null' => TRUE,
27 ),
28 'source_id' => array(
29 'type' => 'int',
30 'unsigned' => TRUE,
31 'not null' => TRUE,
32 ),
33 'destination_type' => array(
34 'type' => 'varchar',
35 'length' => 128,
36 'not null' => TRUE,
37 ),
38 'destination_id' => array(
39 'type' => 'int',
40 'unsigned' => TRUE,
41 'not null' => TRUE,
42 ),
43 'delta' => array(
44 'type' => 'int',
45 'unsigned' => TRUE,
46 'not null' => TRUE,
47 ),
48 ),
49 MigrateDestinationRelation::getKeySchema()
50 );
51
52 $this->destination = new MigrateDestinationRelation($this->relation_type);
53
54 $this->addFieldMapping('uid')->defaultValue(variable_get('relation_migrate_' . $field_type . '_user', 1))->description(t('The owner of relation.'));
55 }
56
57 public function prepare(stdClass $relation, stdClass $source_row) {
58 $relation->endpoints[LANGUAGE_NONE] = array(
59 array('entity_type' => $source_row->source_type, 'entity_id' => $source_row->source_id),
60 array('entity_type' => $source_row->destination_type, 'entity_id' => $source_row->destination_id),
61 );
62 }
63 }
64
65 class RelationMigrateEntityReference extends RelationMigrateReference {
66 public function __construct() {
67 parent::__construct('entityreference');
68 $this->source = new MigrateSourceEntityReference($this->fields);
69 }
70 }
71
72 class RelationMigrateNodeReference extends RelationMigrateReference {
73 public function __construct() {
74 parent::__construct('node_reference');
75 $this->source = new MigrateSourceNodeReference($this->fields);
76 }
77 }
78
79 class RelationMigrateUserReference extends RelationMigrateReference {
80 public function __construct() {
81 parent::__construct('user_reference');
82 $this->source = new MigrateSourceUserReference($this->fields);
83 }
84 }
85
86 class RelationMigrateTermReference extends RelationMigrateReference {
87 public function __construct() {
88 parent::__construct('taxonomy_term_reference');
89 $this->source = new MigrateSourceTermReference($this->fields);
90 }
91 }
92