1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Migrations for WEM Commerce Product Nodes. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
class DFSWEMProductReviewNodes extends DemoFrameworkBaseNodesUUID { |
9
|
|
|
|
10
|
|
|
public function __construct($arguments) { |
11
|
|
|
parent::__construct($arguments); |
12
|
|
|
$this->description = t('Import product reviews for WEM Commerce nodes.'); |
13
|
|
|
|
14
|
|
|
$this->dependencies = array('DFSWEMCommerceNodes'); |
15
|
|
|
|
16
|
|
|
$import_path = drupal_get_path('module', 'dfs_wem') . '/import/'; |
17
|
|
|
|
18
|
|
|
// Create a MigrateSource object. |
19
|
|
|
$this->source = new MigrateSourceCSV($import_path . 'dfs_wem.nodes.wem_product_review.csv', $this->csvcolumns(), array('header_rows' => 1)); |
20
|
|
|
|
21
|
|
|
$this->destination = new MigrateDestinationNode('wem_product_review'); |
22
|
|
|
|
23
|
|
|
// Author |
24
|
|
|
$this->addFieldMapping('uid', 'author')->sourceMigration('DFSWEMUsers'); |
25
|
|
|
|
26
|
|
|
// Entity Reference |
27
|
|
|
$this->addFieldMapping('field_wem_commerce_ref', 'commerce')->sourceMigration('DFSWEMCommerceNodes'); |
28
|
|
|
|
29
|
|
|
// Image |
30
|
|
|
$this->addFieldMapping('field_product_review_image', 'image'); |
31
|
|
|
$this->addFieldMapping('field_product_review_image:file_replace')->defaultValue(FILE_EXISTS_REPLACE); |
32
|
|
|
$this->addFieldMapping('field_product_review_image:source_dir')->defaultValue($import_path . 'images'); |
33
|
|
|
$this->addFieldMapping('field_product_review_image:destination_file', 'filename'); |
34
|
|
|
|
35
|
|
|
// Created |
36
|
|
|
$this->addFieldMapping('created', 'created')->defaultValue(strtotime("now")); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
View Code Duplication |
function csvcolumns() { |
|
|
|
|
40
|
|
|
$columns[0] = array('title', 'Title'); |
|
|
|
|
41
|
|
|
$columns[1] = array('body', 'Body'); |
42
|
|
|
$columns[2] = array('commerce', 'Commerce'); |
43
|
|
|
$columns[3] = array('image', 'Image'); |
44
|
|
|
$columns[4] = array('author', 'Author'); |
45
|
|
|
$columns[5] = array('uuid', 'UUID'); |
46
|
|
|
$columns[6] = array('created', 'Created'); |
47
|
|
|
return $columns; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
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.