123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- /**
- * @file
- * Install, update and uninstall functions for the Search API autocomplete module.
- */
- /**
- * Implements hook_schema().
- */
- function search_api_autocomplete_schema() {
- $schema['search_api_autocomplete_search'] = array(
- 'description' => 'Stores autocomplete settings for searches on Search API indexes.',
- 'fields' => array(
- 'id' => array(
- 'description' => 'The primary identifier for a search.',
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'machine_name' => array(
- 'description' => 'A string identifier for a search.',
- 'type' => 'varchar',
- 'length' => 100,
- 'not null' => TRUE,
- ),
- 'name' => array(
- 'description' => 'A human-readable name for the search.',
- 'type' => 'varchar',
- 'length' => 50,
- ),
- 'index_id' => array(
- 'description' => 'The {search_api_index}.machine_name this search belongs to.',
- 'type' => 'varchar',
- 'length' => 50,
- 'not null' => TRUE,
- ),
- 'type' => array(
- 'description' => 'The type of search, usually a module name.',
- 'type' => 'varchar',
- 'length' => 50,
- 'not null' => TRUE,
- ),
- 'enabled' => array(
- 'description' => 'A flag indicating whether autocompletion for this search is enabled.',
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => TRUE,
- 'default' => 1,
- ),
- 'options' => array(
- 'description' => 'The options used to configure autocompletion for this search.',
- 'type' => 'text',
- 'serialize' => TRUE,
- 'not null' => TRUE,
- ),
- 'status' => array(
- 'description' => 'The exportable status of the entity.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0x01,
- 'size' => 'tiny',
- ),
- 'module' => array(
- 'description' => 'The name of the providing module if the entity has been defined in code.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => FALSE,
- ),
- ),
- 'primary key' => array('id'),
- 'unique keys' => array(
- 'machine_name' => array('machine_name'),
- ),
- 'indexes' => array(
- 'enabled' => array('enabled'),
- ),
- );
- return $schema;
- }
- /**
- * Update permissions to the new system with search-specific permissions.
- */
- function search_api_autocomplete_update_7101() {
- $roles = db_select('role_permission', 'r')
- ->fields('r', array('rid'))
- ->condition('permission', 'use search_api_autocomplete')
- ->execute()
- ->fetchCol();
- $searches = db_select('search_api_autocomplete_search', 's')
- ->fields('s', array('machine_name'))
- ->execute()
- ->fetchCol();
- try {
- $tx = db_transaction();
- db_delete('role_permission')
- ->condition('permission', 'use search_api_autocomplete')
- ->execute();
- if ($roles && $searches) {
- $insert = db_insert('role_permission')
- ->fields(array('rid', 'permission', 'module'));
- foreach ($roles as $rid) {
- foreach ($searches as $id) {
- $insert->values(array(
- 'rid' => $rid,
- 'permission' => 'use search_api_autocomplete for ' . $id,
- 'module' => 'search_api_autocomplete',
- ));
- }
- }
- $insert->execute();
- }
- }
- catch (PDOException $e) {
- $tx->rollback();
- throw new DrupalUpdateException(t('A database error occurred during update: @msg', array('@msg' => $e->getMessage())));
- }
- }
|