-
Notifications
You must be signed in to change notification settings - Fork 0
/
photogallery.inc
151 lines (127 loc) · 4.74 KB
/
photogallery.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* @file
*
*/
class NistPhotoGalleryMigration extends NistMigration {
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = t('Import of NIST Photo Gallery images');
$fields = array(
'author' => 'This is the credit line from the image gallery',
'avnumber' => 'internal reference ID',
'copyright' => 'this is a boolean indicating whether or not the image is copyrighted',
'description' => 'Image description',
'fileformat' => 'File format fo the image.',
'imagedate' => 'date image was taken',
'imageid' => 'Image ID',
'imagesource' => 'originating organization',
'imagetype' => 'what kind of image is it',
'imageurl' => 'URL on source site',
'moddate' => 'Date image was modified',
'subjects' => 'people tagged in the images',
'title' => 'The Title of the Image',
'topics' => 'keywords from the gallery topic list'
/*
* FROM FEED
** author
** avnumber
** copyright
** description
editorid
** file150 NOT USED
** file300 NOT USED
** file72 NOT USED
** fileformat
** imagedate
** imageid
** imagesource
** imagetype
** imageurl
** internalonly NOT USED, WE'RE ONLY PULLING THINGS ALLOWED ON EXT
** moddate
** subjects
** title
** topics
*/
// NOT USING'filename' => 'Filename from Commonspot',
// NOT USING 'ownerid' => 'Source owner ID',
// NOT USING 'subsiteurl' => 'URL on source site (minus filename)',
// NOT USING 'taxonomy_ids' => 'Taxonomy ids',
);
$this->highwaterField = array(
'name' => 'moddate', // Column to be used as highwater mark
'alias' => 'i',
);
$this->source = new MigrateSourceJSON('', 'imageid', $fields);
$this->destination = new MigrateDestinationFile('image');
$this->map = new MigrateSQLMap($this->machineName,
array('imageid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'ImageID',
)
),
MigrateDestinationFile::getKeySchema()
);
//$this->addFieldMapping('source_dir', 'imageurl');
$this->addFieldMapping('value', 'imageurl');
$this->addFieldMapping('destination_dir', 'public://');
$this->addFieldMapping('destination_file', 'generatedFileName');
$this->addFieldMapping('preserve_files')
->defaultValue(true);
$this->addFieldMapping('file_replace')
->defaultValue(MigrateFile::FILE_EXISTS_REUSE);
$this->addFieldMapping('filename', 'title');
$this->addFieldMapping('timestamp', 'moddate');
$this->addFieldMapping('field_credit', 'author');
$this->addFieldMapping('field_av_number', 'avnumber');
$this->addFieldMapping('field_image_gallery')
->defaultValue(true);
$this->addFieldMapping('field_copyright_protected', 'copyright');
$this->addFieldMapping('field_image_caption', 'description');
$this->addFieldMapping('field_date', 'imagedate');
/*
Going to revisit this when we get a mapping from the weird old
Tag to the new gloabal taxonomy.
$this->addFieldMapping('field_keyword_tags', 'topics')
->separator('/');
$this->addFieldMapping('field_keyword_tags:source_type')
->defaultValue('term');
$this->addFieldMapping('field_keyword_tags:create_term')
->defaultValue(TRUE);
*/
$this->addFieldMapping('field_image_source', 'imagesource');
$this->addFieldMapping('field_subjects', 'subjects');
// THIS WILL NEED A MAPPING FROM THE OLD SYSTEM
$this->addFieldMapping('field_image_format', 'generatedImageType');
$this->addUnmigratedSources(array(
'imagedescription'
));
$this->addUnmigratedDestinations(array(
'fid', 'source_dir', 'path', 'urlencode'
));
$this->removeFieldMapping('pathauto');
}
/**
* Implementation of Migration::prepareRow
*/
public function prepareRow($row) {
if (parent::prepareRow($row) === FALSE) :
return FALSE;
endif;
$row->generatedImageType = $this->getImageTypeFromMap($row->imagetype);
// replcae strings and lower case the file name
$newImageFileName = preg_replace('/[^a-z0-9]+/', '_', strtolower($row->title)) . '.' . $row->fileformat;
$row->generatedFileName = '/images/photogallery/' . $newImageFileName;
$row->theImageURL = trim($row->imageurl);
/*
drush_log($row->generatedImageType, $type = 'warning', $error = null);
drush_log($row->theImageURL, $type = 'warning', $error = null);
drush_log($row->generatedFileName, $type = 'warning', $error = null);
drush_log($row->topics, $type = 'warning', $error = null);
drush_log($row->subjects, $type = 'warning', $error = null);
*/
}
}