function scald_file_update_7001 in Scald File Provider 7
Add the file field and update Files to the new scald_file field.
File
- ./
scald_file.install, line 64 - Scald Files Installation.
Code
function scald_file_update_7001(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['current_sid'] = 0;
$sandbox['max'] = db_query("SELECT COUNT(s.sid) FROM {scald_atoms} s WHERE s.provider='scald_file' AND s.type='file' AND s.base_id IS NOT NULL")
->fetchField();
$sandbox['affected_rows'] = 0;
}
// First make sure we have the file field.
_scald_file_create_file_field();
$stop_at = time() + 5;
// Get all the file atom sids.
$sids = db_query("SELECT s.sid FROM {scald_atoms} s WHERE s.provider='scald_file' AND s.type='file' AND s.base_id IS NOT NULL AND s.sid > :sid ORDER BY s.sid", array(
':sid' => $sandbox['current_sid'],
));
// Loop them through.
while ($sid = $sids
->fetchColumn()) {
$atom = scald_atom_load($sid);
// Make sure we have a base entity.
if (isset($atom->base_id)) {
$file = file_load($atom->base_id);
// Make sure we have something in uri.
if (!empty($file->uri)) {
// Add the display field.
$file->display = TRUE;
// Use it for the scald_file field.
$atom->scald_file[LANGUAGE_NONE][0] = (array) $file;
scald_atom_save($atom);
$sandbox['affected_rows']++;
}
}
$sandbox['progress']++;
$sandbox['current_sid'] = $sid;
if (time() > $stop_at) {
break;
}
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
if ($sandbox['#finished'] >= 1) {
return t('Updated %affected_rows atoms.', array(
'%affected_rows' => $sandbox['affected_rows'],
));
}
}