-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfile.inc
73 lines (63 loc) · 2.58 KB
/
file.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* @file
* Class for migrating files into Ding2.
*/
class DingFileMigration extends DrupalFile6Migration {
public function __construct($arguments) {
// in settings.php file, add the absolute path your ding1 sites files reside in by including the line:
// $conf['migrate_ding1_ding2_source_dir'] = '/home/YOUR-DING1-SITE/sites/default/files';
$source_dir = variable_get('migrate_ding1_ding2_source_dir', '/home/web/YOUR/SOURCE/FILES');
// The description and the migration machine name are also required arguments,
// which will be unique for each migration you register.
$file_arguments = array(
'source_connection' => 'legacy',
'source_version' => 6,
'description' => t('Migration of files from Ding1/D6'),
'machine_name' => 'DingFile',
'group_name' => 'ding1_group',
'source_dir' => $source_dir,
'user_migration' => 'DingUser',
);
parent::__construct($file_arguments);
// Removing and redefining existing field mapping
$this->removeFieldMapping('destination_file');
$this->addFieldMapping('destination_file', 'filepath')
->description(t('filepath is trimmed and path modified to fit destination directories'))
->callbacks(array($this, 'get_modified_path'));
// urlencode option, see https://drupal.org/node/1540106#urlencode
$this->addFieldMapping('urlencode')
->description(t('urlencode set to TRUE has no effect on this migration, but we set it anyway'))
->defaultValue(1);
// Unmapped destination fields
$this->addUnmigratedDestinations(array('path'));
}
//Function to strip "sites/default/files/" and modify path based on strings in filepath
protected function get_modified_path($value) {
$value = str_replace('sites/default/files/', '', $value);
// Get path part
$path_value = substr($value, 0, strpos($value,'/'));
// Change path part in filepath according to a list
switch ($path_value) {
case "campaigns":
$value = str_replace('campaigns/', 'ding_campaign_image/', $value);
break;
case "content_images":
$value = str_replace('content_images/', '', $value);
break;
case "file_attachments":
$value = str_replace('file_attachments/', 'files/', $value);
break;
case "list_images":
$value = str_replace('list_images/', 'list_image/', $value);
break;
case "profile_image":
$value = str_replace('profile_image/', 'profile_image/staff/', $value);
break;
default:
// modify nothing
break;
}
return $value;
}
}