123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- // $Id: qbf.install,v 1.1.4.6 2009-03-22 15:15:19 marand Exp $
- /**
- * @file
- * QBF module - installer
- *
- * Copyright 2008-2009 Ouest Systèmes Informatiques SARL
- *
- * Author FG Marand
- *
- * Licensed under the CeCILL 2.0 and the General Public Licence version 2 or later
- */
- // We need to import the module to access its named constants
- require_once(drupal_get_path('module', 'qbf') .'/qbf.module');
- /**
- * Implement hook_schema().
- *
- * @ingroup hooks
- *
- * @return array
- */
- function qbf_schema()
- {
- $schema[QBF_TABLE_NAME] = array
- (
- 'description' => t('Saved QBF queries.'),
- 'fields' => array
- (
- 'qid' => array
- (
- 'description' => t('Query ID'),
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'uid' => array
- (
- 'description' => t('User ID'),
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'type' => array
- (
- 'description' => t('Query type'),
- 'type' => 'varchar',
- 'length' => 20,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'name' => array
- (
- 'description' => t('Query name'),
- 'type' => 'varchar',
- 'length' => 60,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'query' => array
- (
- 'description' => t('Query array'),
- 'type' => 'text',
- 'not null' => TRUE,
- ),
- 'created' => array
- (
- 'description' => 'Query creation timestamp.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'updated' => array
- (
- 'description' => 'Query update timestamp',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- ),
- 'primary key' => array('qid'),
- 'indexes' => array
- (
- 'query_updated' => array('updated'),
- 'query_created' => array('created'),
- 'query_per_user' => array('uid', 'type'),
- ),
- 'unique keys' => array(),
- );
- return $schema;
- }
- /**
- * Implement hook_install().
- *
- * - Install schema
- * - Assign initial settings
- *
- * @ingroup hooks
- * @return void
- */
- function qbf_install()
- {
- drupal_install_schema('qbf');
- // Initialize settings
- $ar_const = get_defined_constants();
- $ar_const = array_keys($ar_const);
- $count = 0;
- $init_count = 0;
- foreach ($ar_const as $name)
- {
- if (strpos($name, 'QBF_VAR_') === 0)
- {
- $count++;
- $default = 'QBF_DEF_'. drupal_substr($name, drupal_strlen('QBF_VAR_'));
- if (defined($default))
- {
- variable_set(constant($name), constant($default));
- $init_count++;
- }
- }
- }
- drupal_set_message(t('Initialized QBF module settings (@initCount/@count parameters). You can <a href="!link">complete setup</a>.',
- array
- (
- '@initCount' => $init_count,
- '@count' => $count,
- '!link' => url(QBF_PATH_SETTINGS),
- )
- ));
- }
- /**
- * Implement hook_uninstall().
- *
- * - Uninstall schema
- * - Remove nodes of all the types maintained by the module
- * - none
- * - Remove module settings
- * - none
- * - Do NOT remove module schema version from {system}
- *
- * @ingroup hooks
- * @return void
- */
- function qbf_uninstall()
- {
- drupal_uninstall_schema('qbf');
- // Remove settings
- $ar_const = get_defined_constants();
- $ar_const = array_keys($ar_const);
- foreach ($ar_const as $name)
- {
- if (strpos($name, 'QBF_VAR_') === 0)
- {
- variable_del($name);
- }
- }
- drupal_set_message(t('Removed QBF module settings.'));
- }
- /**
- * Implement hook_update_N().
- *
- * For 5.x, just define a proper initial schema version.
- *
- * @ingroup hooks
- * @return array
- */
- function qbf_update_5000()
- {
- return array();
- }
- /**
- * Implement hook_update_N().
- *
- * 5000 to 6000
- * - new "type" column
- * - "name" varchar(40)->varchar(60)
- * - "qid" int->serial
- *
- * @ingroup hooks
- * @return array
- */
- function qbf_update_6000()
- {
- $ret = array();
- variable_set(QBF_VAR_MAX_QUERIES, variable_get('job_max_queries', QBF_DEF_MAX_QUERIES));
- variable_set(QBF_VAR_PROFILE_CATEGORY, variable_get('job_profile_category', QBF_DEF_PROFILE_CATEGORY));
- variable_set(QBF_VAR_QUERY_MODE, variable_get('job_query_mode', Qbf_Query_Mode::CONTAINS));
- drupal_set_message('Migrated QBF-related settings from Job 5.x to QBF 6.x settings');
- db_drop_primary_key($ret, QBF_TABLE_NAME);
- db_drop_index($ret, QBF_TABLE_NAME, 'query_updated');
- db_drop_index($ret, QBF_TABLE_NAME, 'query_created');
- db_drop_index($ret, QBF_TABLE_NAME, 'query_per_user');
- db_add_field($ret, QBF_TABLE_NAME, 'type', array
- (
- 'description' => t('Query type'),
- 'type' => 'varchar',
- 'length' => 20,
- 'not null' => TRUE,
- 'default' => '',
- 'initial' => 'job_form', // Version 5 was bound to the OSInet job search
- ));
- db_change_field($ret, QBF_TABLE_NAME, 'name', 'name',
- array
- (
- 'type' => 'varchar',
- 'length' => 60, // was 40
- )
- );
- db_change_field($ret, QBF_TABLE_NAME, 'qid', 'qid',
- array
- (
- 'type' => 'serial',
- ),
- array
- (
- 'primary key' => array('qid'),
- 'indexes' => array
- (
- 'query_updated' => array('updated'),
- 'query_created' => array('created'),
- 'query_per_user' => array('uid', 'type'),
- ),
- 'unique keys' => array(),
- )
- );
- return $ret;
- }
|