| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* Install file for G2 Glossary
|
| 4 |
*
|
| 5 |
* @copyright 2007 Ouest Systemes Informatiques
|
| 6 |
* @license CeCILL 2.0
|
| 7 |
* @version $Id$
|
| 8 |
*
|
| 9 |
*/
|
| 10 |
$_g2_install_er = error_reporting(E_ALL | E_STRICT);
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Drupal install function for 4.7
|
| 14 |
* http://drupal.org/node/51220
|
| 15 |
* @return void
|
| 16 |
*/
|
| 17 |
function g2_install()
|
| 18 |
{
|
| 19 |
$required_table_names = array
|
| 20 |
(
|
| 21 |
'g2_node',
|
| 22 |
'g2_referer'
|
| 23 |
);
|
| 24 |
|
| 25 |
$sq = "show tables like '{g2_%}'" ;
|
| 26 |
$q = db_query($sq);
|
| 27 |
$existing_table_names = array();
|
| 28 |
while ($o = db_fetch_array($q))
|
| 29 |
{
|
| 30 |
$existing_table_names[] = array_pop($o);
|
| 31 |
}
|
| 32 |
$created_tables = array_diff($required_table_names, $existing_table_names);
|
| 33 |
g2_create_tables($created_tables);
|
| 34 |
watchdog('g2 install', print_r($created_tables, true), WATCHDOG_NOTICE);
|
| 35 |
}
|
| 36 |
|
| 37 |
|
| 38 |
/**
|
| 39 |
* Create tables necessary for G2.module
|
| 40 |
* Pure creation, to keep it plain. No checks for existence or level
|
| 41 |
*
|
| 42 |
* @param array $tables
|
| 43 |
* @return void
|
| 44 |
*/
|
| 45 |
function g2_create_tables($table_names = array())
|
| 46 |
{
|
| 47 |
foreach ($table_names as $table_name)
|
| 48 |
{
|
| 49 |
switch ($table_name)
|
| 50 |
{
|
| 51 |
case 'g2_referer':
|
| 52 |
$sq = 'CREATE TABLE {g2_referer} '
|
| 53 |
. ' ( '
|
| 54 |
. " `nid` int(10) unsigned NOT NULL default '0', "
|
| 55 |
. " `referer` varchar(128) NOT NULL default '', "
|
| 56 |
. " `incoming` int(10) NOT NULL default '0', "
|
| 57 |
. " PRIMARY KEY (`nid`,`referer`), "
|
| 58 |
. " KEY `referer` (`referer`) "
|
| 59 |
. " ) "
|
| 60 |
. "ENGINE=MyISAM "
|
| 61 |
. "DEFAULT CHARSET=utf8 "
|
| 62 |
. "COMMENT='G2 referer stats for link exchange' ";
|
| 63 |
break;
|
| 64 |
case 'g2_node':
|
| 65 |
$sq = 'CREATE TABLE {g2_node} '
|
| 66 |
. " ( "
|
| 67 |
. " `nid` int(11) NOT NULL default '0', "
|
| 68 |
. " `period` varchar(50) default NULL, "
|
| 69 |
. " `complement` mediumtext, "
|
| 70 |
. " `origin` mediumtext, "
|
| 71 |
. " PRIMARY KEY (`nid`) "
|
| 72 |
. " ) "
|
| 73 |
. "ENGINE=MyISAM "
|
| 74 |
. "DEFAULT CHARSET=utf8 "
|
| 75 |
. "COMMENT='Extensions to node for g2 module' " ;
|
| 76 |
break;
|
| 77 |
default:
|
| 78 |
watchdog('g2', "g2_create_tables: trying to install unknown table $table_name", WATCHDOG_ERROR);
|
| 79 |
break;
|
| 80 |
}
|
| 81 |
$q = db_query($sq);
|
| 82 |
if ($q != 1)
|
| 83 |
{
|
| 84 |
watchdog('g2', 'g2 installer failed at creating table %table_name',
|
| 85 |
array('%table_name' => $table_name),
|
| 86 |
WATCHDOG_ERROR
|
| 87 |
);
|
| 88 |
}
|
| 89 |
}
|
| 90 |
}
|
| 91 |
|
| 92 |
function g2_uninstall()
|
| 93 |
{
|
| 94 |
$variables = array();
|
| 95 |
$sq = "SELECT v.name FROM {variable} v WHERE v.name LIKE 'g2_%' or v.name LIKE 'g2/%' ";
|
| 96 |
$q = db_query($sq);
|
| 97 |
while ($o = db_fetch_object($q))
|
| 98 |
{
|
| 99 |
$variables[] = $o->name;
|
| 100 |
}
|
| 101 |
array_walk($variables, 'variable_del');
|
| 102 |
drupal_set_message(t('Removed G2 Glossary variables'), 'status');
|
| 103 |
}
|
| 104 |
|
| 105 |
error_reporting($_g2_install_er);
|
| 106 |
unset($_g2_install_er);
|