|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @file |
|
5
|
|
|
* Migrations for Slideshow Nodes. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
class DFSMEDSlideshowNodes extends DemoFrameworkBaseNodesUUID { |
|
9
|
|
View Code Duplication |
public function __construct($arguments) { |
|
|
|
|
|
|
10
|
|
|
parent::__construct($arguments); |
|
11
|
|
|
$this->description = t('Import nodes.'); |
|
12
|
|
|
$import_path = drupal_get_path('module', 'dfs_med') . '/import/'; |
|
13
|
|
|
// Create a MigrateSource object. |
|
14
|
|
|
$this->source = new MigrateSourceCSV($import_path . 'dfs_med.nodes.slideshow.csv', $this->csvcolumns(), array('header_rows' => 1)); |
|
15
|
|
|
$this->destination = new MigrateDestinationNode('slideshow_slide'); |
|
16
|
|
|
// Created |
|
17
|
|
|
$this->addFieldMapping('created', 'created')->defaultValue(strtotime("now")); |
|
18
|
|
|
// Main Image |
|
19
|
|
|
$this->addFieldMapping('field_main_image', 'image'); |
|
20
|
|
|
$this->addFieldMapping('field_main_image:file_replace')->defaultValue(FILE_EXISTS_REPLACE); |
|
21
|
|
|
$this->addFieldMapping('field_main_image:source_dir')->defaultValue($import_path . 'images'); |
|
22
|
|
|
$this->addFieldMapping('field_main_image:destination_file', 'filename'); |
|
23
|
|
|
// Link |
|
24
|
|
|
$this->addfieldmapping('field_link', 'link'); |
|
25
|
|
|
$this->addfieldmapping('field_link:title', 'link_title'); |
|
26
|
|
|
// Persona |
|
27
|
|
|
$this->addFieldMapping('field_persona', 'persona'); |
|
28
|
|
|
// Site Section |
|
29
|
|
|
$this->addFieldMapping('field_site_section', 'site_section')->defaultValue("Content"); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
View Code Duplication |
function csvcolumns() { |
|
|
|
|
|
|
33
|
|
|
$columns[0] = array('uuid', 'UUID'); |
|
|
|
|
|
|
34
|
|
|
$columns[1] = array('title', 'Title'); |
|
35
|
|
|
$columns[2] = array('body', 'Body'); |
|
36
|
|
|
$columns[3] = array('image', 'Image'); |
|
37
|
|
|
$columns[4] = array('link', 'Link'); |
|
38
|
|
|
$columns[5] = array('link_title', 'Link Title'); |
|
39
|
|
|
$columns[6] = array('persona', 'Persona'); |
|
40
|
|
|
return $columns; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
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.