This repository has been archived by the owner on May 2, 2018. It is now read-only.
forked from vejlebib/migrate_ding1_ding2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookmark.inc
103 lines (86 loc) · 3.5 KB
/
bookmark.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* Common mappings for flag migrations.
*/
abstract class DingFlagMigration extends Migration {
public function __construct($arguments) {
parent::__construct($arguments);
// With migrate_ui enabled, migration pages will indicate people involved in
// the particular migration, with their role and contact info. We default the
// list in the shared class; it can be overridden for specific migrations.
$this->team = array(
new MigrateTeamMember('Ewan Andreasen', '[email protected]', t('Webdeveloper (Ding1 -> Ding2 Migration)')),
);
$this->description = $arguments['description'];
$this->dependencies = $arguments['dependencies'];
$this->sourceConnection = 'legacy';
$this->machine_name = $arguments['machine_name'];
$this->source_table = $arguments['source_table'];
$this->destination_fid = $arguments['destination_fid'];
$this->source_key = $arguments['source_key'];
$this->source = new MigrateSourceSQL($this->query(), array(), NULL, array('map_joinable' => FALSE));
$this->destination = new MigrateDestinationFlagSimple($this->destination_fid);
$this->map = new MigrateSQLMap(
$this->machineName,
$this->source_key,
MigrateDestinationFlagSimple::getKeySchema()
);
}
protected function query() {
$query = Database::getConnection('default', $this->sourceConnection)
->select($this->source_table, 't')
->fields('t');
return $query;
}
}
class DingBookmarkMigration extends DingFlagMigration {
public function __construct($arguments) {
// "bookmark" flags in ding2 has fid = 2
$bookmark_fid = 2;
$arguments = array(
'description' => t('Migration of ding_cart table from Ding1/D6 into D7 bookmark flags (ding_bookmark)'),
'machine_name' => 'DingBookmark',
'group_name' => 'ding1_group',
'source_table' => 'ding_cart',
'destination_fid' => $bookmark_fid,
'dependencies' => array('DingUser'),
'source_key' => array(
'uid' => array(
'description' => t('{users}.uid for user'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'local_id' => array(
'description' => t('Local ID in Ting lingo.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
),
);
parent::__construct($arguments);
$this->addFieldMapping('uid', 'uid')
->sourceMigration('DingUser');
$this->addFieldMapping('fid')
->defaultValue($bookmark_fid)
->description(t('hardcoded to 2, the assigned value of bookmark flags in ding2'));
$this->addFieldMapping('content_type')
->defaultValue('ding_entity');
$this->addFieldMapping('content_id', 'ting_id')
->description(t('Handled in prepareRow function'));
$this->addFieldMapping('timestamp', 'created');
// Unmapped source fields
$this->addUnmigratedSources(array('title', 'author', 'type', 'thumbnail_url'));
// Unmapped destination fields
//$this->addUnmigratedDestinations(array('category_tid'));
}
public function prepareRow($row) {
// Always include this snippet, in case our parent class decides to ignore the row
if (parent::prepareRow($row) === FALSE) {
return FALSE;
}
// we populate the ting_object table during migrating and replace ting_id with tid from ting_object_table
$row->ting_id = migrate_ding1_ding2_add_ting_object($row->ting_id);
}
}