function ultimate_cron_update_7105 in Ultimate Cron 7.2
Same name and namespace in other branches
- 7 ultimate_cron.install \ultimate_cron_update_7105()
Add missing index to database.
File
- ./
ultimate_cron.install, line 510 - Installation file for Ultimate Cron.
Code
function ultimate_cron_update_7105() {
if (!db_field_exists('ultimate_cron_log', 'name') && !db_index_exists('ultimate_cron', 'uniq_function')) {
// 'name' doesn't exist, so update ultimate_cron_update_7106() has never
// run and was never run when it was previously called
// ultimate_cron_update_6106(). If one of these updates had run, we would
// have already done this update and could safely skip it.
// 'uniq_function' also does not exist, so this update has never run and
// was never run when it was previously called ultimate_cron_update_6105()
// - hence, it needs to be run.
$items = db_select('ultimate_cron')
->fields('ultimate_cron', array(
'fid',
'function',
))
->orderBy('fid', 'ASC')
->execute()
->fetchAllAssoc('fid', PDO::FETCH_ASSOC);
$fids = array();
$keep = array();
foreach ($items as $item) {
if (isset($keep[$item['function']])) {
$fids[] = $keep[$item['function']];
}
$keep[$item['function']] = $item['fid'];
}
if ($fids) {
db_delete('ultimate_cron')
->condition('fid', $fids)
->execute();
}
db_add_unique_key('ultimate_cron', 'uniq_function', array(
'function',
));
}
}