| 
franck@0
 | 
     1 <?php | 
| 
franck@2
 | 
     2 // $Id: og_statistics.install,v 1.2.2.1 2009/08/12 19:53:28 dereine Exp $ | 
| 
franck@0
 | 
     3  | 
| 
franck@0
 | 
     4 /** | 
| 
franck@0
 | 
     5  * @file | 
| 
franck@0
 | 
     6  *   Installs the og_statistics module. | 
| 
franck@0
 | 
     7  */ | 
| 
franck@0
 | 
     8  | 
| 
franck@0
 | 
     9 /** | 
| 
franck@0
 | 
    10  * Implemenation of hook_install(). | 
| 
franck@0
 | 
    11  */ | 
| 
franck@0
 | 
    12 function og_statistics_install() { | 
| 
franck@0
 | 
    13   drupal_install_schema('og_statistics'); | 
| 
franck@0
 | 
    14 } | 
| 
franck@0
 | 
    15  | 
| 
franck@0
 | 
    16 /** | 
| 
franck@0
 | 
    17  * Implemenation of hook_schema(). | 
| 
franck@0
 | 
    18  */ | 
| 
franck@0
 | 
    19 function og_statistics_schema() { | 
| 
franck@0
 | 
    20   $schema['og_statistics'] = array( | 
| 
franck@0
 | 
    21     'description' => 'Saves some statistics foreach group', | 
| 
franck@0
 | 
    22     'fields'          => array( | 
| 
franck@0
 | 
    23       'nid'             => array( | 
| 
franck@0
 | 
    24         'description'     => "The groups's {node}.nid.", | 
| 
franck@0
 | 
    25         'type'            => 'int', | 
| 
franck@0
 | 
    26         'size'            => 'normal', | 
| 
franck@0
 | 
    27         'not null'        => TRUE, | 
| 
franck@0
 | 
    28       ), | 
| 
franck@0
 | 
    29       'members_count' => array( | 
| 
franck@0
 | 
    30         'description' => 'How many members has a group', | 
| 
franck@0
 | 
    31         'type' => 'int', | 
| 
franck@0
 | 
    32         'size' => 'normal', | 
| 
franck@0
 | 
    33         'not null' => TRUE, | 
| 
franck@0
 | 
    34       ), | 
| 
franck@0
 | 
    35       'posts_count' => array( | 
| 
franck@0
 | 
    36         'description' => 'How many posts has a group', | 
| 
franck@0
 | 
    37         'type' => 'int', | 
| 
franck@0
 | 
    38         'size' => 'normal', | 
| 
franck@0
 | 
    39         'not null' => TRUE, | 
| 
franck@0
 | 
    40       ), | 
| 
franck@0
 | 
    41       'comments_count' => array( | 
| 
franck@0
 | 
    42         'description' => 'How many comments has a group', | 
| 
franck@0
 | 
    43         'type' => 'int', | 
| 
franck@0
 | 
    44         'size' => 'normal', | 
| 
franck@0
 | 
    45         'not null' => TRUE, | 
| 
franck@0
 | 
    46       ), | 
| 
franck@0
 | 
    47       'last_node_timestamp' => array( | 
| 
franck@0
 | 
    48         'description'     => 'Last Time when a in the group was created.', | 
| 
franck@0
 | 
    49         'type'            => 'int', | 
| 
franck@0
 | 
    50         'size'            => 'normal', | 
| 
franck@0
 | 
    51         'not null'        => FALSE, | 
| 
franck@0
 | 
    52         'default'         => 0, | 
| 
franck@0
 | 
    53       ), | 
| 
franck@0
 | 
    54       'last_comment_timestamp' => array( | 
| 
franck@0
 | 
    55         'description'     => 'Last Time when a comment in the group was created.', | 
| 
franck@0
 | 
    56         'type'            => 'int', | 
| 
franck@0
 | 
    57         'size'            => 'normal', | 
| 
franck@0
 | 
    58         'not null'        => FALSE, | 
| 
franck@0
 | 
    59         'default'         => 0, | 
| 
franck@0
 | 
    60       ), | 
| 
franck@0
 | 
    61       'last_member_timestamp' => array( | 
| 
franck@0
 | 
    62         'description'     => 'Last Time when a user joins a group.', | 
| 
franck@0
 | 
    63         'type'            => 'int', | 
| 
franck@0
 | 
    64         'size'            => 'normal', | 
| 
franck@0
 | 
    65         'not null'        => FALSE, | 
| 
franck@0
 | 
    66         'default'         => 0, | 
| 
franck@0
 | 
    67       ), | 
| 
franck@2
 | 
    68       'last_comment_uid' => array( | 
| 
franck@2
 | 
    69         'description' => 'Last {users}.uid to post a comment in a group.', | 
| 
franck@2
 | 
    70         'type' => 'int', | 
| 
franck@2
 | 
    71         'unsigned' => TRUE, | 
| 
franck@2
 | 
    72         'not null' => FALSE, | 
| 
franck@2
 | 
    73         'default' => 0, | 
| 
franck@2
 | 
    74       ), | 
| 
franck@2
 | 
    75       'last_comment_nid' => array( | 
| 
franck@2
 | 
    76         'description' => 'Node the last comment was posted to in a group.', | 
| 
franck@2
 | 
    77         'type' => 'int', | 
| 
franck@2
 | 
    78         'unsigned' => TRUE, | 
| 
franck@2
 | 
    79         'not null' => FALSE, | 
| 
franck@2
 | 
    80         'default' => 0, | 
| 
franck@2
 | 
    81       ), | 
| 
franck@2
 | 
    82       'last_comment_cid' => array( | 
| 
franck@2
 | 
    83         'description' => '{comments}.cid of the last comment in a group.', | 
| 
franck@2
 | 
    84         'type' => 'int', | 
| 
franck@2
 | 
    85         'unsigned' => TRUE, | 
| 
franck@2
 | 
    86         'not null' => FALSE, | 
| 
franck@2
 | 
    87         'default' => 0, | 
| 
franck@2
 | 
    88       ), | 
| 
franck@2
 | 
    89       'last_node_nid' => array( | 
| 
franck@2
 | 
    90         'description' => 'Last {node}.nid posted to a group.', | 
| 
franck@2
 | 
    91         'type' => 'int', | 
| 
franck@2
 | 
    92         'unsigned' => TRUE, | 
| 
franck@2
 | 
    93         'not null' => FALSE, | 
| 
franck@2
 | 
    94         'default' => 0, | 
| 
franck@2
 | 
    95       ), | 
| 
franck@2
 | 
    96       'last_node_uid' => array( | 
| 
franck@2
 | 
    97         'description' => '{users}.uid of the last node posted to a group.', | 
| 
franck@2
 | 
    98         'type' => 'int', | 
| 
franck@2
 | 
    99         'unsigned' => TRUE, | 
| 
franck@2
 | 
   100         'not null' => FALSE, | 
| 
franck@2
 | 
   101         'default' => 0, | 
| 
franck@2
 | 
   102       ), | 
| 
franck@2
 | 
   103       'last_member_uid' => array( | 
| 
franck@2
 | 
   104         'description' => '{users}.uid of the last user to join a group.', | 
| 
franck@2
 | 
   105         'type' => 'int', | 
| 
franck@2
 | 
   106         'unsigned' => TRUE, | 
| 
franck@2
 | 
   107         'not null' => FALSE, | 
| 
franck@2
 | 
   108         'default' => 0, | 
| 
franck@2
 | 
   109       ), | 
| 
franck@0
 | 
   110     ), | 
| 
franck@0
 | 
   111     'primary key' => array('nid'), | 
| 
franck@0
 | 
   112   ); | 
| 
franck@0
 | 
   113  | 
| 
franck@0
 | 
   114   return $schema; | 
| 
franck@0
 | 
   115 } | 
| 
franck@0
 | 
   116  | 
| 
franck@0
 | 
   117 /** | 
| 
franck@0
 | 
   118  * Implemenation of hook_uninstall(). | 
| 
franck@0
 | 
   119  */ | 
| 
franck@0
 | 
   120 function og_statistics_uninstall() { | 
| 
franck@0
 | 
   121   drupal_uninstall_schema('og_statistics'); | 
| 
franck@0
 | 
   122 } | 
| 
franck@2
 | 
   123  | 
| 
franck@2
 | 
   124 /** | 
| 
franck@2
 | 
   125  * Adds more verbose og statistics. | 
| 
franck@2
 | 
   126  */ | 
| 
franck@2
 | 
   127 function og_statistics_update_6001() { | 
| 
franck@2
 | 
   128   $ret = array(); | 
| 
franck@2
 | 
   129   $schema = drupal_get_schema_unprocessed('og_statistics'); | 
| 
franck@2
 | 
   130   $table_definition = $schema['og_statistics']; | 
| 
franck@2
 | 
   131   // Add detailed columns for last comment post. | 
| 
franck@2
 | 
   132   foreach (array('last_comment_uid', 'last_comment_nid', 'last_comment_cid') as $column) { | 
| 
franck@2
 | 
   133     if (!db_column_exists('og_statistics', $column)) { | 
| 
franck@2
 | 
   134       db_add_field($ret, 'og_statistics', $column, $table_definition['fields'][$column]); | 
| 
franck@2
 | 
   135     } | 
| 
franck@2
 | 
   136   } | 
| 
franck@2
 | 
   137   // Add detailed columns for last node post. | 
| 
franck@2
 | 
   138   foreach (array('last_node_uid', 'last_node_nid') as $column) { | 
| 
franck@2
 | 
   139     if (!db_column_exists('og_statistics', $column)) { | 
| 
franck@2
 | 
   140       db_add_field($ret, 'og_statistics', $column, $table_definition['fields'][$column]); | 
| 
franck@2
 | 
   141     } | 
| 
franck@2
 | 
   142   } | 
| 
franck@2
 | 
   143   // Add detailed columns for last user to join. | 
| 
franck@2
 | 
   144   foreach (array('last_member_uid') as $column) { | 
| 
franck@2
 | 
   145     if (!db_column_exists('og_statistics', $column)) { | 
| 
franck@2
 | 
   146       db_add_field($ret, 'og_statistics', $column, $table_definition['fields'][$column]); | 
| 
franck@2
 | 
   147     } | 
| 
franck@2
 | 
   148   } | 
| 
franck@2
 | 
   149   // Rebuild schema. | 
| 
franck@2
 | 
   150   drupal_get_schema('og_statistics', TRUE); | 
| 
franck@2
 | 
   151 } |