| pierre@0 | 1 <?php | 
| pierre@1 | 2 // $Id: ad_notify.install,v 1.1.2.2.2.6.2.3.2.3 2009/03/29 20:17:21 jeremy Exp $ | 
| pierre@0 | 3 | 
| pierre@0 | 4 /** | 
| pierre@0 | 5  * @file | 
| pierre@0 | 6  * Ad_notify module database schema. | 
| pierre@0 | 7  * | 
| pierre@0 | 8  * Copyright (c) 2005-2009. | 
| pierre@0 | 9  *   Jeremy Andrews <jeremy@tag1consulting.com>. | 
| pierre@0 | 10  */ | 
| pierre@0 | 11 | 
| pierre@0 | 12 /** | 
| pierre@0 | 13  * Implementation of hook_schema(). | 
| pierre@0 | 14  */ | 
| pierre@0 | 15 function ad_notify_schema() { | 
| pierre@0 | 16   $schema['ad_notify'] = array( | 
| pierre@0 | 17     'description' => 'The ad_notify table stores notifications data such as recepient, message body, event, etc.', | 
| pierre@0 | 18     'fields' => array( | 
| pierre@0 | 19       'notid' => array( | 
| pierre@0 | 20         'type' => 'serial', | 
| pierre@0 | 21         'unsigned' => TRUE, | 
| pierre@0 | 22         'not null' => TRUE, | 
| pierre@0 | 23       ), | 
| pierre@0 | 24       'aid' => array( | 
| pierre@0 | 25         'type' => 'int', | 
| pierre@0 | 26         'unsigned' => TRUE, | 
| pierre@0 | 27         'not null' => TRUE, | 
| pierre@0 | 28         'default' => 0, | 
| pierre@0 | 29       ), | 
| pierre@0 | 30       'oid' => array( | 
| pierre@0 | 31         'type' => 'int', | 
| pierre@0 | 32         'unsigned' => TRUE, | 
| pierre@0 | 33         'not null' => TRUE, | 
| pierre@0 | 34         'default' => 0, | 
| pierre@0 | 35       ), | 
| pierre@0 | 36       'event' => array( | 
| pierre@0 | 37         'type' => 'varchar', | 
| pierre@0 | 38         'length' => '255', | 
| pierre@0 | 39         'not null' => TRUE, | 
| pierre@0 | 40         'default' => '' | 
| pierre@0 | 41       ), | 
| pierre@0 | 42       'delay' => array( | 
| pierre@0 | 43         'type' => 'int', | 
| pierre@0 | 44         'not null' => TRUE, | 
| pierre@0 | 45         'default' => 0, | 
| pierre@0 | 46       ), | 
| pierre@0 | 47       'queued' => array( | 
| pierre@0 | 48         'type' => 'int', | 
| pierre@0 | 49         'not null' => TRUE, | 
| pierre@0 | 50         'default' => 0, | 
| pierre@0 | 51       ), | 
| pierre@0 | 52       'sent' => array( | 
| pierre@0 | 53         'type' => 'int', | 
| pierre@0 | 54         'not null' => TRUE, | 
| pierre@0 | 55         'default' => 0, | 
| pierre@0 | 56       ), | 
| pierre@0 | 57       'counter' => array( | 
| pierre@0 | 58         'type' => 'int', | 
| pierre@0 | 59         'unsigned' => TRUE, | 
| pierre@0 | 60         'not null' => TRUE, | 
| pierre@0 | 61         'default' => 0, | 
| pierre@0 | 62       ), | 
| pierre@0 | 63       'locked' => array( | 
| pierre@0 | 64         'type' => 'int', | 
| pierre@0 | 65         'unsigned' => TRUE, | 
| pierre@0 | 66         'size' => 'tiny', | 
| pierre@0 | 67         'not null' => TRUE, | 
| pierre@0 | 68         'default' => 0, | 
| pierre@0 | 69       ), | 
| pierre@0 | 70       'expire' => array( | 
| pierre@0 | 71         'type' => 'int', | 
| pierre@0 | 72         'unsigned' => TRUE, | 
| pierre@0 | 73         'size' => 'tiny', | 
| pierre@0 | 74         'not null' => TRUE, | 
| pierre@0 | 75         'default' => 0, | 
| pierre@0 | 76       ), | 
| pierre@0 | 77       'status' => array( | 
| pierre@0 | 78         'type' => 'int', | 
| pierre@0 | 79         'unsigned' => TRUE, | 
| pierre@0 | 80         'size' => 'tiny', | 
| pierre@0 | 81         'not null' => TRUE, | 
| pierre@0 | 82         'default' => 0, | 
| pierre@0 | 83       ), | 
| pierre@0 | 84       'address' => array( | 
| pierre@0 | 85         'type' => 'varchar', | 
| pierre@0 | 86         'length' => '255', | 
| pierre@0 | 87         'not null' => TRUE, | 
| pierre@0 | 88         'default' => '', | 
| pierre@0 | 89       ), | 
| pierre@0 | 90       'subject' => array( | 
| pierre@0 | 91         'type' => 'varchar', | 
| pierre@0 | 92         'length' => '255', | 
| pierre@0 | 93         'not null' => TRUE, | 
| pierre@0 | 94         'default' => '', | 
| pierre@0 | 95       ), | 
| pierre@0 | 96       'body' => array( | 
| pierre@0 | 97         'type' => 'text', | 
| pierre@0 | 98         'not null' => FALSE, | 
| pierre@0 | 99       ), | 
| pierre@1 | 100       'roles' => array( | 
| pierre@1 | 101         'type' => 'varchar', | 
| pierre@1 | 102         'length' => '255', | 
| pierre@1 | 103         'not null' => TRUE, | 
| pierre@1 | 104         'default' => '', | 
| pierre@1 | 105       ), | 
| pierre@1 | 106       'template' => array( | 
| pierre@1 | 107         'type' => 'int', | 
| pierre@1 | 108         'unsigned' => TRUE, | 
| pierre@1 | 109         'not null' => TRUE, | 
| pierre@1 | 110         'default' => 0, | 
| pierre@1 | 111       ), | 
| pierre@0 | 112     ), | 
| pierre@0 | 113     'primary key' => array('notid'), | 
| pierre@0 | 114     'unique keys' => array( | 
| pierre@0 | 115       'oid' => array('oid', 'event', 'delay'), | 
| pierre@0 | 116     ), | 
| pierre@0 | 117     'indexes' => array( | 
| pierre@0 | 118       'delay' => array('delay'), | 
| pierre@0 | 119       'event' => array('event'), | 
| pierre@0 | 120       'oid_2' => array('oid'), | 
| pierre@0 | 121       'queued' => array('queued'), | 
| pierre@0 | 122       'sent' => array('sent'), | 
| pierre@0 | 123       'status' => array('status'), | 
| pierre@0 | 124     ), | 
| pierre@0 | 125   ); | 
| pierre@0 | 126 | 
| pierre@0 | 127   return $schema; | 
| pierre@0 | 128 } | 
| pierre@0 | 129 | 
| pierre@0 | 130 /** | 
| pierre@0 | 131  * ad_notify module installation. | 
| pierre@0 | 132  */ | 
| pierre@0 | 133 function ad_notify_install() { | 
| pierre@0 | 134   drupal_install_schema('ad_notify'); | 
| pierre@0 | 135 } | 
| pierre@0 | 136 | 
| pierre@0 | 137 /** | 
| pierre@0 | 138  * Allow complete uninstallation of the ad_notify module. | 
| pierre@0 | 139  */ | 
| pierre@0 | 140 function ad_notify_uninstall() { | 
| pierre@0 | 141   // Remove tables. | 
| pierre@0 | 142   drupal_uninstall_schema('ad_notify'); | 
| pierre@0 | 143 } | 
| pierre@1 | 144 | 
| pierre@1 | 145 /** | 
| pierre@1 | 146  * Introduce new roles field to allow per-role notifications. | 
| pierre@1 | 147  * Replace nonstandard %sitename with standard %site-name. | 
| pierre@1 | 148  * Replace nonstandard %siteurl with standard %site-url. | 
| pierre@1 | 149  */ | 
| pierre@1 | 150 function ad_notify_update_6001() { | 
| pierre@1 | 151   $ret = array(); | 
| pierre@1 | 152   db_add_field($ret, 'ad_notify', 'roles', array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => '')); | 
| pierre@1 | 153 | 
| pierre@1 | 154   $ret[] = update_sql('UPDATE {ad_notify} SET subject = REPLACE(subject, "%sitename", "%site-name")'); | 
| pierre@1 | 155   $ret[] = update_sql('UPDATE {ad_notify} SET body = REPLACE(body, "%siteurl", "%site-url")'); | 
| pierre@1 | 156 | 
| pierre@1 | 157 } | 
| pierre@1 | 158 | 
| pierre@1 | 159 /** | 
| pierre@1 | 160  * Introduce new template field. | 
| pierre@1 | 161  */ | 
| pierre@1 | 162 function ad_notify_update_6002() { | 
| pierre@1 | 163   $ret = array(); | 
| pierre@1 | 164   db_add_field($ret, 'ad_notify', 'template', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); | 
| pierre@1 | 165   return $ret; | 
| pierre@1 | 166 } | 
| pierre@1 | 167 | 
| pierre@1 | 168 /** | 
| pierre@1 | 169  * Replace nonstandard %sitename with standard %site-name. | 
| pierre@1 | 170  * Replace nonstandard %siteurl with standard %site-url. | 
| pierre@1 | 171  * (Repeating update_6001 as there were more instances of these old variables | 
| pierre@1 | 172  * in the code.) | 
| pierre@1 | 173  */ | 
| pierre@1 | 174 function ad_notify_update_6003() { | 
| pierre@1 | 175   $ret = array(); | 
| pierre@1 | 176   $ret[] = update_sql('UPDATE {ad_notify} SET subject = REPLACE(subject, "%%sitename", "%%site-name")'); | 
| pierre@1 | 177   $ret[] = update_sql('UPDATE {ad_notify} SET body = REPLACE(body, "%%sitename", "%%site-name")'); | 
| pierre@1 | 178   $ret[] = update_sql('UPDATE {ad_notify} SET body = REPLACE(body, "%%max_views", "%%max_impressions")'); | 
| pierre@1 | 179   $ret[] = update_sql('UPDATE {ad_notify} SET body = REPLACE(body, "%%global_views", "%%global_impressions")'); | 
| pierre@1 | 180   $ret[] = update_sql('UPDATE {ad_notify} SET body = REPLACE(body, "%%last_year_views", "%%last_year_impressions")'); | 
| pierre@1 | 181   $ret[] = update_sql('UPDATE {ad_notify} SET body = REPLACE(body, "%%this_year_views", "%%this_year_impressions")'); | 
| pierre@1 | 182   $ret[] = update_sql('UPDATE {ad_notify} SET body = REPLACE(body, "%%last_month_views", "%%last_month_impressions")'); | 
| pierre@1 | 183   $ret[] = update_sql('UPDATE {ad_notify} SET body = REPLACE(body, "%%this_month_views", "%%this_month_impressions")'); | 
| pierre@1 | 184   $ret[] = update_sql('UPDATE {ad_notify} SET body = REPLACE(body, "%%yesterday_views", "%%yesterday_impressions")'); | 
| pierre@1 | 185   $ret[] = update_sql('UPDATE {ad_notify} SET body = REPLACE(body, "%%today_views", "%%today_impressions")'); | 
| pierre@1 | 186   $ret[] = update_sql('UPDATE {ad_notify} SET body = REPLACE(body, "%%last_hour_views", "%%last_hour_impressions")'); | 
| pierre@1 | 187   $ret[] = update_sql('UPDATE {ad_notify} SET body = REPLACE(body, "%%this_hour_views", "%%this_hour_impressions")'); | 
| pierre@1 | 188   return $ret; | 
| pierre@1 | 189 } | 
| pierre@1 | 190 |