function search_api_autocomplete_update_7102 in Search API Autocomplete 7
Convert settings for search pages to use machine names instead of IDs.
File
- ./
search_api_autocomplete.install, line 140 - Install, update and uninstall functions for the Search API autocomplete module.
Code
function search_api_autocomplete_update_7102() {
if (!db_table_exists('search_api_page')) {
return;
}
$tx = db_transaction();
try {
$pages = db_query('SELECT * FROM {search_api_page}')
->fetchAllAssoc('id');
$searches = db_query('SELECT * FROM {search_api_autocomplete_search} WHERE type = :type', array(
':type' => 'search_api_page',
));
foreach ($searches as $search) {
$page_id = (int) substr($search->machine_name, 16);
if (isset($pages[$page_id])) {
$machine_name = 'search_api_page_' . $pages[$page_id]->machine_name;
$options = unserialize($search->options);
$options['custom']['page_id'] = $pages[$page_id]->machine_name;
db_update('search_api_autocomplete_search')
->fields(array(
'machine_name' => $machine_name,
'options' => serialize($options),
))
->condition('id', $search->id)
->execute();
}
}
} catch (PDOException $e) {
$tx
->rollback();
throw new DrupalUpdateException(t('A database error occurred during update: @msg', array(
'@msg' => $e
->getMessage(),
)));
}
}