-
-
Save vinmassaro/049109c69d59aa2d33c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Fix importer mappings for file and image fields to use :uri convention. | |
*/ | |
function feeds_update_7210(&$sandbox) { | |
// If this is the first pass through this update function then set some variables. | |
if (!isset($sandbox['progress'])) { | |
$sandbox['importers'] = feeds_importer_load_all(TRUE); | |
$sandbox['progress'] = 0; | |
$sandbox['max'] = count($sandbox['importers']); | |
} | |
$importer_index = $sandbox['progress']; | |
$importer = array_pop($sandbox['importers']); | |
$processor = $importer->processor; | |
$config = $processor->getConfig(); | |
foreach ($config['mappings'] as $id => $mapping) { | |
// Act on mappings that do not contain a colon. | |
if (!strpos($mapping['target'], ':')) { | |
// Get field data. Check if $info is empty to weed out non-field mappings like temporary targets. | |
$info = field_info_field($mapping['target']); | |
if (!empty($info)) { | |
// Act on file or image fields. | |
if (in_array($info['type'], array('file', 'image'))) { | |
// Add ':uri' to fix the mapping. | |
$config['mappings'][$id]['target'] = $mapping['target'] . ':uri'; | |
} | |
} | |
} | |
} | |
// Add the updated config and save the importer. | |
$processor->addConfig(array('mappings' => $config['mappings'])); | |
$importer->save(); | |
$sandbox['progress']++; | |
// Set the value for finished. If progress == max then finished will be 1, signifying we are done. | |
$sandbox['#finished'] = ($sandbox['progress'] / $sandbox['max']); | |
return t('@importers importers processed.', array('@importers' => $sandbox['max'])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment