function counter_update_6001 in Counter 6.2
1 call to counter_update_6001()
- counter_install in ./
counter.install - Install the module with a new database table @file
File
- ./
counter.install, line 101 - Install the module with a new database table
Code
function counter_update_6001() {
$ret = array();
$schema = counter_schema();
_drupal_initialize_schema('counter', $schema);
foreach ($schema as $name => $table) {
if (!db_table_exists($name)) {
db_create_table($ret, $name, $table);
}
}
//site_counter
$sql = " SELECT count(*) as total FROM {counter} c ";
$data = db_fetch_object(db_query($sql));
$counter_total = $data->total;
$sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'site_counter' ";
$counter_data = db_fetch_object(db_query($sql));
$counter_name_exist = $counter_data->total;
if (!$counter_name_exist) {
$sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('%s','%s')";
$results = db_query($sql, "site_counter", $counter_total);
}
//unique_visitor
$sql = " SELECT count(*) as total FROM (SELECT counter_ip FROM {counter} GROUP BY counter_ip) c";
$data = db_fetch_object(db_query($sql));
$counter_total = $data->total;
$sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'unique_visitor' ";
$counter_data = db_fetch_object(db_query($sql));
$counter_name_exist = $counter_data->total;
if (!$counter_name_exist) {
$sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('%s','%s')";
$results = db_query($sql, "unique_visitor", $counter_total);
}
//registered_user
$sql = " SELECT count(*) as total FROM {users} WHERE access<>0 and uid<>0";
$data = db_fetch_object(db_query($sql));
$counter_total = $data->total;
$sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'registered_user' ";
$counter_data = db_fetch_object(db_query($sql));
$counter_name_exist = $counter_data->total;
if (!$counter_name_exist) {
$sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('%s','%s')";
$results = db_query($sql, "registered_user", $counter_total);
}
//unregistered_user
$sql = " SELECT count(*) as total FROM {users} WHERE access=0 and uid<>0";
$data = db_fetch_object(db_query($sql));
$counter_total = $data->total;
$sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'unregistered_user' ";
$counter_data = db_fetch_object(db_query($sql));
$counter_name_exist = $counter_data->total;
if (!$counter_name_exist) {
$sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('%s','%s')";
$results = db_query($sql, "unregistered_user", $counter_total);
}
//published_node
$sql = " SELECT count(*) as total FROM {node} WHERE status=1";
$data = db_fetch_object(db_query($sql));
$counter_total = $data->total;
$sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'published_node' ";
$counter_data = db_fetch_object(db_query($sql));
$counter_name_exist = $counter_data->total;
if (!$counter_name_exist) {
$sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('%s','%s')";
$results = db_query($sql, "published_node", $counter_total);
}
//unpublished_node
$sql = " SELECT count(*) as total FROM {node} WHERE status=0";
$data = db_fetch_object(db_query($sql));
$counter_total = $data->total;
$sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'unpublished_node' ";
$counter_data = db_fetch_object(db_query($sql));
$counter_name_exist = $counter_data->total;
if (!$counter_name_exist) {
$sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('%s','%s')";
$results = db_query($sql, "unpublished_node", $counter_total);
}
return $ret;
}