You are here

function counter_update_7102 in Counter 7

Same name and namespace in other branches
  1. 8 counter.install \counter_update_7102()

Update: Updating Counter Data table.

1 call to counter_update_7102()
counter_install in ./counter.install
Implements hook_install().

File

./counter.install, line 106
Install the module with a new database table

Code

function counter_update_7102() {
  $ret = array();

  // site_counter
  $sql = " SELECT count(*) as total FROM {counter} c ";
  $counter_total = db_query($sql)
    ->fetchField();
  $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'site_counter' ";
  $counter_name_exist = db_query($sql)
    ->fetchField();
  if (!$counter_name_exist) {
    $sql = " INSERT INTO {counter_data} (counter_name, counter_value) VALUES ('site_counter', '{$counter_total}')";
    db_query($sql);
  }

  // unique_visitor
  $sql = " SELECT count(*) as total FROM (SELECT ip FROM {counter} GROUP BY ip) c";
  $counter_total = db_query($sql)
    ->fetchField();
  $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'unique_visitor' ";
  $counter_name_exist = db_query($sql)
    ->fetchField();
  if (!$counter_name_exist) {
    $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('unique_visitor','{$counter_total}')";
    db_query($sql);
  }

  // registered_user
  $sql = " SELECT count(*) as total FROM {users} WHERE access<>0 and uid<>0";
  $counter_total = db_query($sql)
    ->fetchField();
  $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'registered_user' ";
  $counter_name_exist = db_query($sql)
    ->fetchField();
  if (!$counter_name_exist) {
    $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('registered_user', '{$counter_total}')";
    db_query($sql);
  }

  // unregistered_user
  $sql = " SELECT count(*) as total FROM {users} WHERE access=0 and uid<>0";
  $counter_total = db_query($sql)
    ->fetchField();
  $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'unregistered_user' ";
  $counter_name_exist = db_query($sql)
    ->fetchField();
  if (!$counter_name_exist) {
    $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('unregistered_user', '{$counter_total}')";
    db_query($sql);
  }

  // published_node
  $sql = " SELECT count(*) as total FROM {node} WHERE status=1";
  $counter_total = db_query($sql)
    ->fetchField();
  $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'published_node' ";
  $counter_name_exist = db_query($sql)
    ->fetchField();
  if (!$counter_name_exist) {
    $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('published_node', '{$counter_total}')";
    db_query($sql);
  }

  // unpublished_node
  $sql = " SELECT count(*) as total FROM {node} WHERE status=0";
  $counter_total = db_query($sql)
    ->fetchField();
  $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'unpublished_node' ";
  $counter_name_exist = db_query($sql)
    ->fetchField();
  if (!$counter_name_exist) {
    $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('unpublished_node','{$counter_total}')";
    db_query($sql);
  }

  // blocked_user
  $sql = " SELECT count(*) as total FROM {users} WHERE status=0 and uid<>0";
  $counter_total = db_query($sql)
    ->fetchField();
  $sql = " SELECT count(*) as total FROM {counter_data} WHERE counter_name= 'blocked_user' ";
  $counter_name_exist = db_query($sql)
    ->fetchField();
  if (!$counter_name_exist) {
    $sql = " INSERT INTO {counter_data} (counter_name,counter_value) VALUES ('blocked_user','{$counter_total}')";
    db_query($sql);
  }
  return $ret;
}