1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Migrations for WEM Contest Nodes. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
class DFSWEMContestNodes extends DemoFrameworkBaseNodesUUID { |
9
|
|
|
|
10
|
|
|
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_contest.csv', $this->csvcolumns(), array('header_rows' => 1)); |
16
|
|
|
$this->destination = new MigrateDestinationNode('wem_contest'); |
17
|
|
|
// Image |
18
|
|
|
$this->addFieldMapping('field_contest_image', 'image'); |
19
|
|
|
$this->addFieldMapping('field_contest_image:file_replace')->defaultValue(FILE_EXISTS_REPLACE); |
20
|
|
|
$this->addFieldMapping('field_contest_image:source_dir')->defaultValue($import_path . 'images'); |
21
|
|
|
$this->addFieldMapping('field_contest_image:destination_file', 'filename'); |
22
|
|
|
// Taxonomy |
23
|
|
|
$this->addFieldMapping('field_contest_interests', 'interests'); |
24
|
|
|
// Persona |
25
|
|
|
$this->addFieldMapping('field_persona', 'persona'); |
26
|
|
|
// Site Section |
27
|
|
|
$this->addFieldMapping('field_site_section', 'site_section')->defaultValue("Community"); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
View Code Duplication |
function csvcolumns() { |
|
|
|
|
31
|
|
|
$columns[0] = array('title', 'Title'); |
|
|
|
|
32
|
|
|
$columns[1] = array('body', 'Body'); |
33
|
|
|
$columns[2] = array('image', 'Image'); |
34
|
|
|
$columns[3] = array('interests', 'Interests'); |
35
|
|
|
$columns[4] = array('uuid', 'UUID'); |
36
|
|
|
$columns[5] = array('created', 'Created'); |
37
|
|
|
$columns[6] = array('persona', 'Persona'); |
38
|
|
|
return $columns; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
function prepareRow($row) { |
|
|
|
|
42
|
|
|
$row->interests = explode(", ", $row->interests); |
43
|
|
|
return TRUE; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
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.