1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Migrations for Editorial Nodes. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
class DFSMEDEditorialNodes extends DemoFrameworkBaseNodesUUID { |
9
|
|
|
public function __construct($arguments) { |
10
|
|
|
parent::__construct($arguments); |
11
|
|
|
$this->description = t('Import nodes.'); |
12
|
|
|
$this->map = new MigrateSQLMap($this->machineName, |
13
|
|
|
array( |
14
|
|
|
'uuid' => array( |
15
|
|
|
'type' => 'char', |
16
|
|
|
'length' => 36, |
17
|
|
|
'not null' => FALSE, |
18
|
|
|
), |
19
|
|
|
), |
20
|
|
|
MigrateDestinationNode::getKeySchema() |
21
|
|
|
); |
22
|
|
|
$import_path = drupal_get_path('module', 'dfs_med') . '/import/'; |
23
|
|
|
// Create a MigrateSource object. |
24
|
|
|
$this->source = new MigrateSourceCSV($import_path . 'dfs_med.nodes.article.csv', $this->csvcolumns(), array('header_rows' => 1)); |
25
|
|
|
$this->destination = new MigrateDestinationNode('article'); |
26
|
|
|
// Override body:format |
27
|
|
|
$this->addFieldMapping('body:format')->defaultValue('full_html'); |
28
|
|
|
// Created |
29
|
|
|
$this->addFieldMapping('created', 'created')->defaultValue(strtotime("now")); |
30
|
|
|
// Image |
31
|
|
|
$this->addFieldMapping('field_image', 'image'); |
32
|
|
|
$this->addFieldMapping('field_image:file_replace')->defaultValue(FILE_EXISTS_REPLACE); |
33
|
|
|
$this->addFieldMapping('field_image:source_dir')->defaultValue($import_path . 'images'); |
34
|
|
|
$this->addFieldMapping('field_image:destination_file', 'filename'); |
35
|
|
|
// Headlines |
36
|
|
|
$this->addfieldmapping('field_headline', 'headlines'); |
37
|
|
|
// Persona |
38
|
|
|
$this->addFieldMapping('field_persona', 'persona'); |
39
|
|
|
// Site Section |
40
|
|
|
$this->addFieldMapping('field_site_section', 'site_section')->defaultValue("Content"); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function csvcolumns() { |
|
|
|
|
44
|
|
|
$columns[0] = array('uuid', 'UUID'); |
|
|
|
|
45
|
|
|
$columns[1] = array('title', 'Title'); |
46
|
|
|
$columns[2] = array('image', 'Image'); |
47
|
|
|
$columns[3] = array('body', 'Body'); |
48
|
|
|
$columns[4] = array('headlines', 'Headlines'); |
49
|
|
|
$columns[5] = array('persona', 'Persona'); |
50
|
|
|
return $columns; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function prepareRow($row) { |
54
|
|
|
$row->headlines = explode(", ", $row->headlines); |
55
|
|
|
return TRUE; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
class DFSMEDEditorialComments extends ImportBaseComments { |
61
|
|
|
|
62
|
|
View Code Duplication |
public function __construct($arguments) { |
|
|
|
|
63
|
|
|
parent::__construct($arguments); |
64
|
|
|
$this->description = t('Import comments.'); |
65
|
|
|
// Create a map object for tracking the relationships between source rows |
66
|
|
|
$this->map = new MigrateSQLMap($this->machineName, |
67
|
|
|
array( |
68
|
|
|
'subject' => array( |
69
|
|
|
'type' => 'varchar', |
70
|
|
|
'length' => 255, |
71
|
|
|
'not null' => TRUE, |
72
|
|
|
), |
73
|
|
|
), |
74
|
|
|
MigrateDestinationComment::getKeySchema() |
75
|
|
|
); |
76
|
|
|
$import_path = drupal_get_path('module', 'dfs_med') . '/import/'; |
77
|
|
|
$this->source = new MigrateSourceCSV($import_path . 'dfs_med.comments.article.csv', $this->csvcolumns(), array('header_rows' => 1)); |
78
|
|
|
$this->destination = new MigrateDestinationComment('comment_node_article'); |
79
|
|
|
$this->addFieldMapping('nid', 'node')->sourceMigration('DFSMEDEditorialNodes'); |
80
|
|
|
$this->addFieldMapping('uid', 'author')->sourceMigration('DFSMEDUsers'); |
81
|
|
|
$this->addFieldMapping('created', 'created'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
function csvcolumns() { |
|
|
|
|
85
|
|
|
$columns[0] = array('subject', 'Subject'); |
|
|
|
|
86
|
|
|
$columns[1] = array('node', 'Node'); |
87
|
|
|
$columns[2] = array('author', 'Author'); |
88
|
|
|
$columns[3] = array('body', 'Body'); |
89
|
|
|
$columns[4] = array('created', 'Created'); |
90
|
|
|
return $columns; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.