/[drupal]/contributions/modules/akismet/akismet.install
ViewVC logotype

Diff of /contributions/modules/akismet/akismet.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.3 by drewish, Fri Jun 1 21:41:17 2007 UTC revision 1.4 by drewish, Mon Mar 24 23:31:16 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: akismet.install,v 1.2 2006/12/28 19:00:03 eaton Exp $  // $Id: akismet.install,v 1.3 2007/06/01 21:41:17 drewish Exp $
3    
4    /**
5     * Implementation of hook_schema().
6     */
7    function akismet_schema() {
8      $schema['akismet_spam_marks'] = array(
9        'fields' => array(
10          'content_type' => array(
11            'type' => 'varchar',
12            'length' => 20,
13            'not null' => TRUE,
14            'default' => '',
15          ),
16          'content_id' => array(
17            'type' => 'int',
18            'unsigned' => TRUE,
19            'not null' => TRUE,
20            'default' => 0,
21          ),
22          'spam_created' => array(
23            'type' => 'int',
24            'unsigned' => TRUE,
25            'not null' => TRUE,
26            'default' => 0,
27          ),
28          'hostname' => array(
29            'type' => 'varchar',
30            'length' => 128,
31            'not null' => TRUE,
32            'default' => '',
33          ),
34          'mail' => array(
35            'type' => 'varchar',
36            'length' => 128,
37            'not null' => TRUE,
38            'default' => '',
39          ),
40        ),
41        'unique key' => array(
42          'content' => array('content_type', 'content_id'),
43        ),
44        'indexes' => array(
45          'spam_created' => array('spam_created'),
46          'hostname' => array('hostname'),
47          'mail' => array('mail'),
48        ),
49      );
50      $schema['akismet_moderator'] = array(
51        'fields' => array(
52          'uid' => array(
53            'type' => 'int',
54            'unsigned' => TRUE,
55            'not null' => TRUE,
56            'default' => 0,
57          ),
58          'email_for' => array(
59            'type' => 'varchar',
60            'length' => 20,
61            'not null' => TRUE,
62            'default' => '',
63          ),
64        ),
65        'primary key' => array('uid'),
66        'indexes' => array(
67          'email_for' => array('email_for'),
68        ),
69      );
70      return $schema;
71    }
72    
73  /**  /**
74   * Implementation of hook_install().   * Implementation of hook_install().
75   */   */
76  function akismet_install() {  function akismet_install() {
77    switch ($GLOBALS['db_type']) {    drupal_install_schema('akismet');
78      case 'mysql':  }
79      case 'mysqli':  
80        db_query("CREATE TABLE {akismet_spam_marks} (  /**
81            content_type varchar(20) NOT NULL default '',   * Implementation of hook_uninstall().
82            content_id int(10) unsigned NOT NULL default 0,   */
83            spam_created int(11) unsigned NOT NULL default 0,  function akismet_uninstall() {
84            hostname varchar(128) NOT NULL default '',    drupal_uninstall_schema('akismet');
           mail varchar(128) NOT NULL default '',  
           UNIQUE content (content_type, content_id),  
           INDEX spam_created (spam_created),  
           INDEX hostname (hostname),  
           INDEX mail (mail)  
         ) /*!40100 DEFAULT CHARACTER SET utf8 */;");  
       db_query("CREATE TABLE {akismet_moderator} (  
           uid int(10) unsigned NOT NULL default 0,  
           email_for varchar(20) NOT NULL default '',  
           PRIMARY KEY (uid),  
           INDEX email_for (email_for)  
         ) /*!40100 DEFAULT CHARACTER SET utf8 */;");  
       break;  
   
     case 'pgsql':  
       db_query("CREATE TABLE {akismet_spam_marks} (  
           content_type varchar(20) NOT NULL default '',  
           content_id integer NOT NULL default 0 CHECK (content_id >= 0),  
           spam_created integer NOT NULL default 0 CHECK (spam_created >= 0),  
           hostname varchar(128) NOT NULL default '',  
           mail varchar(128) NOT NULL default ''  
         )");  
       db_query("CREATE UNIQUE INDEX {akismet_spam_marks_content} ON {akismet_spam_marks} (content_type, content_id)");  
       db_query("CREATE INDEX {akismet_spam_marks_spamcreated} ON {akismet_spam_marks} (spam_created)");  
       db_query("CREATE INDEX {akismet_spam_marks_hostname} ON {akismet_spam_marks} (hostname)");  
       db_query("CREATE INDEX {akismet_spam_marks_mail} ON {akismet_spam_marks} (mail)");  
       db_query("CREATE TABLE {akismet_moderator} (  
           uid INTEGER NOT NULL DEFAULT 0 CHECK (uid >= 0),  
           email_for VARCHAR(20) NOT NULL DEFAULT '',  
           PRIMARY KEY (uid)  
         )");  
       db_query("CREATE INDEX {akismet_moderator_email_for} ON {akismet_moderator} (email_for)");  
       break;  
   }  
85  }  }
86    
87  /**  /**
88   * Update 1: Add table for moderator extensions.   * Update 1: Add table for moderator extensions.
89   */   */
90  function akismet_update_1() {  function akismet_update_1() {
91    $ret = array();    $schema['akismet_moderator'] = array(
92        'field' => array(
93    switch ($GLOBALS['db_type']) {        'uid' => array(
94      case 'mysql':          'type' => 'int',
95      case 'mysqli':          'unsigned' => TRUE,
96        $ret[] = update_sql("CREATE TABLE {akismet_moderator} (          'not null' => TRUE,
97            uid int(10) unsigned NOT NULL default 0,          'default' => 0,
98            email_for varchar(20) NOT NULL default '',        ),
99            PRIMARY KEY (uid),        'email_for' => array(
100            INDEX email_for (email_for)          'type' => 'varchar',
101          ) /*!40100 DEFAULT CHARACTER SET utf8 */;");          'length' => 20,
102        break;          'not null' => TRUE,
103            'default' => '',
104      case 'pgsql':        ),
105        $ret[] = update_sql("CREATE TABLE {akismet_moderator} (      ),
106            uid INTEGER NOT NULL DEFAULT 0 CHECK (uid >= 0),      'primary key' => array('uid'),
107            email_for VARCHAR(20) NOT NULL DEFAULT '',      'indexes' => array(
108            PRIMARY KEY (uid)        'email_for' => array('email_for'),
109          )");      ),
110        $ret[] = update_sql("CREATE INDEX {akismet_moderator_email_for} ON {akismet_moderator} (email_for)");    );
       break;  
   }  
111    
112      $ret = array();
113      db_create_table($ret, 'akismet_moderator', $schema['akismet_moderator']);
114    return $ret;    return $ret;
115  }  }
116    
# Line 85  function akismet_update_1() { Line 120  function akismet_update_1() {
120  function akismet_update_2() {  function akismet_update_2() {
121    $ret = array();    $ret = array();
122    
123    switch ($GLOBALS['db_type']) {    db_add_field($ret, 'akismet_spam_marks', 'hostname', array(
124      case 'mysql':      'type' => 'varchar',
125      case 'mysqli':      'length' => 128,
126        $ret[] = update_sql("ALTER TABLE {akismet_spam_marks} ADD COLUMN hostname varchar(128) NOT NULL default ''");      'not null' => TRUE,
127        $ret[] = update_sql("ALTER TABLE {akismet_spam_marks} ADD INDEX hostname (hostname)");      'default' => '',
128      ));
129        $ret[] = update_sql("ALTER TABLE {akismet_spam_marks} ADD COLUMN mail varchar(128) NOT NULL default ''");    db_add_index($ret, 'akismet_spam_marks', 'hostname', array('hostname'));
130        $ret[] = update_sql("ALTER TABLE {akismet_spam_marks} ADD INDEX mail (mail)");  
131        break;    db_add_field($ret, 'akismet_spam_marks', 'mail', array(
132        'type' => 'varchar',
133      case 'pgsql':      'length' => 128,
134        $ret[] = update_sql("ALTER TABLE {akismet_spam_marks} ADD COLUMN hostname VARCHAR(128)");      'not null' => TRUE,
135        $ret[] = update_sql("ALTER TABLE {akismet_spam_marks} ALTER COLUMN hostname SET DEFAULT ''");      'default' => '',
136        $ret[] = update_sql("UPDATE TABLE {akismet_spam_marks} SET hostname = '' WHERE hostname IS NULL");    ));
137        $ret[] = update_sql("ALTER TABLE {akismet_spam_marks} ALTER COLUMN hostname SET NOT NULL");    db_add_index($ret, 'akismet_spam_marks', 'mail', array('mail'));
       $ret[] = update_sql("CREATE INDEX {akismet_spam_marks_hostname} ON {akismet_spam_marks} (hostname)");  
   
       $ret[] = update_sql("ALTER TABLE {akismet_spam_marks} ADD COLUMN mail VARCHAR(128)");  
       $ret[] = update_sql("ALTER TABLE {akismet_spam_marks} ALTER COLUMN mail SET DEFAULT ''");  
       $ret[] = update_sql("UPDATE TABLE {akismet_spam_marks} SET mail = '' WHERE mail IS NULL");  
       $ret[] = update_sql("ALTER TABLE {akismet_spam_marks} ALTER COLUMN mail SET NOT NULL");  
       $ret[] = update_sql("CREATE INDEX {akismet_spam_marks_mail} ON {akismet_spam_marks} (mail)");  
       break;  
   }  
138    
139    return $ret;    return $ret;
140  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.3