|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @file |
|
5
|
|
|
* Migrations for WEM News Nodes. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
class DFSWEMNewsNodes extends DemoFrameworkBaseNodesUUID { |
|
9
|
|
|
|
|
10
|
|
View Code Duplication |
public function __construct($arguments) { |
|
|
|
|
|
|
11
|
|
|
parent::__construct($arguments); |
|
12
|
|
|
$this->description = t('Import nodes.'); |
|
13
|
|
|
$import_path = drupal_get_path('module', 'dfs_wem') . '/import/'; |
|
14
|
|
|
// Create a MigrateSource object. |
|
15
|
|
|
$this->source = new MigrateSourceCSV($import_path . 'dfs_wem.nodes.wem_news.csv', $this->csvcolumns(), array('header_rows' => 1)); |
|
16
|
|
|
$this->destination = new MigrateDestinationNode('wem_news'); |
|
17
|
|
|
// Image |
|
18
|
|
|
$this->addFieldMapping('field_wem_image', 'image'); |
|
19
|
|
|
$this->addFieldMapping('field_wem_image:file_replace')->defaultValue(FILE_EXISTS_REPLACE); |
|
20
|
|
|
$this->addFieldMapping('field_wem_image:source_dir')->defaultValue($import_path . 'images'); |
|
21
|
|
|
$this->addFieldMapping('field_wem_image:destination_file', 'filename'); |
|
22
|
|
|
// Video |
|
23
|
|
|
$this->addFieldMapping('field_wem_video', 'video')->sourceMigration('DFSWEMNewsVideo'); |
|
24
|
|
|
$this->addFieldMapping('field_wem_video:file_class')->defaultValue('MigrateFileFid'); |
|
25
|
|
|
// Taxonomy |
|
26
|
|
|
$this->addFieldMapping('field_wem_interests', 'interests'); |
|
27
|
|
|
// Persona |
|
28
|
|
|
$this->addFieldMapping('field_persona', 'persona'); |
|
29
|
|
|
// Site Section |
|
30
|
|
|
$this->addFieldMapping('field_site_section', 'site_section')->defaultValue("Content"); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
function csvcolumns() { |
|
|
|
|
|
|
34
|
|
|
$columns[0] = array('title', 'Title'); |
|
|
|
|
|
|
35
|
|
|
$columns[1] = array('body', 'Body'); |
|
36
|
|
|
$columns[2] = array('image', 'Image'); |
|
37
|
|
|
$columns[3] = array('video', 'Video'); |
|
38
|
|
|
$columns[4] = array('interests', 'Interests'); |
|
39
|
|
|
$columns[5] = array('uuid', 'UUID'); |
|
40
|
|
|
$columns[6] = array('created', 'Created'); |
|
41
|
|
|
$columns[7] = array('persona', 'Persona'); |
|
42
|
|
|
return $columns; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
function prepareRow($row) { |
|
|
|
|
|
|
46
|
|
|
$row->interests = explode(", ", $row->interests); |
|
47
|
|
|
return TRUE; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
View Code Duplication |
class DFSWEMNewsVideo extends Migration { |
|
|
|
|
|
|
53
|
|
|
public function __construct($arguments) { |
|
54
|
|
|
parent::__construct($arguments); |
|
55
|
|
|
$this->map = new MigrateSQLMap($this->machineName, |
|
56
|
|
|
array( |
|
57
|
|
|
'video' => array( |
|
58
|
|
|
'type' => 'varchar', |
|
59
|
|
|
'length' => 255, |
|
60
|
|
|
'not null' => TRUE, |
|
61
|
|
|
), |
|
62
|
|
|
), |
|
63
|
|
|
MigrateDestinationFile::getKeySchema() |
|
64
|
|
|
); |
|
65
|
|
|
$this->destination = new MigrateDestinationFile('video', 'MigrateExtrasFileYoutube'); |
|
66
|
|
|
$import_path = drupal_get_path('module', 'dfs_wem') . '/import/'; |
|
67
|
|
|
$this->source = new MigrateSourceCSV($import_path . 'dfs_wem.nodes.wem_news.csv', $this->csvcolumns(), array('header_rows' => 1)); |
|
68
|
|
|
$this->addFieldMapping('value', 'video'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
function csvcolumns() { |
|
|
|
|
|
|
72
|
|
|
$columns[3] = array('video', 'Video'); |
|
|
|
|
|
|
73
|
|
|
return $columns; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.