|
@@ -1,5 +1,5 @@
|
|
|
<?php
|
|
|
-// $Id: qbf.install,v 1.1.4.1 2009-03-17 10:57:58 marand Exp $
|
|
|
+// $Id: qbf.install,v 1.1.4.2 2009-03-17 11:43:04 marand Exp $
|
|
|
/**
|
|
|
* @file
|
|
|
* QBF module - installer
|
|
@@ -8,25 +8,98 @@
|
|
|
*
|
|
|
* Author FG Marand
|
|
|
*
|
|
|
- * License GPL2 or later
|
|
|
+ * 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_queries'] = 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,
|
|
|
+ ),
|
|
|
+ 'name' => array
|
|
|
+ (
|
|
|
+ 'description' => t('Query name'),
|
|
|
+ 'type' => 'varchar',
|
|
|
+ 'length' => 40,
|
|
|
+ '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'),
|
|
|
+ ),
|
|
|
+
|
|
|
+ 'unique keys' => array(),
|
|
|
+ );
|
|
|
+
|
|
|
+ return $schema;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Implement hook_install().
|
|
|
*
|
|
|
- * - Create the QBF tables
|
|
|
- * - qbf_queries
|
|
|
+ * - Install schema
|
|
|
* - Assign initial settings
|
|
|
- * - none
|
|
|
*
|
|
|
- * @todo support PGSQL
|
|
|
* @ingroup hooks
|
|
|
* @return void
|
|
|
*/
|
|
|
function qbf_install()
|
|
|
{
|
|
|
+ drupal_install_schema('qbf');
|
|
|
+
|
|
|
// Initialize settings
|
|
|
$ar_const = get_defined_constants();
|
|
|
$ar_const = array_keys($ar_const);
|
|
@@ -45,49 +118,21 @@ function qbf_install()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
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),
|
|
|
- )));
|
|
|
-
|
|
|
- switch ($GLOBALS['db_type'])
|
|
|
- {
|
|
|
- case 'mysql':
|
|
|
- case 'mysqli':
|
|
|
- $sq = 'CREATE TABLE {qbf_queries} '
|
|
|
- .' ( '
|
|
|
- ." `qid` INT(10) NOT NULL DEFAULT '0' COMMENT 'Query ID', "
|
|
|
- ." `uid` INT(10) NOT NULL DEFAULT '0' COMMENT 'User ID', "
|
|
|
- ." `name` VARCHAR(40) NOT NULL DEFAULT '' COMMENT 'Query name', "
|
|
|
- ." `query` TEXT NOT NULL COMMENT 'Query array', "
|
|
|
- ." `created` INT(10) NOT NULL DEFAULT '0' COMMENT 'Creation timestamp', "
|
|
|
- ." `updated` INT(10) NOT NULL DEFAULT '0' COMMENT 'Update timestamp', "
|
|
|
- .' PRIMARY KEY (`qid`) , '
|
|
|
- .' KEY `uid` (`uid`), '
|
|
|
- .' KEY `updated`(`updated`) '
|
|
|
- .' ) '
|
|
|
- .'ENGINE = MyISAM '
|
|
|
- .'CHARACTER SET = utf8 '
|
|
|
- ."COMMENT = 'QBF Query store' ";
|
|
|
- db_query($sq);
|
|
|
- break;
|
|
|
-
|
|
|
- case pgsql:
|
|
|
- default:
|
|
|
- drupal_set_message(t('Unsupported database backend for QBF module: @db',
|
|
|
- array('@db' => $GLOBALS['db_type'])), 'error');
|
|
|
- break;
|
|
|
- }
|
|
|
+ )
|
|
|
+ ));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Implement hook_uninstall().
|
|
|
*
|
|
|
- * - Drop all the tables maintained by the module
|
|
|
- * - qbf_queries
|
|
|
+ * - Uninstall schema
|
|
|
* - Remove nodes of all the types maintained by the module
|
|
|
* - none
|
|
|
* - Remove module settings
|
|
@@ -99,6 +144,8 @@ function qbf_install()
|
|
|
*/
|
|
|
function qbf_uninstall()
|
|
|
{
|
|
|
+ drupal_uninstall_schema('qbf');
|
|
|
+
|
|
|
// Remove settings
|
|
|
$ar_const = get_defined_constants();
|
|
|
$ar_const = array_keys($ar_const);
|
|
@@ -110,31 +157,30 @@ function qbf_uninstall()
|
|
|
}
|
|
|
}
|
|
|
drupal_set_message(t('Removed QBF module settings.'));
|
|
|
-
|
|
|
- switch ($GLOBALS['db_type'])
|
|
|
- {
|
|
|
- case 'mysql':
|
|
|
- case 'mysqli':
|
|
|
- case 'pgsql':
|
|
|
- db_query("DROP TABLE {qbf_queries}");
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- drupal_set_message(t('Unsupported database backend for QBF module: @db',
|
|
|
- array('@db' => $GLOBALS['db_type'])), 'error');
|
|
|
- break;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Implement hook_update_N().
|
|
|
*
|
|
|
- * For now, just define a proper initial schema version.
|
|
|
+ * For 5.x, just define a proper initial schema version.
|
|
|
*
|
|
|
* @ingroup hooks
|
|
|
* @return array
|
|
|
*/
|
|
|
function qbf_update_5000()
|
|
|
+ {
|
|
|
+ return array();
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implement hook_update_N().
|
|
|
+ *
|
|
|
+ * No data structure change from 5000 to 6000, but we need a 6xxx schema version.
|
|
|
+ *
|
|
|
+ * @ingroup hooks
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+function qbf_update_6000()
|
|
|
{
|
|
|
return array();
|
|
|
}
|