1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Migrations for Episode Nodes. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
class DFSMEDEpisodeNodes extends DemoFrameworkBaseNodesUUID { |
9
|
|
|
|
10
|
|
|
public function __construct($arguments) { |
11
|
|
|
parent::__construct($arguments); |
12
|
|
|
$this->description = t('Import nodes.'); |
13
|
|
|
|
14
|
|
|
$this->map = new MigrateSQLMap($this->machineName, |
15
|
|
|
array( |
16
|
|
|
'uuid' => array( |
17
|
|
|
'type' => 'char', |
18
|
|
|
'length' => 36, |
19
|
|
|
'not null' => FALSE, |
20
|
|
|
), |
21
|
|
|
), |
22
|
|
|
MigrateDestinationNode::getKeySchema() |
23
|
|
|
); |
24
|
|
|
|
25
|
|
|
$import_path = drupal_get_path('module', 'dfs_med') . '/import/'; |
26
|
|
|
|
27
|
|
|
// Create a MigrateSource object. |
28
|
|
|
$this->source = new MigrateSourceCSV($import_path . 'dfs_med.nodes.episode.csv', $this->csvcolumns(), array('header_rows' => 1)); |
29
|
|
|
$this->destination = new MigrateDestinationNode('episode'); |
30
|
|
|
|
31
|
|
|
// Created |
32
|
|
|
$this->addFieldMapping('created', 'created')->defaultValue(strtotime("now")); |
33
|
|
|
|
34
|
|
|
// Splash Image |
35
|
|
|
$this->addFieldMapping('field_splash_image', 'splash'); |
36
|
|
|
$this->addFieldMapping('field_splash_image:file_replace')->defaultValue(FILE_EXISTS_REPLACE); |
37
|
|
|
$this->addFieldMapping('field_splash_image:source_dir')->defaultValue($import_path . 'images'); |
38
|
|
|
$this->addFieldMapping('field_splash_image:destination_file', 'filename'); |
39
|
|
|
|
40
|
|
|
// Metadata |
41
|
|
|
$this->addfieldmapping('field_author', 'author'); |
42
|
|
|
$this->addfieldmapping('field_length', 'length'); |
43
|
|
|
$this->addfieldmapping('field_guidance', 'guidance'); |
44
|
|
|
|
45
|
|
|
// Text |
46
|
|
|
$this->addFieldMapping('field_quote', 'quote'); |
47
|
|
|
$this->addFieldMapping('field_quote:format')->defaultValue('filtered_html'); |
48
|
|
|
$this->addFieldMapping('field_quote_by', 'quote_by'); |
49
|
|
|
$this->addFieldMapping('field_supplemental', 'supplemental'); |
50
|
|
|
$this->addFieldMapping('field_supplemental:format')->defaultValue('filtered_html'); |
51
|
|
|
|
52
|
|
|
// Video |
53
|
|
|
$this->addFieldMapping('field_video', 'video')->sourceMigration('DFSMEDEpisodeVideo'); |
54
|
|
|
$this->addFieldMapping('field_video:file_class')->defaultValue('MigrateFileFid'); |
55
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
function csvcolumns() { |
|
|
|
|
59
|
|
|
$columns[0] = array('uuid', 'UUID'); |
|
|
|
|
60
|
|
|
$columns[1] = array('title', 'Title'); |
61
|
|
|
$columns[2] = array('splash', 'Image'); |
62
|
|
|
$columns[3] = array('body', 'Synopsis'); |
63
|
|
|
$columns[4] = array('author', 'Author'); |
64
|
|
|
$columns[5] = array('length', 'Duration'); |
65
|
|
|
$columns[6] = array('guidance', 'Guidance'); |
66
|
|
|
$columns[7] = array('quote', 'Quote'); |
67
|
|
|
$columns[8] = array('quote_by', 'Cited'); |
68
|
|
|
$columns[9] = array('supplemental', 'Supplemental'); |
69
|
|
|
$columns[10] = array('video', 'Video'); |
70
|
|
|
return $columns; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
View Code Duplication |
class DFSMEDEpisodeVideo extends Migration { |
|
|
|
|
76
|
|
|
public function __construct($arguments) { |
77
|
|
|
parent::__construct($arguments); |
78
|
|
|
$this->map = new MigrateSQLMap($this->machineName, |
79
|
|
|
array( |
80
|
|
|
'video' => array( |
81
|
|
|
'type' => 'varchar', |
82
|
|
|
'length' => 255, |
83
|
|
|
'not null' => TRUE, |
84
|
|
|
), |
85
|
|
|
), |
86
|
|
|
MigrateDestinationFile::getKeySchema() |
87
|
|
|
); |
88
|
|
|
$this->destination = new MigrateDestinationFile('video', 'MigrateExtrasFileYoutube'); |
89
|
|
|
$import_path = drupal_get_path('module', 'dfs_med') . '/import/'; |
90
|
|
|
$this->source = new MigrateSourceCSV($import_path . 'dfs_med.nodes.episode.csv', $this->csvcolumns(), array('header_rows' => 1)); |
91
|
|
|
$this->addFieldMapping('value', 'video'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
function csvcolumns() { |
|
|
|
|
95
|
|
|
$columns[10] = array('video', 'Video'); |
|
|
|
|
96
|
|
|
return $columns; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
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.