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

Contents of /contributions/modules/counter/counter.install

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


Revision 1.7 - (show annotations) (download) (as text)
Mon Oct 26 04:58:57 2009 UTC (4 weeks, 2 days ago) by thenicespider
Branch: MAIN
CVS Tags: DRUPAL-6--2-2
Changes since 1.6: +21 -1 lines
File MIME type: text/x-php
6.x-2.2: New: Show Block/Unblock Users
         New: Redesign "Counter Settings" page
         New: Variable to show how many items per page on Counter Report
         Bug fix: Error on Counter Report when i18n module enable
1 <?php
2 // $Id: counter.install,v 1.6 2009/10/07 04:33:37 thenicespider Exp $
3 /**
4 * Install the module with a new database table
5 * @file
6 */
7
8 function counter_install() {
9 drupal_set_message('Installing Counter module');
10 drupal_install_schema('counter');
11 counter_update_6000();
12 counter_update_6001();
13 counter_update_6002();
14 }
15
16 function counter_uninstall() {
17 drupal_uninstall_schema('counter');
18 }
19
20 /**
21 * Implementation of hook_schema().
22 */
23 function counter_schema() {
24 $schema['counter'] = array(
25 'fields' => array(
26 'counter_id' => array(
27 'type' => 'serial',
28 'not null' => TRUE,
29 ),
30 'counter_ip' => array(
31 'type' => 'varchar',
32 'length' => 32,
33 'not null' => TRUE,
34 'default' => '',
35 ),
36 'counter_date' => array(
37 'type' => 'varchar',
38 'length' => 32,
39 'not null' => TRUE,
40 'default' => '',
41 ),
42 'counter_page' => array(
43 'type' => 'varchar',
44 'length' => 255,
45 'not null' => TRUE,
46 'default' => '0',
47 ),
48 ),
49 'primary key' => array('counter_id'),
50 );
51
52 $schema['counter_data'] = array(
53 'fields' => array(
54 'counter_name' => array('type' => 'varchar','length' => 255,'not null' => TRUE,'default' => 0),
55 'counter_value' => array('type' => 'varchar','length' => 255,'not null' => TRUE,'default' => 0),
56 ),
57 'primary key' => array('counter_name'),
58 );
59 // site_counter, unique_visitor, registered_user, unregistered_user, published_node, unpublished_node
60 return $schema;
61 }
62
63 function counter_update_6000() {
64 $ret = array();
65
66 if (db_column_exists('counter', 'counter_page')) {
67 db_change_field($ret, 'counter', 'counter_page', 'counter_page', array('type' => 'varchar', 'length' => '255','not null' => TRUE, 'default' => '0'));
68 }
69 return $ret;
70 }
71
72 function counter_update_6001() {
73 $ret = array();
74 $schema = counter_schema();
75 _drupal_initialize_schema('counter', $schema);
76
77 foreach ($schema as $name => $table) {
78 if (!db_table_exists($name)) {
79 db_create_table($ret, $name, $table);
80 }
81 }
82 //site_counter
83 $sql = " SELECT count(*) as total FROM {counter} c ";
84 $data = db_fetch_object(db_query($sql));
85 $counter_total = $data->total;
86
87 $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'site_counter' ";
88 $counter_data = db_fetch_object(db_query($sql));
89 $counter_name_exist = $counter_data->total;
90
91 if (!$counter_name_exist) {
92 $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('%s','%s')";
93 $results = db_query($sql,"site_counter",$counter_total);
94 }
95 //unique_visitor
96 $sql = " SELECT count(*) as total FROM (SELECT counter_ip FROM {counter} GROUP BY counter_ip) c";
97 $data = db_fetch_object(db_query($sql));
98 $counter_total = $data->total;
99
100 $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'unique_visitor' ";
101 $counter_data = db_fetch_object(db_query($sql));
102 $counter_name_exist = $counter_data->total;
103
104 if (!$counter_name_exist) {
105 $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('%s','%s')";
106 $results = db_query($sql,"unique_visitor",$counter_total);
107 }
108 //registered_user
109 $sql = " SELECT count(*) as total FROM {users} WHERE access<>0 and uid<>0";
110 $data = db_fetch_object(db_query($sql));
111 $counter_total = $data->total;
112
113 $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'registered_user' ";
114 $counter_data = db_fetch_object(db_query($sql));
115 $counter_name_exist = $counter_data->total;
116
117 if (!$counter_name_exist) {
118 $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('%s','%s')";
119 $results = db_query($sql,"registered_user",$counter_total);
120 }
121 //unregistered_user
122 $sql = " SELECT count(*) as total FROM {users} WHERE access=0 and uid<>0";
123 $data = db_fetch_object(db_query($sql));
124 $counter_total = $data->total;
125
126 $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'unregistered_user' ";
127 $counter_data = db_fetch_object(db_query($sql));
128 $counter_name_exist = $counter_data->total;
129
130 if (!$counter_name_exist) {
131 $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('%s','%s')";
132 $results = db_query($sql,"unregistered_user",$counter_total);
133 }
134 //published_node
135 $sql = " SELECT count(*) as total FROM {node} WHERE status=1";
136 $data = db_fetch_object(db_query($sql));
137 $counter_total = $data->total;
138
139 $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'published_node' ";
140 $counter_data = db_fetch_object(db_query($sql));
141 $counter_name_exist = $counter_data->total;
142
143 if (!$counter_name_exist) {
144 $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('%s','%s')";
145 $results = db_query($sql,"published_node",$counter_total);
146 }
147 //unpublished_node
148 $sql = " SELECT count(*) as total FROM {node} WHERE status=0";
149 $data = db_fetch_object(db_query($sql));
150 $counter_total = $data->total;
151
152 $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'unpublished_node' ";
153 $counter_data = db_fetch_object(db_query($sql));
154 $counter_name_exist = $counter_data->total;
155
156 if (!$counter_name_exist) {
157 $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('%s','%s')";
158 $results = db_query($sql,"unpublished_node",$counter_total);
159 }
160 return $ret;
161 }
162
163 function counter_update_6002() {
164 $ret = array();
165
166 //blocked_user
167 $sql = " SELECT count(*) as total FROM {users} WHERE status=0 and uid<>0";
168 $data = db_fetch_object(db_query($sql));
169 $counter_total = $data->total;
170
171 $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'blocked_user' ";
172 $counter_data = db_fetch_object(db_query($sql));
173 $counter_name_exist = $counter_data->total;
174
175 if (!$counter_name_exist) {
176 $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('%s','%s')";
177 $results = db_query($sql,"blocked_user",$counter_total);
178 }
179 }
180

  ViewVC Help
Powered by ViewVC 1.1.2