pierre@0: . pierre@0: */ pierre@0: pierre@0: /** pierre@0: * Ad module database schema. pierre@0: */ pierre@0: function ad_schema() { pierre@0: /** pierre@0: * The ad table stores administrative information about each ad. The pierre@0: * actual ad itself can be found in the appropriate ad type table. pierre@0: */ pierre@0: $schema['ads'] = array( pierre@0: 'description' => 'The ad table stores administrative information about each ad. The actual ad itself can be found in the appropriate ad type table.', pierre@0: 'fields' => array( pierre@0: 'aid' => array( pierre@0: 'type' => 'int', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => 'Unique ad ID. Equals to ad nid.', pierre@0: ), pierre@0: 'uid' => array( pierre@0: 'type' => 'int', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.', pierre@0: ), pierre@0: 'adstatus' => array( pierre@0: 'type' => 'varchar', pierre@0: 'length' => 255, pierre@0: 'not null' => TRUE, pierre@0: 'default' => '', pierre@0: 'description' => 'Ad status', pierre@0: ), pierre@0: 'adtype' => array( pierre@0: 'type' => 'varchar', pierre@0: 'length' => 255, pierre@0: 'not null' => TRUE, pierre@0: 'default' => '', pierre@0: 'description' => 'Ad type', pierre@0: ), pierre@0: 'redirect' => array( pierre@0: 'type' => 'varchar', pierre@0: 'length' => 255, pierre@0: 'not null' => TRUE, pierre@0: 'default' => '', pierre@0: 'description' => 'Ad redirect URL', pierre@0: ), pierre@0: 'autoactivate' => array( pierre@0: 'type' => 'int', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => 'Is ad autoactivating?', pierre@0: ), pierre@0: 'autoactivated' => array( pierre@0: 'type' => 'int', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => 'Is ad autoactivated?', pierre@0: ), pierre@0: 'autoexpire' => array( pierre@0: 'type' => 'int', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => 'Is ad autoexpiring?', pierre@0: ), pierre@0: 'autoexpired' => array( pierre@0: 'type' => 'int', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => 'Is ad autoexpired?', pierre@0: ), pierre@0: 'activated' => array( pierre@0: 'type' => 'int', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => 'Is ad activated?', pierre@0: ), pierre@0: 'maxviews' => array( pierre@0: 'type' => 'int', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => 'Maximum ad impressions', pierre@0: ), pierre@0: 'maxclicks' => array( pierre@0: 'type' => 'int', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => 'Maximum ad clicks', pierre@0: ), pierre@0: 'expired' => array( pierre@0: 'type' => 'int', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => 'Is ad expired?', pierre@0: ), pierre@0: ), pierre@0: 'primary key' => array('aid'), pierre@0: 'indexes' => array( pierre@0: 'uid' => array('uid'), pierre@0: 'autoactivate' => array('autoactivate'), pierre@0: 'autoactivate' => array('autoactivate'), pierre@0: ), pierre@0: ); pierre@0: pierre@0: /** pierre@0: * This table counts each time a given action occurs on an ad. Actions pierre@0: * include when the ad is viewed, clicked, enabled and disabled. pierre@0: * Statistics are collected at an hourly granularity. pierre@0: * pierre@0: * The source column is used for tracking statistics for externally pierre@0: * hosted ads. pierre@0: * pierre@0: * Actions: pierre@0: * 'view', 'click', 'enable', 'disable' pierre@0: */ pierre@0: $schema['ad_statistics'] = array( pierre@0: 'description' => 'Stores ad statistics.', pierre@0: 'fields' => array( pierre@0: 'sid' => array( pierre@0: 'type' => 'serial', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'description' => 'Statistics entry ID.', pierre@0: ), pierre@0: 'aid' => array( pierre@0: 'type' => 'int', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => 'Ad id.', pierre@0: ), pierre@0: 'date' => array( pierre@0: 'type' => 'int', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => 'Date when action was made.', pierre@0: ), pierre@0: 'action' => array( pierre@0: 'type' => 'varchar', pierre@0: 'length' => 255, pierre@0: 'not null' => TRUE, pierre@0: 'default' => '', pierre@0: 'description' => 'Actions: "view", "click", "enable", "disable".', pierre@0: ), pierre@0: 'adgroup' => array( pierre@0: 'type' => 'varchar', pierre@0: 'length' => 255, pierre@0: 'not null' => FALSE, pierre@0: 'default' => '', pierre@0: 'description' => 'Ad group.', pierre@0: ), pierre@0: 'hostid' => array( pierre@0: 'type' => 'varchar', pierre@0: 'length' => 32, pierre@0: 'not null' => TRUE, pierre@0: 'default' => '', pierre@0: 'description' => 'Host from which acion was made.', pierre@0: ), pierre@0: 'count' => array( pierre@0: 'type' => 'int', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => 'Count of actions triggered.', pierre@0: ), pierre@0: ), pierre@0: 'primary key' => array('sid'), pierre@0: 'indexes' => array( pierre@0: 'aid' => array('aid'), pierre@0: 'date' => array('date'), pierre@0: 'action' => array('action'), pierre@0: 'adgroup' => array('adgroup'), pierre@0: 'hostid' => array('hostid'), pierre@0: ), pierre@0: ); pierre@0: pierre@0: /** pierre@0: * The ad_clicks table tracks when a given advertisement was clicked, pierre@0: * who clicked it (uid if any and IP address), and what page they were pierre@0: * on when they clicked it. pierre@0: */ pierre@0: $schema['ad_clicks'] = array( pierre@0: 'description' => 'The ad_clicks table tracks when a given advertisement was clicked, who clicked it (uid if any and IP address), and what page they were on when they clicked it.', pierre@0: 'fields' => array( pierre@0: 'cid' => array( pierre@0: 'type' => 'serial', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'description' => 'Statistics entry ID.', pierre@0: ), pierre@0: 'aid' => array( pierre@0: 'type' => 'int', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => 'Ad id.', pierre@0: ), pierre@0: 'uid' => array( pierre@0: 'type' => 'int', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => '', pierre@0: ), pierre@0: 'status' => array( pierre@0: 'type' => 'int', pierre@0: 'size' => 'tiny', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => '', pierre@0: ), pierre@0: 'hostname' => array( pierre@0: 'type' => 'varchar', pierre@0: 'length' => 128, pierre@0: 'not null' => TRUE, pierre@0: 'default' => '', pierre@0: 'description' => 'Host from which acion was made.', pierre@0: ), pierre@0: 'user_agent' => array( pierre@0: 'type' => 'varchar', pierre@0: 'length' => 255, pierre@0: 'not null' => TRUE, pierre@0: 'default' => '', pierre@0: 'description' => 'Clicker\'s browser agent.', pierre@0: ), pierre@0: 'adgroup' => array( pierre@0: 'type' => 'varchar', pierre@0: 'length' => 255, pierre@0: 'not null' => TRUE, pierre@0: 'default' => '', pierre@0: 'description' => 'Ad group.', pierre@0: ), pierre@0: 'hostid' => array( pierre@0: 'type' => 'varchar', pierre@0: 'length' => 32, pierre@0: 'not null' => TRUE, pierre@0: 'default' => '', pierre@0: 'description' => 'Host from which acion was made.', pierre@0: ), pierre@0: 'url' => array( pierre@0: 'type' => 'varchar', pierre@0: 'length' => 255, pierre@0: 'not null' => FALSE, pierre@0: 'default' => '', pierre@0: 'description' => 'Clicked URL.', pierre@0: ), pierre@0: 'timestamp' => array( pierre@0: 'type' => 'int', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => 'Date when action was made.', pierre@0: ), pierre@0: ), pierre@0: 'primary key' => array('cid'), pierre@0: 'indexes' => array( pierre@0: 'aid' => array('aid'), pierre@0: 'status' => array('status'), pierre@0: 'hostname' => array('hostname'), pierre@0: 'user_agent' => array('user_agent'), pierre@0: 'adgroup' => array('adgroup'), pierre@0: 'hostid' => array('hostid'), pierre@0: 'url' => array('url'), pierre@0: ), pierre@0: ); pierre@0: pierre@0: return $schema; pierre@0: } pierre@0: pierre@0: /** pierre@0: * Ad module installation. pierre@0: */ pierre@0: function ad_install() { pierre@0: // Create tables. pierre@0: drupal_install_schema('ad'); pierre@0: } pierre@0: pierre@0: /** pierre@0: * Allow complete uninstallation of the ad module. pierre@0: */ pierre@0: function ad_uninstall() { pierre@0: // Delete all ad content. pierre@0: $result = db_query("SELECT nid FROM {node} WHERE type = 'ad'"); pierre@0: while ($node = db_fetch_object($result)) { pierre@0: node_delete($node->nid); pierre@0: variable_del("ad_autoactivate_warning_$node->nid"); pierre@0: } pierre@0: pierre@0: // Delete all remaining ad module variables. pierre@0: $variables = array('ad_cron_timestamp', 'ad_link_target', 'ad_cache', 'ad_cache_file', 'adserve', 'ad_group_vid', 'ad_groups', 'ad_validate_url', 'ad_display'); pierre@0: foreach ($variables as $variable) { pierre@0: variable_del($variable); pierre@0: } pierre@0: db_query("DELETE FROM {variable} WHERE name LIKE 'ad_block_quantity_%'"); pierre@1: pierre@1: // Remove tables. pierre@1: drupal_uninstall_schema('ad'); pierre@0: } pierre@0: pierre@0: /** pierre@0: * Convert some things from absolete dev. schema to new schema API pierre@0: */ pierre@0: function ad_update_6001() { pierre@0: $ret = array(); pierre@0: // When we touching index columns, we should first remove it from schema pierre@0: db_drop_index($ret, 'ad_clicks', 'status'); pierre@0: db_change_field($ret, 'ad_clicks', 'status', 'status', pierre@0: array( pierre@0: 'type' => 'int', pierre@0: 'size' => 'tiny', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => '', pierre@0: ), pierre@0: array('indexes' => array( pierre@0: 'status' => array('status'), pierre@0: ), pierre@0: ) pierre@0: ); pierre@0: db_drop_index($ret, 'ad_hosts', 'status'); pierre@0: db_change_field($ret, 'ad_hosts', 'status', 'status', pierre@0: array( pierre@0: 'type' => 'int', pierre@0: 'size' => 'tiny', pierre@0: 'not null' => TRUE, pierre@0: 'unsigned' => TRUE, pierre@0: 'default' => 0, pierre@0: 'description' => '', pierre@0: ), pierre@0: array('indexes' => array( pierre@0: 'status' => array('status'), pierre@0: ), pierre@0: ) pierre@0: ); pierre@0: pierre@0: db_drop_index($ret, 'ad_statistics', 'hostid'); pierre@0: db_change_field($ret, 'ad_statistics', 'hostid', 'hostid', pierre@0: array( pierre@0: 'type' => 'varchar', pierre@0: 'length' => 32, pierre@0: 'not null' => TRUE, pierre@0: 'default' => '', pierre@0: 'description' => 'Host from which acion was made.', pierre@0: ), pierre@0: array('indexes' => array( pierre@0: 'hostid' => array('hostid'), pierre@0: ), pierre@0: ) pierre@0: ); pierre@0: pierre@0: db_drop_index($ret, 'ad_hosts', 'hostid'); pierre@0: db_change_field($ret, 'ad_hosts', 'hostid', 'hostid', pierre@0: array( pierre@0: 'type' => 'varchar', pierre@0: 'length' => 32, pierre@0: 'not null' => TRUE, pierre@0: 'default' => '', pierre@0: 'description' => 'Host from which acion was made.', pierre@0: ), pierre@0: array('indexes' => array( pierre@0: 'hostid' => array('hostid'), pierre@0: ), pierre@0: ) pierre@0: ); pierre@0: return $ret; pierre@0: } pierre@0: pierre@0: /** pierre@0: * Rebuild menu for anyone using the ad_embed module. pierre@0: */ pierre@0: function ad_update_6002() { pierre@0: menu_rebuild(); pierre@0: return array(); pierre@0: } pierre@0: pierre@0: /** pierre@0: * Flush all caches for new themeable ad display functions. pierre@0: */ pierre@0: function ad_update_6003() { pierre@0: drupal_flush_all_caches(); pierre@0: return array(); pierre@0: } pierre@1: pierre@1: /** pierre@1: * Introduce "extra" field for ad statistics and clicks, optionally allowing pierre@1: * add-on modules to provide additional granularity. pierre@1: */ pierre@1: function ad_update_6004() { pierre@1: $ret = array(); pierre@1: db_add_field($ret, 'ad_statistics', 'extra', pierre@1: array( pierre@1: 'type' => 'varchar', pierre@1: 'length' => 255, pierre@1: 'not null' => TRUE, pierre@1: 'default' => '', pierre@1: 'description' => 'Alow add-on modules to provide additional statistics granularity.', pierre@1: ), pierre@1: array('indexes' => array( pierre@1: 'extra' => array('extra')) pierre@1: )); pierre@1: db_add_field($ret, 'ad_clicks', 'extra', pierre@1: array( pierre@1: 'type' => 'varchar', pierre@1: 'length' => 255, pierre@1: 'not null' => TRUE, pierre@1: 'default' => '', pierre@1: 'description' => 'Alow add-on modules to provide additional statistics granularity.', pierre@1: ), pierre@1: array('indexes' => array( pierre@1: 'extra' => array('extra')) pierre@1: )); pierre@1: return $ret; pierre@1: } pierre@1: pierre@1: /** pierre@1: * Flush all caches for AHAH ad type switcher to work. pierre@1: */ pierre@1: function ad_update_6005() { pierre@1: drupal_flush_all_caches(); pierre@1: return array(); pierre@1: } pierre@1: