diff options
| author | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-04-15 10:08:51 +0000 |
|---|---|---|
| committer | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-04-15 10:08:51 +0000 |
| commit | 7af07ac3e1c9c6c2a9fa97cb2cd3c92080752430 (patch) | |
| tree | 59bccc0c112d42c3a9e9bd07709e8f78e2625950 /frontends/php | |
| parent | dc613c5587703836d1d0b4767e95a7d1b294b528 (diff) | |
| download | zabbix-7af07ac3e1c9c6c2a9fa97cb2cd3c92080752430.tar.gz zabbix-7af07ac3e1c9c6c2a9fa97cb2cd3c92080752430.tar.xz zabbix-7af07ac3e1c9c6c2a9fa97cb2cd3c92080752430.zip | |
- [DEV-142] improvements in transactions for DB actions (beta) (Artem)
git-svn-id: svn://svn.zabbix.com/trunk@5622 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php')
| -rw-r--r-- | frontends/php/hosts.php | 54 | ||||
| -rw-r--r-- | frontends/php/items.php | 47 | ||||
| -rw-r--r-- | frontends/php/triggers.php | 12 | ||||
| -rw-r--r-- | frontends/php/users.php | 13 |
4 files changed, 65 insertions, 61 deletions
diff --git a/frontends/php/hosts.php b/frontends/php/hosts.php index d0daaf00..8a419d59 100644 --- a/frontends/php/hosts.php +++ b/frontends/php/hosts.php @@ -258,13 +258,14 @@ include_once "include/page_header.php"; while($db_host=DBfetch($db_hosts)){ $host=get_host_by_hostid($db_host["hostid"]); - if(!uint_in_array($db_host["hostid"],$hosts)) continue; - if(!delete_host($db_host["hostid"], $unlink_mode)) continue; - - add_audit(AUDIT_ACTION_DELETE,AUDIT_RESOURCE_HOST,"Host [".$host["host"]."]"); + if(!uint_in_array($db_host["hostid"],$hosts)) continue; + $result=delete_host($db_host["hostid"], $unlink_mode); + + if($result) + add_audit(AUDIT_ACTION_DELETE,AUDIT_RESOURCE_HOST,"Host [".$host["host"]."]"); } $result = DBend(); - show_messages($result, S_HOST_DELETED, NULL); + show_messages($result, S_HOST_DELETED, S_CANNOT_DELETE_HOST); } unset($_REQUEST["delete"]); } @@ -302,17 +303,20 @@ include_once "include/page_header.php"; $hosts = get_request("hosts",array()); $db_hosts=DBselect('select hostid from hosts where '.DBin_node('hostid')); - while($db_host=DBfetch($db_hosts)){ - + DBstart(); + while($db_host=DBfetch($db_hosts)){ if(!uint_in_array($db_host["hostid"],$hosts)) continue; + $host=get_host_by_hostid($db_host["hostid"]); $res=update_host_status($db_host["hostid"],$status); - - add_audit(AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_HOST, - "Old status [".$host["status"]."] "."New status [".$status."]"); + + if($res){ + add_audit(AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_HOST,"Old status [".$host["status"]."] "."New status [".$status."]"); + } } + $result = DBend(); - show_messages($result, S_HOST_STATUS_UPDATED, NULL); + show_messages($result, S_HOST_STATUS_UPDATED, S_CANNOT_UPDATE_HOST); unset($_REQUEST["activate"]); } @@ -390,22 +394,22 @@ include_once "include/page_header.php"; $groups = get_request("groups",array()); $db_groups=DBselect('select groupid, name from groups where '.DBin_node('groupid')); + + DBstart(); while($db_group=DBfetch($db_groups)){ if(!uint_in_array($db_group["groupid"],$groups)) continue; if(!($group = get_hostgroup_by_groupid($db_group["groupid"]))) continue; - - DBstart(); $result = delete_host_group($db_group["groupid"]); - $result = DBend(); if($result){ add_audit(AUDIT_ACTION_DELETE,AUDIT_RESOURCE_HOST_GROUP, S_HOST_GROUP." [".$group["name"]." ] [".$group['groupid']."]"); } } - - show_messages(true, S_GROUP_DELETED, NULL); + $result = DBend(); + + show_messages(true, S_GROUP_DELETED, S_CANNOT_DELETE_GROUP); } unset($_REQUEST["delete"]); } @@ -420,6 +424,7 @@ include_once "include/page_header.php"; ' where h.hostid=hg.hostid '. ' and h.status in ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.')'. ' and '.DBin_node('h.hostid')); + DBstart(); while($db_host=DBfetch($db_hosts)){ if(!uint_in_array($db_host["groupid"],$groups)) continue; $host=get_host_by_hostid($db_host["hostid"]); @@ -429,8 +434,9 @@ include_once "include/page_header.php"; add_audit(AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_HOST, "Old status [".$host["status"]."] "."New status [".$status."]"); } + $result = DBend(); - show_messages($result, S_HOST_STATUS_UPDATED, NULL); + show_messages($result, S_HOST_STATUS_UPDATED, S_CANNOT_UPDATE_HOST); unset($_REQUEST["activate"]); } @@ -483,19 +489,19 @@ include_once "include/page_header.php"; $db_applications = DBselect("select applicationid, name, hostid from applications ". 'where '.DBin_node('applicationid')); + DBstart(); while($db_app = DBfetch($db_applications)){ if(!uint_in_array($db_app["applicationid"],$applications)) continue; - DBstart(); $result = delete_application($db_app["applicationid"]); - $result = DBend(); - + if($result){ $host = get_host_by_hostid($db_app["hostid"]); add_audit(AUDIT_ACTION_DELETE,AUDIT_RESOURCE_APPLICATION,"Application [".$db_app["name"]."] from host [".$host["host"]."]"); } } - + $result = DBend(); + show_messages(true, S_APPLICATION_DELETED, NULL); } unset($_REQUEST["delete"]); @@ -505,6 +511,7 @@ include_once "include/page_header.php"; $result = true; $applications = get_request("applications",array()); + DBstart(); foreach($applications as $id => $appid){ $sql = 'SELECT ia.itemid,i.hostid,i.key_'. @@ -531,6 +538,7 @@ include_once "include/page_header.php"; } } } + $result = DBend(); (isset($_REQUEST["activate"]))?show_messages($result, S_ITEMS_ACTIVATED, null):show_messages($result, S_ITEMS_DISABLED, null); } else if($_REQUEST["config"]==5 && isset($_REQUEST["save"])){ @@ -608,6 +616,7 @@ include_once "include/page_header.php"; $status = isset($_REQUEST["activate"]) ? HOST_STATUS_MONITORED : HOST_STATUS_NOT_MONITORED; $hosts = get_request("hosts",array()); + DBstart(); foreach($hosts as $hostid){ $db_hosts = DBselect('SELECT hostid,status '. ' FROM hosts '. @@ -624,7 +633,8 @@ include_once "include/page_header.php"; add_audit(AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_HOST,"Old status [".$old_status."] "."New status [".$status."] [".$db_host["hostid"]."]"); } } - + $result = DBend(); + show_messages($result, S_HOST_STATUS_UPDATED, NULL); if(isset($_REQUEST["activate"])) diff --git a/frontends/php/items.php b/frontends/php/items.php index 8023efa5..730cc7dc 100644 --- a/frontends/php/items.php +++ b/frontends/php/items.php @@ -646,8 +646,7 @@ include_once "include/page_header.php"; $show_applications = 0; $show_host = 1; } - else - { + else{ $form->AddItem(array('[', new CLink($showdisabled ? S_HIDE_DISABLED_ITEMS : S_SHOW_DISABLED_ITEMS, @@ -660,27 +659,29 @@ include_once "include/page_header.php"; $result=DBselect("select distinct g.groupid,g.name from groups g,hosts_groups hg". " where g.groupid=hg.groupid and hg.hostid in (".$accessible_hosts.") ". " order by name"); - while($row=DBfetch($result)) - { + while($row=DBfetch($result)){ $cmbGroup->AddItem($row["groupid"],$row["name"]); } $form->AddItem(S_GROUP.SPACE); $form->AddItem($cmbGroup); - if(isset($_REQUEST["groupid"]) && $_REQUEST["groupid"]>0) - { - $sql='select distinct h.hostid,h.host from hosts h,hosts_groups hg'. - ' where hg.groupid='.$_REQUEST['groupid'].' and hg.hostid=h.hostid '. - ' and h.status in ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.','.HOST_STATUS_TEMPLATE.')'. - ' and h.hostid in ('.$accessible_hosts.') '. - ' group by h.hostid,h.host order by h.host'; - } - else - { - $sql='select distinct h.hostid,h.host from hosts h'. + if(isset($_REQUEST["groupid"]) && $_REQUEST["groupid"]>0){ + $sql='select distinct h.hostid,h.host '. + ' from hosts h,hosts_groups hg'. + ' where hg.groupid='.$_REQUEST['groupid']. + ' and hg.hostid=h.hostid '. + ' and h.status in ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.','.HOST_STATUS_TEMPLATE.')'. + ' and h.hostid in ('.$accessible_hosts.') '. + ' group by h.hostid,h.host '. + ' order by h.host'; + } + else{ + $sql='select distinct h.hostid,h.host '. + ' from hosts h'. ' where h.status in ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.','.HOST_STATUS_TEMPLATE.')'. - ' and h.hostid in ('.$accessible_hosts.') '. - ' group by h.hostid,h.host order by h.host'; + ' and h.hostid in ('.$accessible_hosts.') '. + ' group by h.hostid,h.host '. + ' order by h.host'; } $result=DBselect($sql); @@ -690,8 +691,7 @@ include_once "include/page_header.php"; unset($correct_hostid); $first_hostid = -1; - while($row=DBfetch($result)) - { + while($row=DBfetch($result)){ $cmbHosts->AddItem($row["hostid"],$row["host"]); if($_REQUEST["hostid"]!=0){ @@ -710,8 +710,7 @@ include_once "include/page_header.php"; $form->AddItem(SPACE); $form->AddItem(new CButton("external_filter",S_EXTERNAL_FILTER)); - if($host_info = DBfetch(DBselect('select host from hosts where hostid='.$_REQUEST["hostid"]))) - { + if($host_info = DBfetch(DBselect('select host from hosts where hostid='.$_REQUEST["hostid"]))){ $form->AddVar('with_host', $host_info['host']); } $where_case[] = 'i.hostid='.$_REQUEST['hostid']; @@ -780,12 +779,10 @@ include_once "include/page_header.php"; "&group_task=".($db_item["status"] ? "Activate+selected" : "Disable+selected"), item_status2style($db_item["status"]))); - if($db_item["error"] == '') - { + if($db_item["error"] == ''){ $error=new CCol('-',"off"); } - else - { + else{ $error=new CCol($db_item["error"],"on"); } diff --git a/frontends/php/triggers.php b/frontends/php/triggers.php index 6a1ba3a9..2139840f 100644 --- a/frontends/php/triggers.php +++ b/frontends/php/triggers.php @@ -400,8 +400,7 @@ include_once "include/page_header.php"; $sql .= order_by('h.host,t.description,t.priority,t.status'); $result=DBselect($sql); - while($row=DBfetch($result)) - { + while($row=DBfetch($result)){ if(!check_right_on_trigger_by_triggerid(null, $row['triggerid'], $accessible_hosts)) continue; @@ -416,17 +415,14 @@ include_once "include/page_header.php"; $row["triggerid"]), /* value */ SPACE); - if($row["templateid"]) - { + if($row["templateid"]){ $real_hosts = get_realhosts_by_triggerid($row["triggerid"]); $real_host = DBfetch($real_hosts); - if($real_host) - { + if($real_host){ $description[] = new CLink($real_host["host"], "triggers.php?&hostid=".$real_host["hostid"], 'unknown'); } - else - { + else{ $description[] = new CSpan("error","on"); } $description[] = ':'; diff --git a/frontends/php/users.php b/frontends/php/users.php index a0381745..381dbb66 100644 --- a/frontends/php/users.php +++ b/frontends/php/users.php @@ -466,9 +466,8 @@ include_once "include/page_header.php"; ' FROM users u'. ' WHERE '.DBin_node('u.userid'). order_by('u.alias,u.name,u.surname,u.type','u.userid')); - while($db_user=DBfetch($db_users)) - { -//Log Out 10min ot Autologout time + while($db_user=DBfetch($db_users)){ +//Log Out 10min or Autologout time $online_time = (($db_user['autologout'] == 0) || (ZBX_USER_ONLINE_TIME<$db_user['autologout']))?ZBX_USER_ONLINE_TIME:$db_user['autologout']; $db_sessions = DBselect('SELECT count(*) as count, max(s.lastaccess) as lastaccess'. ' FROM sessions s, users u'. @@ -484,12 +483,14 @@ include_once "include/page_header.php"; $online=new CCol(S_NO,"disabled"); $user_groups = array(); - $db_groups = DBselect("select g.name from usrgrp g, users_groups ug". - " where g.usrgrpid=ug.usrgrpid and ug.userid=".$db_user['userid']); + $db_groups = DBselect('SELECT g.name '. + ' FROM usrgrp g, users_groups ug '. + ' WHERE g.usrgrpid=ug.usrgrpid '. + ' and ug.userid='.$db_user['userid']); + while($db_group = DBfetch($db_groups)) array_push($user_groups,empty($user_groups)?'':BR(),$db_group['name']); - $db_user['users_status'] = check_perm2system($db_user['userid']); $db_user['gui_access'] = check_perm2login($db_user['userid']); |
