annotate channel/ad_channel.install @ 8:32c1a7d9e1fa ad tip

maj module ad en 2.1
author sly
date Fri, 11 Sep 2009 11:10:20 +0000
parents 6aeff3329e01
children
rev   line source
pierre@1 1 <?php
sly@8 2 // $Id: ad_channel.install,v 1.1.4.9 2009/07/28 17:39:35 jeremy Exp $
pierre@1 3
pierre@1 4 /**
pierre@1 5 *
pierre@1 6 * Ad channel database schema.
pierre@1 7 * Copyright (c) 2008-2009 Jeremy Andrews <jeremy@tag1consulting.com>.
pierre@1 8 */
pierre@1 9
pierre@1 10 /**
pierre@1 11 * Create the ad_channel schema.
pierre@1 12 */
sly@8 13 function ad_channel_schema() {
sly@8 14 $schema['ad_channel'] = array(
sly@8 15 'description' => 'The ad_channel table allows advertisements to be organized into channels against which rules can be applied.',
sly@8 16 'fields' => array(
sly@8 17 'chid' => array(
sly@8 18 'type' => 'serial',
sly@8 19 'not null' => TRUE,
sly@8 20 'unsigned' => TRUE,
sly@8 21 'description' => 'Unique channel ID.',
sly@8 22 ),
sly@8 23 'name' => array(
sly@8 24 'type' => 'varchar',
sly@8 25 'length' => 64,
sly@8 26 'not null' => TRUE,
sly@8 27 'default' => '',
sly@8 28 'description' => 'The name of the channel.',
sly@8 29 ),
sly@8 30 'description' => array(
sly@8 31 'type' => 'text',
sly@8 32 'size' => 'big',
sly@8 33 'not null' => FALSE,
sly@8 34 'description' => 'A description of the channel.',
sly@8 35 ),
sly@8 36 'conid' => array(
sly@8 37 'type' => 'int',
sly@8 38 'not null' => TRUE,
sly@8 39 'unsigned' => TRUE,
sly@8 40 'default' => 0,
sly@8 41 'description' => 'ID of the container the channel is in.',
sly@8 42 ),
sly@8 43 'weight' => array(
sly@8 44 'type' => 'int',
sly@8 45 'size' => 'medium',
sly@8 46 'not null' => TRUE,
sly@8 47 'unsigned' => TRUE,
sly@8 48 'default' => 0,
sly@8 49 'description' => 'Used when displaying channels to admins, heavier weights sink to the bottom.',
sly@8 50 ),
sly@8 51 'display' => array(
sly@8 52 'type' => 'int',
sly@8 53 'size' => 'tiny',
sly@8 54 'not null' => TRUE,
sly@8 55 'unsigned' => TRUE,
sly@8 56 'default' => 0,
sly@8 57 ),
sly@8 58 'no_channel_percent' => array(
sly@8 59 'type' => 'int',
sly@8 60 'size' => 'medium',
sly@8 61 'not null' => TRUE,
sly@8 62 'unsigned' => TRUE,
sly@8 63 'default' => 0,
sly@8 64 ),
sly@8 65 'inventory' => array(
sly@8 66 'type' => 'int',
sly@8 67 'not null' => TRUE,
sly@8 68 'unsigned' => TRUE,
sly@8 69 'default' => 0,
sly@8 70 ),
sly@8 71 'urls' => array(
sly@8 72 'type' => 'text',
sly@8 73 ),
sly@8 74 'groups' => array(
sly@8 75 'type' => 'text',
sly@8 76 ),
sly@8 77 ),
sly@8 78 'primary key' => array('chid'),
sly@8 79 'indexes' => array(
sly@8 80 'name' => array('name'),
sly@8 81 ),
sly@8 82 );
sly@8 83 $schema['ad_channel_remnant'] = array(
sly@8 84 'fields' => array(
sly@8 85 'aid' => array(
sly@8 86 'type' => 'int',
sly@8 87 'not null' => TRUE,
sly@8 88 'unsigned' => TRUE,
sly@8 89 'default' => 0,
sly@8 90 ),
sly@8 91 'remnant' => array(
sly@8 92 'type' => 'int',
sly@8 93 'size' => 'tiny',
sly@8 94 'not null' => TRUE,
sly@8 95 'unsigned' => TRUE,
sly@8 96 'default' => 0,
sly@8 97 ),
sly@8 98 ),
sly@8 99 'primary key' => array('aid', 'remnant'),
sly@8 100 );
sly@8 101 $schema['ad_channel_container'] = array(
sly@8 102 'description' => 'The ad_channel_container table stores channel container definitions.',
sly@8 103 'fields' => array(
sly@8 104 'conid' => array(
sly@8 105 'type' => 'serial',
sly@8 106 'not null' => TRUE,
sly@8 107 'unsigned' => TRUE,
sly@8 108 'description' => 'Unique container ID.',
sly@8 109 ),
sly@8 110 'name' => array(
sly@8 111 'type' => 'varchar',
sly@8 112 'length' => 64,
sly@8 113 'not null' => TRUE,
sly@8 114 'default' => '',
sly@8 115 'description' => 'The name of the container.',
sly@8 116 ),
sly@8 117 'description' => array(
sly@8 118 'type' => 'text',
sly@8 119 'size' => 'big',
sly@8 120 'not null' => FALSE,
sly@8 121 'description' => 'A description of the container.',
sly@8 122 ),
sly@8 123 'weight' => array(
sly@8 124 'type' => 'int',
sly@8 125 'size' => 'medium',
sly@8 126 'not null' => TRUE,
sly@8 127 'unsigned' => TRUE,
sly@8 128 'default' => 0,
sly@8 129 'description' => 'Used when displaying channels to admins, heavier weights sink to the bottom.',
sly@8 130 ),
sly@8 131 ),
sly@8 132 'primary key' => array('conid'),
sly@8 133 );
sly@8 134 $schema['ad_channel_node'] = array(
sly@8 135 'description' => 'The ad_channel_node table stores per node channel information.',
sly@8 136 'fields' => array(
sly@8 137 'chid' => array(
sly@8 138 'type' => 'int',
sly@8 139 'not null' => TRUE,
sly@8 140 'unsigned' => TRUE,
sly@8 141 'default' => 0,
sly@8 142 ),
sly@8 143 'nid' => array(
sly@8 144 'type' => 'int',
sly@8 145 'not null' => TRUE,
sly@8 146 'unsigned' => TRUE,
sly@8 147 'default' => 0,
sly@8 148 ),
sly@8 149 ),
sly@8 150 'primary key' => array('chid', 'nid'),
sly@8 151 'indexes' => array(
sly@8 152 'nid_chid' => array('nid', 'chid'),
sly@8 153 ),
sly@8 154 );
sly@8 155 $schema['ad_priority'] = array(
sly@8 156 'fields' => array(
sly@8 157 'aid' => array(
sly@8 158 'type' => 'int',
sly@8 159 'not null' => TRUE,
sly@8 160 'unsigned' => TRUE,
sly@8 161 'default' => 0,
sly@8 162 ),
sly@8 163 'priority' => array(
sly@8 164 'type' => 'int',
sly@8 165 'size' => 'tiny',
sly@8 166 'not null' => TRUE,
sly@8 167 'unsigned' => TRUE,
sly@8 168 'default' => 0,
sly@8 169 ),
sly@8 170 ),
sly@8 171 'primary key' => array('aid', 'priority'),
sly@8 172 );
sly@8 173 return $schema;
sly@8 174 }
sly@8 175
pierre@1 176 function ad_channel_install() {
sly@8 177 // Create tables
sly@8 178 drupal_install_schema('ad_channel');
pierre@1 179 }
pierre@1 180
pierre@1 181 /**
pierre@1 182 * Completely uninstall the ad channel module.
pierre@1 183 */
pierre@1 184 function ad_channel_uninstall() {
sly@8 185 // Drop tables
sly@8 186 drupal_uninstall_schema('ad_channel');
pierre@1 187 }
pierre@1 188
pierre@1 189 /**
pierre@1 190 * Populate the ad_priority table.
pierre@1 191 */
pierre@1 192 function ad_channel_update_6001() {
pierre@1 193 $ret = array();
pierre@1 194
pierre@1 195 $result = db_query('SELECT a.aid, p.priority FROM {ads} a LEFT JOIN {ad_priority} p ON a.aid = p.aid');
pierre@1 196 while ($ad = db_fetch_object($result)) {
pierre@1 197 if (!isset($ad->priority)) {
pierre@1 198 $ret[] = update_sql("INSERT INTO {ad_priority} (aid, priority) VALUES ($ad->aid, 0)");
pierre@1 199 }
pierre@1 200 }
pierre@1 201
pierre@1 202 return $ret;
pierre@1 203 }
pierre@1 204
sly@2 205 /**
sly@2 206 * Rebuild the menu so that channels and containers can be deleted.
sly@2 207 */
sly@2 208 function ad_channel_update_6002() {
sly@2 209 cache_clear_all();
sly@2 210 menu_rebuild();
sly@2 211 return array();
sly@2 212 }
sly@2 213
sly@2 214 /**
sly@2 215 * Introduce no_channel_weight.
sly@2 216 */
sly@2 217 function ad_channel_update_6003() {
sly@2 218 $ret = array();
sly@2 219 $ret[] = update_sql("ALTER TABLE {ad_channel} ADD no_channel_weight INT(3) NOT NULL DEFAULT '0'");
sly@2 220 return $ret;
sly@2 221 }
sly@2 222
piotre@7 223 /**
piotre@7 224 * Introduce no_channel_percent.
piotre@7 225 */
piotre@7 226 function ad_channel_update_6004() {
piotre@7 227 $ret = array();
piotre@7 228 $ret[] = update_sql("ALTER TABLE {ad_channel} CHANGE COLUMN no_channel_weight no_channel_percent INT(3) NOT NULL DEFAULT '0'");
piotre@7 229 // migration of no_channel_weights to no_channel_percent is an approximation
piotre@7 230 // to evenly distribute legacy values to new inorder to maintain weighting
piotre@7 231 $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=20 WHERE no_channel_percent=25");
piotre@7 232 $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=25 WHERE no_channel_percent=33");
piotre@7 233 $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=35 WHERE no_channel_percent=50");
piotre@7 234 $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=50 WHERE no_channel_percent=100");
piotre@7 235 $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=65 WHERE no_channel_percent=200");
piotre@7 236 $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=75 WHERE no_channel_percent=300");
piotre@7 237 $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=80 WHERE no_channel_percent=400");
piotre@7 238 return $ret;
piotre@7 239 }
piotre@7 240
piotre@7 241 /*
piotre@7 242 * Introduce channel inventory and remnant ads
piotre@7 243 */
piotre@7 244 function ad_channel_update_6005() {
piotre@7 245 $ret = array();
piotre@7 246 $ret[] = update_sql("ALTER TABLE {ad_channel} ADD inventory INT(11)");
piotre@7 247 $ret[] = update_sql("CREATE TABLE {ad_channel_remnant} (aid INT(11) UNSIGNED NOT NULL DEFAULT '0', remnant TINYINT UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY (aid, remnant))");
piotre@7 248 return $ret;
piotre@7 249 }