| 1 |
<?php
|
| 2 |
// $Id: logwatcher.install,v 1.3 2008/09/15 16:02:16 deekayen Exp $
|
| 3 |
|
| 4 |
function logwatcher_schema() {
|
| 5 |
$schema = array();
|
| 6 |
$schema['logwatcher_data'] = array(
|
| 7 |
'fields' => array(
|
| 8 |
'id' => array(
|
| 9 |
'type' => 'serial',
|
| 10 |
'size' => 'normal',
|
| 11 |
'length' => 10,
|
| 12 |
'not null' => TRUE,
|
| 13 |
'default' => '',
|
| 14 |
'unsigned' => TRUE
|
| 15 |
),
|
| 16 |
'job_id' => array(
|
| 17 |
'type' => 'int',
|
| 18 |
'size' => 'normal',
|
| 19 |
'unsigned' => TRUE,
|
| 20 |
'not null' => FALSE,
|
| 21 |
),
|
| 22 |
'message' => array(
|
| 23 |
'type' => 'text',
|
| 24 |
'size' => 'big'
|
| 25 |
),
|
| 26 |
'num' => array(
|
| 27 |
'type' => 'int',
|
| 28 |
'length' => 10,
|
| 29 |
'not null' => FALSE
|
| 30 |
),
|
| 31 |
'last_referer' => array(
|
| 32 |
'type' => 'varchar',
|
| 33 |
'length' => 128,
|
| 34 |
'not null' => FALSE
|
| 35 |
),
|
| 36 |
'run_timestamp' => array(
|
| 37 |
'type' => 'int',
|
| 38 |
'size' => 'normal',
|
| 39 |
'length' => 11,
|
| 40 |
'not null' => FALSE
|
| 41 |
),
|
| 42 |
'run_timeframe' => array(
|
| 43 |
'type' => 'int',
|
| 44 |
'size' => 'medium',
|
| 45 |
'length' => 3,
|
| 46 |
'not null' => FALSE
|
| 47 |
)
|
| 48 |
),
|
| 49 |
'primary key' => array('id'),
|
| 50 |
);
|
| 51 |
$schema['logwatcher_settings'] = array(
|
| 52 |
'fields' => array(
|
| 53 |
'id' => array(
|
| 54 |
'type' => 'serial',
|
| 55 |
'size' => 'normal',
|
| 56 |
'length' => 10,
|
| 57 |
'not null' => TRUE,
|
| 58 |
'default' => '',
|
| 59 |
'unsigned' => TRUE
|
| 60 |
),
|
| 61 |
'type' => array(
|
| 62 |
'type' => 'varchar',
|
| 63 |
'length' => '30',
|
| 64 |
'not null' => FALSE
|
| 65 |
),
|
| 66 |
'timeframe' => array(
|
| 67 |
'type' => 'int',
|
| 68 |
'size' => 'medium',
|
| 69 |
'length' => 3
|
| 70 |
),
|
| 71 |
'rows' => array(
|
| 72 |
'type' => 'int',
|
| 73 |
'size' => 'medium',
|
| 74 |
'length' => 4,
|
| 75 |
'not null' => FALSE
|
| 76 |
),
|
| 77 |
'last_run' => array(
|
| 78 |
'type' => 'int',
|
| 79 |
'length' => 11,
|
| 80 |
'not null' => FALSE
|
| 81 |
),
|
| 82 |
'active' => array(
|
| 83 |
'type' => 'int',
|
| 84 |
'size' => 'tiny',
|
| 85 |
'length' => 1,
|
| 86 |
'default' => 1,
|
| 87 |
'not null' => TRUE
|
| 88 |
)
|
| 89 |
),
|
| 90 |
'primary key' => array('id'),
|
| 91 |
);
|
| 92 |
return $schema;
|
| 93 |
}
|
| 94 |
|
| 95 |
/**
|
| 96 |
* Implementation of hook_install().
|
| 97 |
*/
|
| 98 |
function logwatcher_install() {
|
| 99 |
switch ($GLOBALS['db_type']) {
|
| 100 |
case 'mysql':
|
| 101 |
case 'mysqli':
|
| 102 |
db_query("CREATE TABLE {logwatcher_data} (
|
| 103 |
`id` int(10) unsigned NOT NULL auto_increment,
|
| 104 |
job_id int(10) default NULL,
|
| 105 |
message longtext,
|
| 106 |
`num` int(10) default NULL,
|
| 107 |
last_referer varchar(128) default NULL,
|
| 108 |
run_timestamp int(11) default NULL,
|
| 109 |
run_timeframe int(3) default NULL,
|
| 110 |
PRIMARY KEY (`id`)
|
| 111 |
)");
|
| 112 |
db_query("CREATE TABLE {logwatcher_settings} (
|
| 113 |
`id` int(10) unsigned NOT NULL auto_increment,
|
| 114 |
`type` varchar(30) default NULL,
|
| 115 |
timeframe int(3) default NULL,
|
| 116 |
`rows` int(4) default NULL,
|
| 117 |
last_run int(11) default NULL,
|
| 118 |
active tinyint(4) default '1',
|
| 119 |
PRIMARY KEY (`id`)
|
| 120 |
)");
|
| 121 |
break;
|
| 122 |
}
|
| 123 |
}
|
| 124 |
|
| 125 |
/**
|
| 126 |
* Switch the timeframe from an int representing days to a
|
| 127 |
* varchar so it can support strings in cronplus compatible intervals.
|
| 128 |
* Last run time is no longer needed with cronplus, though it does
|
| 129 |
* remain useful for displaying the last report on the config screen.
|
| 130 |
*/
|
| 131 |
function logwatcher_update_5000() {
|
| 132 |
$ret = array();
|
| 133 |
switch ($GLOBALS['db_type']) {
|
| 134 |
case 'mysql':
|
| 135 |
case 'mysqli':
|
| 136 |
$ret[] = update_sql("ALTER TABLE {logwatcher_settings} CHANGE timeframe timeframe VARCHAR(7) NOT NULL DEFAULT ''");
|
| 137 |
break;
|
| 138 |
}
|
| 139 |
return $ret;
|
| 140 |
}
|
| 141 |
|
| 142 |
/**
|
| 143 |
* There doesn't appear to be any reason to zerofill the id field,
|
| 144 |
* especially since job_id isn't making use of it.
|
| 145 |
*/
|
| 146 |
function logwatcher_update_5001() {
|
| 147 |
$ret = array();
|
| 148 |
switch ($GLOBALS['db_type']) {
|
| 149 |
case 'mysql':
|
| 150 |
case 'mysqli':
|
| 151 |
$ret[] = update_sql("ALTER TABLE {logwatcher_data} CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
|
| 152 |
$ret[] = update_sql("ALTER TABLE {logwatcher_settings} CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
|
| 153 |
break;
|
| 154 |
}
|
| 155 |
return $ret;
|
| 156 |
}
|