1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Migrations for WEM Contest Nodes Translations. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
class DFSWEMContestNodesTranslations extends DemoFrameworkBaseNodesTranslations { |
9
|
|
|
|
10
|
|
|
public function __construct($arguments) { |
11
|
|
|
parent::__construct($arguments); |
12
|
|
|
$this->description = t('Import translated 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.translations.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
|
|
|
// Workbench |
25
|
|
|
$this->addFieldMapping('workbench_moderation_state_new', 'workbench_moderation_state_new')->defaultValue('published'); |
26
|
|
|
// Translations |
27
|
|
|
$this->addFieldMapping('title', 'translated_title'); |
28
|
|
|
$this->addFieldMapping('tnid', 'title')->sourceMigration('DFSWEMContestNodes'); |
29
|
|
|
// UUID |
30
|
|
|
$this->addFieldMapping('uuid', 'uuid'); |
31
|
|
|
// Created |
32
|
|
|
$this->addFieldMapping('created', 'created')->defaultValue(strtotime("now")); |
33
|
|
|
// Persona |
34
|
|
|
$this->addFieldMapping('field_persona', 'persona'); |
35
|
|
|
// Site Section |
36
|
|
|
$this->addFieldMapping('field_site_section', 'site_section')->defaultValue("Community"); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
View Code Duplication |
function csvcolumns() { |
|
|
|
|
40
|
|
|
$columns[0] = array('title', 'Source Title'); |
|
|
|
|
41
|
|
|
$columns[1] = array('language', 'Language'); |
42
|
|
|
$columns[2] = array('translated_title', 'Title'); |
43
|
|
|
$columns[3] = array('body', 'Body'); |
44
|
|
|
$columns[4] = array('image', 'Image'); |
45
|
|
|
$columns[5] = array('interests', 'Interests'); |
46
|
|
|
$columns[6] = array('uuid', 'UUID'); |
47
|
|
|
$columns[7] = array('created', 'Created'); |
48
|
|
|
$columns[8] = array('persona', 'Persona'); |
49
|
|
|
return $columns; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
function prepareRow($row) { |
|
|
|
|
53
|
|
|
$row->interests = explode(", ", $row->interests); |
54
|
|
|
return TRUE; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
function prepare(&$node, $row) { |
|
|
|
|
58
|
|
|
if (isset($node->tnid) && ($source = node_load($node->tnid))) { |
59
|
|
|
$node->translation_source = $source; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
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.