You are here

search_files_directories.install in Search Files 6.2

Same filename and directory in other branches
  1. 7.2 search_files_directories.install

Installation and update procedures for the search directories module.

File

search_files_directories.install
View source
<?php

/**
 * @file
 * Installation and update procedures for the search directories module.
 */
function search_files_directories_schema() {
  $schema['search_files_directories_directories'] = array(
    'description' => t('list of directories that we will index'),
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'disp-width' => '11',
      ),
      'filepath' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
      ),
      'uripath' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'unique keys' => array(
      'filepath' => array(
        'filepath',
      ),
    ),
  );
  $schema['search_files_directories_files'] = array(
    'description' => t('list of files in the directories, this is here because the the search_dataset table needs some sort of integer id to reference the file by'),
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'disp-width' => '11',
      ),
      'path' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
      ),
      'directory_id' => array(
        'type' => 'int',
        'not null' => TRUE,
        'disp-width' => '11',
      ),
      'index_attempts' => array(
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'disp-width' => '4',
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'unique keys' => array(
      'path' => array(
        'path',
      ),
    ),
  );
  return $schema;
}
function search_files_directories_install() {
  drupal_install_schema('search_files_directories');
}

/**
 * Update #1 - Migrate from search_files-1.x to search_files-2.x
 */
function search_files_directories_update_1() {
  $ret = array();
  if (db_table_exists('search_files_files')) {
    db_rename_table($res, 'search_files_files', 'search_files_directories_files');
  }
  variable_set('search_files_directories_tab_label', variable_get('search_files_label', NULL));
  variable_del('search_files_label');
  variable_set('search_files_directories_last_index', variable_get('search_files_last_index', 0));
  variable_del('search_files_last_index');
  return $ret;
}

/* http://drupal.org/node/114774#update-n
 */
function search_files_directories_update_6200() {
  $ret = array();

  /* take over module enablement and discard obsolete module information */
  $result = db_result(db_query_range("\n              SELECT status FROM {system}\n              WHERE name = 'search_directories'\n                AND filename LIKE '%/search_files/modules/search_directories/search_directories.module'\n            "), 0, 1);
  if ($result != "") {
    db_query("\n        UPDATE {system}\n        SET status = '%s'\n        WHERE name = 'search_files_directories'\n      ", $result);
    db_query("\n        DELETE FROM {system}\n        WHERE name = 'search_directories'\n          AND filename LIKE '%/search_files/modules/search_directories/search_directories.module'\n      ");
  }

  /* rename tables */
  search_files_db_rename_table_ifexists($ret, 'search_directories', 'search_files_directories');
  search_files_db_rename_table_ifexists($res, 'search_directories_files', 'search_files_directories_files');

  /* rename variables */
  search_files_variable_rename_ifexists('search_directories_last_index', 'search_files_directories_last_index');
  search_files_variable_rename_ifexists('search_directories_tab_disabled', 'search_files_directories_tab_disabled');
  search_files_variable_rename_ifexists('search_directories_tab_label', 'search_files_directories_tab_label');
  search_files_variable_rename_ifexists('search_files_directoryrescanage', 'search_files_directories_rescanage');
  return $ret;
}
function search_files_directories_update_6201() {
  $ret = array();
  db_query("\n    UPDATE {search_dataset}\n    SET type = 'search_files_dir'\n    WHERE ( type = 'search_files' OR type = 'search_directories')\n  ");
  db_query("\n    UPDATE {search_index}\n    SET type = 'search_files_dir'\n    WHERE ( type = 'search_files' OR type = 'search_directories')\n  ");
  return $ret;
}
function search_files_directories_update_6202() {
  $ret = array();
  search_files_db_rename_table_ifexists($ret, 'search_files_directories', 'search_files_directories_directories');
  return $ret;
}
function search_files_directories_update_6203() {
  $ret = array();
  search_files_db_rename_column_ifexists($ret, 'search_files_directories_directories', 'directory', 'path', array(
    'type' => 'varchar',
    'length' => '255',
    'not null' => TRUE,
  ));
  search_files_db_rename_column_ifexists($ret, 'search_files_directories_files', 'full_path', 'path', array(
    'type' => 'varchar',
    'length' => '255',
    'not null' => TRUE,
  ));
  return $ret;
}
function search_files_directories_update_6204() {
  $ret = array();
  search_files_db_rename_column_ifexists($ret, 'search_files_directories_directories', 'path', 'filepath', array(
    'type' => 'varchar',
    'length' => '255',
    'not null' => TRUE,
  ));
  db_add_field($ret, 'search_files_directories_directories', 'uripath', array(
    'type' => 'varchar',
    'length' => '255',
    'not null' => TRUE,
  ));
  return $ret;
}
function search_files_directories_uninstall() {
  drupal_uninstall_schema('search_files_directories');
  db_query("DELETE FROM {search_dataset} WHERE type = 'search_files_dir'");
  db_query("DELETE FROM {search_index} WHERE type = 'search_files_dir'");
  db_query("DELETE FROM {variable} WHERE name LIKE 'search_files_directories_%'");
}