This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dkan_migrate_base_dataset.inc
86 lines (75 loc) · 2.17 KB
/
dkan_migrate_base_dataset.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
<?php
/**
* @file
* Migration Class for Datasets.
*/
/**
* Migrate CKAN dataset.
*/
class MigrateCkanDatasetBase extends MigrateCkanBase {
/**
* Here we go.
*/
public function __construct($arguments) {
parent::__construct($arguments);
$fields = $this->getCkanDatasetFields();
$list_url = isset($arguments['list_url']) ? $arguments['list_url'] : 'package_list';
$list_url = $this->endpoint . $list_url;
$item_url = isset($arguments['item_url']) ? $arguments['item_url'] : 'package_show?id=:id';
$item_url = $this->endpoint . $item_url;
$this->page = isset($arguments['page']) ? $arguments['page'] : '';
$this->offset = isset($arguments['offset']) ? $arguments['offset'] : '';
$this->ids = isset($arguments['ids']) ? $arguments['ids'] : '';
$this->highwaterField = array(
'name' => 'revision_timestamp',
);
$this->source = new MigrateSourceList(new CKANListJSON(
$list_url,
array('page' => $this->page,
'offset' => $this->offset,
'ids' => $this->ids,
)
),
new CKANItemJSON($item_url, $fields), $fields);
$this->map = new MigrateSQLMap(
$this->machineName,
array(
'uuid' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'id',
),
),
MigrateDestinationNode::getKeySchema()
);
$this->destination = new MigrateDestinationNode('dataset', array('text_format' => 'html'));
$this->addDefaultDatasetMappings();
}
/**
* Implements prepareRow.
*/
public function prepareRow($row) {
$this->datasetPrepareRow($row);
}
/**
* Implements prepare.
*/
public function prepare($node, $row) {
$this->datasetPrepare($node, $row);
}
/**
* Implements complete.
*/
public function complete($node, $row) {
if (isset($row->group_ids)) {
$node->og_group_ref = array(
LANGUAGE_NONE => array(),
);
foreach ($row->group_ids as $group) {
$node->og_group_ref[LANGUAGE_NONE][] = array('target_id' => $group);
}
}
node_save($node);
}
}