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

Diff of /contributions/modules/false_account/false_account.install

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

revision 1.3, Wed Oct 15 16:20:08 2008 UTC revision 1.4, Wed Oct 15 16:37:32 2008 UTC
# Line 2  Line 2 
2  // $Id: false_account.install,v 1.2 2008/03/08 14:59:31 introfini Exp $  // $Id: false_account.install,v 1.2 2008/03/08 14:59:31 introfini Exp $
3    
4  /**  /**
5     * @file
6     * Schema installation for false account module
7     */
8    
9    /**
10   * Implementation of hook_install()   * Implementation of hook_install()
  * just give a message  
11   */   */
12  function false_account_install() {  function false_account_install() {
13    switch ($GLOBALS['db_type']) {    $created = drupal_install_schema('false_account');
     case 'mysql':  
     case 'mysqli':  
       $created = db_query("  
         CREATE TABLE IF NOT EXISTS {false_accounts} (  
         cid varchar(64) NOT NULL,  
         uid int(10) NOT NULL,  
         created int(11) unsigned NOT NULL default '0',  
         status tinyint(3) unsigned NOT NULL default '0',  
         PRIMARY KEY (cid, uid)  
       ) /*!40100 DEFAULT CHARACTER SET utf8 */;");  
       break;  
   }  
14    
15    if ($created) {          print_r('aqui');
16            print_r($created);
17    
18      if ($created['success']) {
19      drupal_set_message(t('False Account module installed successfully.'));      drupal_set_message(t('False Account module installed successfully.'));
20    }    }
21    else {    else {
22      drupal_set_message(t('Table installation for the False Accounts module was unsuccessful.'), 'error');      drupal_set_message(t('Table installation for the False Accounts module was unsuccessful.'), 'error');
23    }    }
24    
25  }  }
26    
27    
28  /**  /**
29   * Implementation of hook_update_N()   * Implementation of hook_schema()
  * new DB structure  
30   */   */
31  function false_account_update_1() {  function false_account_schema() {
32    $schema['false_accounts'] = array(
33    $return = array();    'fields' => array(
34    $done = array();      'cid' => array('type' => 'varchar', 'length' => '64', 'not null' => TRUE),
35        'uid' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '10'),
36    // replicate table      'created' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0,
37    $result = db_query('        'disp-width' => '11'),
38      CREATE TABLE IF NOT EXISTS {false_accounts_old}      'status' => array('type' => 'int', 'unsigned' => TRUE, 'size' => 'tiny', 'not null' => TRUE,
39      LIKE {false_accounts}'        'default' => 0, 'disp-width' => '3')
40    );    ),
41    $done[] = $result;    'primary key' => array('cid', 'uid'),
42    );
   $result = db_query('  
     INSERT {false_accounts_old}  
     SELECT *  
     FROM {false_accounts}'  
   );  
   $done[] = $result;  
43    
44    // avoid data destruction if copy actions haven't succeed    return $schema;
   if (! in_array(false, $done)) {  
     $done = array();  
   
     $result = db_query('DROP TABLE {false_accounts}');  
     $done[] = $result;  
   
     $created = db_query("  
       CREATE TABLE IF NOT EXISTS {false_accounts} (  
       cid varchar(64) NOT NULL,  
       uid int(10) NOT NULL,  
       created int(11) unsigned NOT NULL default '0',  
       status tinyint(3) unsigned NOT NULL default '0',  
       PRIMARY KEY (cid, uid)  
     ) /*!40100 DEFAULT CHARACTER SET utf8 */;");  
                 $done[] = $result;  
   
     $result = db_query('  
       SELECT *  
       FROM {false_accounts_old}'  
     );  
   
     // handle old data to fit into new table and instert  
     while ($row = db_fetch_object($result)) {  
                         if ($row->cid != '' && $row->uids != '' && $row->status >= 0) {  
                                 $uids = explode(',', $row->uids);  
   
                                 for ($i = 0 ; $i < sizeof($uids) ; $i++) {  
                                         $res = db_query('  
                                                 INSERT INTO {false_accounts} (cid, uid, created, status)  
                                                 VALUES ("%s", %d, %d, %d)',  
                                                 $row->cid, $uids[$i], $row->updated, $row->status  
                                         );  
                                         $done[] = $res;  
                                 }  
                         }  
     }  
     if (! in_array(false, $done)) {  
       drupal_set_message(t('False Account module upgraded successfully.'));  
     }  
     else {  
       drupal_set_message(t('Table upgrade for the False Accounts module was unsuccessful.'),  
         'error');  
     }  
   }  
   else {  
     drupal_set_message(t('Table upgrade for the False Accounts module was unsuccessful.'), 'error');  
   }  
   
         return $return;  
45  }  }
46    
47    

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

  ViewVC Help
Powered by ViewVC 1.1.2