function _filefield_paths_batch_update_process in File (Field) Paths 7
Same name and namespace in other branches
- 8 filefield_paths.module \_filefield_paths_batch_update_process()
- 6 filefield_paths.module \_filefield_paths_batch_update_process()
Batch callback for File (Field) Paths retroactive updates.
Parameters
$objects:
$instance:
$context:
Throws
1 string reference to '_filefield_paths_batch_update_process'
- filefield_paths_batch_update in ./
filefield_paths.module - Set batch process to update File (Field) Paths.
File
- ./
filefield_paths.module, line 272 - Contains core functions for the File (Field) Paths module.
Code
function _filefield_paths_batch_update_process($objects, $instance, &$context) {
if (!isset($context['sandbox']['progress'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['max'] = count($objects);
$context['sandbox']['objects'] = $objects;
}
// Process nodes by groups of 5.
$count = min(5, count($context['sandbox']['objects']));
for ($i = 1; $i <= $count; $i++) {
// For each oid, load the object, update the files and save it.
$oid = array_shift($context['sandbox']['objects']);
$entity = current(entity_load($instance['entity_type'], array(
$oid,
)));
// Enable active updating if it isn't already enabled.
$active_updating = $instance['settings']['filefield_paths']['active_updating'];
if (!$active_updating) {
$instance['settings']['filefield_paths']['active_updating'] = TRUE;
field_update_instance($instance);
}
// Invoke field_attach_update().
field_attach_update($instance['entity_type'], $entity);
// Restore active updating to it's previous state if necessary.
if (!$active_updating) {
$instance['settings']['filefield_paths']['active_updating'] = $active_updating;
field_update_instance($instance);
}
// Update our progress information.
$context['sandbox']['progress']++;
}
// Inform the batch engine that we are not finished,
// and provide an estimation of the completion level we reached.
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}