cvs: pear /LiveUser_Admin/Perm Complex.php Medium.php Simple.php /LiveUser_Admin/Storage SQL.php

From: Date: Wed, 15 Dec 2004 13:16:50 +0000
Subject: cvs: pear /LiveUser_Admin/Perm Complex.php Medium.php Simple.php /LiveUser_Admin/Storage SQL.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-27433@lists.php.net to get a copy of this message
lsmith Wed Dec 15 08:16:50 2004 EDT Modified files: /pear/LiveUser_Admin/Perm Complex.php Medium.php Simple.php /pear/LiveUser_Admin/Storage SQL.php Log: - moved sanity checking for required fields, sequence handling and numeric checking for integer values into generic SQL layer

http://cvs.php.net/diff.php/pear/LiveUser_Admin/Perm/Complex.php?r1=1.14&r2=1.15&ty=u Index: pear/LiveUser_Admin/Perm/Complex.php diff -u pear/LiveUser_Admin/Perm/Complex.php:1.14 pear/LiveUser_Admin/Perm/Complex.php:1.15 --- pear/LiveUser_Admin/Perm/Complex.php:1.14 Tue Dec 14 13:05:03 2004 +++ pear/LiveUser_Admin/Perm/Complex.php Wed Dec 15 08:16:50 2004 @@ -36,7 +36,7 @@ * @author Christian Dickmann <dickmann@php.net> * @author Markus Wolff <wolff@21st.de> * @author Matt Scifo <mscifo@php.net> - * @version $Id: Complex.php,v 1.14 2004/12/14 18:05:03 dufuz Exp $ + * @version $Id: Complex.php,v 1.15 2004/12/15 13:16:50 lsmith Exp $ * @package LiveUser */ class LiveUser_Admin_Perm_Complex extends LiveUser_Admin_Perm_Medium @@ -50,20 +50,11 @@ */ function LiveUser_Perm_Complex(&$confArray) { - $this->LiveUser_Perm_Simple($confArray); + $this->LiveUser_Perm_Medium($confArray); } function removeArea($filters) { - // sanity checks - if (!isset($filters['area_id']) || !is_numeric($filters['area_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'area_id') - ); - return false; - } - // remove admin areas stuff $this->_storage->delete('area_admin_areas', $filters); parent::removeArea($filters); @@ -71,23 +62,9 @@ function assignSubGroup($data) { - if (!isset($data['group_id']) || !is_numeric($data['group_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'group_id') - ); - return false; - } - - if (!isset($data['subgroup_id']) || !is_numeric($data['subgroup_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'subgroup_id') - ); - return false; - } - - if ($data['subgroup_id'] == $data['group_id']) { + if (isset($data['group_id']) && isset($data['subgroup_id']) && + $data['subgroup_id'] == $data['group_id'] + ) { $this->_stack->push( LIVEUSER_ADMIN_ERROR, 'exception', array('msg' => 'Parent group id is the same as the subgroup id') @@ -123,14 +100,6 @@ function unassignSubGroup($filters) { - if (!isset($filters['subgroup_id']) || !is_numeric($filters['subgroup_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'subgroup_id') - ); - return false; - } - $result = $this->_storage->delete('group_subgroup', $filters); if (!$result) { return $result; @@ -140,23 +109,7 @@ function removeGroup($filters) { - if (!isset($filters['group_id']) || !is_numeric($filters['group_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'group_id') - ); - return false; - } - - if (!isset($filters['subgroup_id']) || !is_numeric($filters['subgroup_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'subgroup_id') - ); - return false; - } - - if ($filters['recursive']) { + if (isset($filters['subgroup_id']) && $filters['recursive']) { $filter = array('group_id' => $filters['subgroup_id']); $result = $this->_storage->selectCol('group_subgroups', 'group_id', $filter); if (!$result) { @@ -178,15 +131,6 @@ function _updateImpliedStatus($filters) { - // sanity checks - if (!isset($filters['right_id']) || !is_numeric($filters['right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'right_id') - ); - return false; - } - $count = $this->_storage->selectOne('rights_implied', 'right_id', $filters, true); if ($count === false) { return false; @@ -205,50 +149,16 @@ function implyRight($data) { - // sanity checks - if (!isset($data['right_id']) || !is_numeric($data['right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'right_id') - ); - return false; - } - - if (!isset($data['implied_right_id']) || !is_numeric($data['implied_right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'implied_right_id') - ); - return false; - } - $result = $this->_storage->insert('rights_implied', $data); if (!$result) { return false; } - + return $this->_updateImpliedStatus($data['right_id']); } function unimplyRight($filters) { - // sanity checks - if (!is_numeric($filters['right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'right_id') - ); - return false; - } - - if (!is_numeric($filters['implied_right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'implied_right_id') - ); - return false; - } - $this->_storage->delete('rights_implied', $filters); return $this->_updateImpliedStatus($data['right_id']); @@ -256,33 +166,15 @@ function removeRight($filters) { - // sanity checks - if (!isset($filters['right_id']) || !is_numeric($filters['right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'right_id') - ); - return false; - } - $this->_storage->delete('rights_implied', $filters); parent::removeRight($filters); - + return $this->_updateImpliedStatus($filters); } function removeUser($filters) { - // sanity checks - if (!isset($filters['perm_user_id']) || !is_numeric($filters['perm_user_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'perm_user_id') - ); - return false; - } - - $data = array('owner_user_id' => 'NULL'); + $data = array('owner_user_id' => null); $result = $this->_storage->update('groups', $data, $filters); if (!$result) { return false; @@ -313,15 +205,6 @@ function _updateImpliedStatus($filters) { - // sanity checks - if (!isset($filters['right_id']) || !is_numeric($filters['right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'right_id') - ); - return false; - } - $count = $this->_storage->selectOne('rights_implied', 'right_id', $filters, true); if (!$count) { return false; @@ -340,15 +223,6 @@ function _updateLevelStatus($filters) { - // sanity checks - if (!isset($filters['right_id']) || !is_numeric($filters['right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'right_id') - ); - return false; - } - // Add right level filter that will be used to get user and group count. $filters['right_level'] = array('op' => '<', 'value' => LIVEUSER_MAX_LEVEL); @@ -363,11 +237,11 @@ } $count = $usercount + $groupcount; - + $data = array('has_level' => ($count > 0)); $filter = array('right_id' => $filters['right_id']); $this->_storage->update('rights', $data, $filter); - + return true; } http://cvs.php.net/diff.php/pear/LiveUser_Admin/Perm/Medium.php?r1=1.16&r2=1.17&ty=u Index: pear/LiveUser_Admin/Perm/Medium.php diff -u pear/LiveUser_Admin/Perm/Medium.php:1.16 pear/LiveUser_Admin/Perm/Medium.php:1.17 --- pear/LiveUser_Admin/Perm/Medium.php:1.16 Tue Dec 14 06:55:51 2004 +++ pear/LiveUser_Admin/Perm/Medium.php Wed Dec 15 08:16:50 2004 @@ -39,7 +39,7 @@ * * @author Markus Wolff <wolff@21st.de> * @author Bjoern Kraus <krausbn@php.net> - * @version $Id: Medium.php,v 1.16 2004/12/14 11:55:51 lsmith Exp $ + * @version $Id: Medium.php,v 1.17 2004/12/15 13:16:50 lsmith Exp $ * @package LiveUser * @category authentication */ @@ -67,15 +67,6 @@ */ function addGroup($data) { - // sanity checks - if (isset($data['group_id']) && !is_numeric($data['group_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_DATA, 'exception', - array('key' => 'group_id') - ); - return false; - } - $result = $this->_storage->insert('groups', $data); // notify observer return $result; @@ -91,15 +82,6 @@ */ function updateGroup($data, $filters) { - // sanity checks - if (!isset($filters['group_id']) || !is_numeric($filters['group_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'group_id') - ); - return false; - } - $result = $this->_storage->update('groups', $data, $filters); // notify observer return $result; @@ -114,15 +96,6 @@ */ function removeGroup($filters) { - // sanity checks - if (!isset($filters['group_id']) || !is_numeric($filters['group_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'group_id') - ); - return false; - } - // Remove users from the group $filter = array('group_id' => $filters['group_id']); $result = $this->_storage->delete('groupusers', $filter); @@ -150,23 +123,6 @@ */ function grantGroupRight($data) { - // sanity checks - if (!isset($data['group_id']) || !is_numeric($data['group_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_DATA, 'exception', - array('key' => 'group_id') - ); - return false; - } - - if (!isset($data['right_id']) || !is_numeric($data['right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_DATA, 'exception', - array('key' => 'right_id') - ); - return false; - } - if (!isset($data['right_level'])) { $data['right_level'] = LIVEUSER_MAX_LEVEL; } @@ -196,31 +152,6 @@ */ function updateGroupRight($data, $filters) { - // sanity checks - if (!isset($data['right_level'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_DATA, 'exception', - array('key' => 'right_level') - ); - return false; - } - - if (!isset($filters['group_id']) || !is_numeric($filters['group_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'group_id') - ); - return false; - } - - if (!isset($filters['right_id']) || !is_numeric($filters['right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'right_id') - ); - return false; - } - $result = $this->_storage->update('grouprights', $data, $filters); // notify observer return $result; @@ -235,23 +166,6 @@ */ function revokeGroupRight($filters) { - // sanity checks - if (!isset($filters['group_id']) || !is_numeric($filters['group_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'group_id') - ); - return false; - } - - if (isset($filters['right_id']) && !is_numeric($filters['right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'right_id') - ); - return false; - } - $result = $this->_storage->delete('grouprights', $filters); // notify observer return $result; @@ -266,23 +180,6 @@ */ function addUserToGroup($data) { - // sanity checks - if (!isset($data['group_id']) || !is_numeric($data['group_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_DATA, 'exception', - array('key' => 'group_id') - ); - return false; - } - - if (!isset($data['perm_user_id']) || !is_numeric($data['perm_user_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_DATA, 'exception', - array('key' => 'perm_user_id') - ); - return false; - } - // check if the userhas already been granted added to that group $filters = array( 'perm_user_id' => $data['perm_user_id'], @@ -307,23 +204,6 @@ */ function removeUserFromGroup($filters) { - // sanity checks - if (isset($filters['group_id']) && !is_numeric($filters['group_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'group_id') - ); - return false; - } - - if (!isset($filters['perm_user_id']) || !is_numeric($filters['perm_user_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'perm_user_id') - ); - return false; - } - $result = $this->_storage->delete('groupusers', $filters); // notify observer return $result; @@ -338,15 +218,6 @@ */ function removeRight($filters) { - // sanity checks - if (!isset($filters['right_id']) || !is_numeric($filters['right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'right_id') - ); - return false; - } - $filter = array('right_id' => $filters['right_id']); $result = $this->_storage->delete('grouprights', $filter); if (!$result) { http://cvs.php.net/diff.php/pear/LiveUser_Admin/Perm/Simple.php?r1=1.30&r2=1.31&ty=u Index: pear/LiveUser_Admin/Perm/Simple.php diff -u pear/LiveUser_Admin/Perm/Simple.php:1.30 pear/LiveUser_Admin/Perm/Simple.php:1.31 --- pear/LiveUser_Admin/Perm/Simple.php:1.30 Tue Dec 14 06:55:51 2004 +++ pear/LiveUser_Admin/Perm/Simple.php Wed Dec 15 08:16:50 2004 @@ -32,7 +32,7 @@ * * @author Markus Wolff <wolff@21st.de> * @author Bjoern Kraus <krausbn@php.net> - * @version $Id: Simple.php,v 1.30 2004/12/14 11:55:51 lsmith Exp $ + * @version $Id: Simple.php,v 1.31 2004/12/15 13:16:50 lsmith Exp $ * @package LiveUser * @category authentication */ @@ -67,23 +67,6 @@ */ function addUser($data) { - // sanity checks - if (!isset($data['auth_container_name'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_DATA, 'exception', - array('key' => 'auth_container_name') - ); - return false; - } - - if (isset($data['perm_user_id']) && !is_numeric($data['perm_user_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_DATA, 'exception', - array('key' => 'perm_user_id') - ); - return false; - } - if (!isset($data['perm_type'])) { $data['perm_type'] = LIVEUSER_USER_TYPE_ID; } @@ -103,15 +86,6 @@ */ function updateUser($data, $filters) { - // sanity checks - if (!isset($filters['perm_user_id']) || !is_numeric($filters['perm_user_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'perm_user_id') - ); - return false; - } - $result = $this->_storage->update('perm_users', $data, $filters); // notify observer return $result; @@ -126,15 +100,6 @@ */ function removeUser($filters) { - // sanity checks - if (!isset($filters['perm_user_id']) || !is_numeric($filters['perm_user_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'perm_user_id') - ); - return false; - } - $result = $this->_storage->delete('perm_users', $filters); // notify observer return $result; @@ -149,15 +114,6 @@ */ function addRight($data) { - // sanity checks - if (!isset($data['area_id']) || !is_numeric($data['area_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_DATA, 'exception', - array('key' => 'area_id') - ); - return false; - } - $result = $this->_storage->insert('rights', $data); // notify observer return $result; @@ -173,23 +129,6 @@ */ function updateRight($data, $filters) { - // sanity checks - if (!isset($filters['right_id']) || !is_numeric($filters['right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'right_id') - ); - return false; - } - - if (isset($filters['area_id']) && !is_numeric($filters['area_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'area_id') - ); - return false; - } - $result = $this->_storage->update('rights', $data, $filters); // notify observer return $result; @@ -204,23 +143,6 @@ */ function removeRight($filters) { - // sanity checks - if (!isset($filters['right_id']) || !is_numeric($filters['right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'right_id') - ); - return false; - } - - if (isset($filters['area_id']) && !is_numeric($filters['area_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'area_id') - ); - return false; - } - // Remove all user assignments to that right $filter_check = array('right_id' => $filters['right_id']); $result = $this->_storage->delete('userrights', $filter_check); @@ -242,15 +164,6 @@ */ function addArea($data) { - // sanity checks - if (!isset($data['application_id']) || !is_numeric($data['application_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_DATA, 'exception', - array('key' => 'application_id') - ); - return false; - } - $result = $this->_storage->insert('areas', $data); // notify observer return $result; @@ -266,23 +179,6 @@ */ function updateArea($data, $filters) { - // sanity checks - if (!isset($filters['area_id']) || !is_numeric($filters['area_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'area_id') - ); - return false; - } - - if (isset($data['application_id']) && !is_numeric($data['application_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'application_id') - ); - return false; - } - $result = $this->_storage->update('areas', $data, $filters); // notify observer return $result; @@ -297,15 +193,6 @@ */ function removeArea($filters) { - // sanity checks - if (!isset($filters['area_id']) || !is_numeric($filters['area_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'area_id') - ); - return false; - } - // Remove all rights under that area $filter_check = array('area_id' => $filters['area_id']); $result = $this->_storage->delete('rights', $filter_check); @@ -352,15 +239,6 @@ */ function addApplication($data) { - // sanity checks - if (isset($data['application_id']) && !is_numeric($data['application_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_DATA, 'exception', - array('key' => 'application_id') - ); - return false; - } - $result = $this->_storage->insert('applications', $data); // notify observer return $result; @@ -376,15 +254,6 @@ */ function updateApplication($data, $filters) { - // sanity checks - if (!isset($filters['application_id']) || !is_numeric($filters['application_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'application_id') - ); - return false; - } - $result = $this->_storage->update('applications', $data, $filters); // notify observer return $result; @@ -399,15 +268,6 @@ */ function removeApplication($filters) { - // sanity checks - if (!isset($filters['application_id']) || !is_numeric($filters['application_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'application_id') - ); - return false; - } - // Remove all areas under that application $filter_check = array('application_id' => $filters['application_id']); $result = $this->_storage->delete('areas', $filter_check); @@ -429,23 +289,6 @@ */ function grantUserRight($data) { - // sanity checks - if (!isset($data['perm_user_id']) || !is_numeric($data['perm_user_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_DATA, 'exception', - array('key' => 'perm_user_id') - ); - return false; - } - - if (!isset($data['right_id']) || !is_numeric($data['right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_DATA, 'exception', - array('key' => 'right_id') - ); - return false; - } - if (!isset($data['right_level'])) { $data['right_level'] = LIVEUSER_MAX_LEVEL; } @@ -475,31 +318,6 @@ */ function updateUserRight($data, $filters) { - // sanity checks - if (!isset($data['right_level'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_DATA, 'exception', - array('key' => 'right_level') - ); - return false; - } - - if (!isset($filters['perm_user_id']) || !is_numeric($filters['perm_user_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'perm_user_id') - ); - return false; - } - - if (!isset($filters['right_id']) || !is_numeric($filters['right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'right_id') - ); - return false; - } - $result = $this->_storage->update('userrights', $data, $filters); // notify observer return $result; @@ -514,23 +332,6 @@ */ function revokeUserRight($filters) { - // sanity checks - if (!isset($filters['perm_user_id']) || !is_numeric($filters['perm_user_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'perm_user_id') - ); - return false; - } - - if (isset($filters['right_id']) && !is_numeric($filters['right_id'])) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_FILTER, 'exception', - array('key' => 'right_id') - ); - return false; - } - $result = $this->_storage->delete('userrights', $filters); // notify observer return $result; http://cvs.php.net/diff.php/pear/LiveUser_Admin/Storage/SQL.php?r1=1.9&r2=1.10&ty=u Index: pear/LiveUser_Admin/Storage/SQL.php diff -u pear/LiveUser_Admin/Storage/SQL.php:1.9 pear/LiveUser_Admin/Storage/SQL.php:1.10 --- pear/LiveUser_Admin/Storage/SQL.php:1.9 Wed Dec 15 01:20:32 2004 +++ pear/LiveUser_Admin/Storage/SQL.php Wed Dec 15 08:16:50 2004 @@ -43,7 +43,7 @@ * * @author Lukas Smith <smith@backendmedia.com> * @author Bjoern Kraus <krausbn@php.net> - * @version $Id: SQL.php,v 1.9 2004/12/15 06:20:32 dufuz Exp $ + * @version $Id: SQL.php,v 1.10 2004/12/15 13:16:50 lsmith Exp $ * @package LiveUser * @category authentication */ @@ -91,19 +91,35 @@ function insert($table, $data) { - if (isset($this->tables[$table]['id']) && !isset($data[$this->tables[$table]['id']])) { - $data[$this->tables[$table]['id']] = $this->nextId($this->prefix . $table, true); + // sanity checks + foreach ($this->tables[$table]['fields'] as $field => $required) { + if ($required) { + if ($required == 'seq' && !isset($data[$field])) { + $data[$field] = $this->nextId($this->prefix . $field, true); + } + if(!isset($data[$field]) || $data[$field] === '') { + $this->_stack->push( + LIVEUSER_ADMIN_ERROR_QUERY_BUILDER, 'exception', + array('reason' => 'field may not be empty: '.$field) + ); + return false; + } + } } $fields = array(); $values = array(); foreach ($data as $field => $value) { $fields[] = $this->alias[$field]; - $values[] = $this->quote($value, $this->fields[$field]); + $value_quoted = $this->quote($value, $this->fields[$field]); + if ($value_quoted === false) { + return false; + } + $values[] = $value_quoted; } $query = $this->createInsert($table, $fields, $values); - if (!$query) { + if ($query === false) { $this->_stack->push( LIVEUSER_ADMIN_ERROR_QUERY_BUILDER, 'exception', array('reason' => 'query was not created') @@ -118,8 +134,8 @@ ); return false; } - if (isset($this->tables[$table]['id'])) { - return $data[$this->tables[$table]['id']]; + if (isset($this->tables[$table]['ids'])) { + return $data[$this->tables[$table]['ids']]; } return true; } @@ -134,14 +150,42 @@ function update($table, $data, $filters) { + // sanity checks + foreach ($this->tables[$table]['fields'] as $field => $required) { + if ($required && isset($data[$field]) && $data[$field] === '') { + $this->_stack->push( + LIVEUSER_ADMIN_ERROR_QUERY_BUILDER, 'exception', + array('reason' => 'field may not be empty: '.$field) + ); + return false; + } + } + + // id filter checks .. we could actually remove this to be more flexible + if (isset($this->tables[$table]['ids'])) { + foreach ($this->tables[$table]['ids'] as $field) { + if(!isset($filters[$field]) || $filters[$field] === '') { + $this->_stack->push( + LIVEUSER_ADMIN_ERROR_QUERY_BUILDER, 'exception', + array('reason' => 'filter for id field may not be empty: '.$field) + ); + return false; + } + } + } + $fields = array(); $values = array(); foreach ($data as $field => $value) { - $fields[] = $this->alias[$field] . ' = ' . $this->quote($value, $this->fields[$field]); + $value_quoted = $this->quote($value, $this->fields[$field]); + if ($value_quoted === false) { + return false; + } + $fields[] = $this->alias[$field] . ' = ' . $value_quoted; } $query = $this->createUpdate($table, $fields, $filters); - if (!$query) { + if ($query === false) { $this->_stack->push( LIVEUSER_ADMIN_ERROR_QUERY_BUILDER, 'exception', array('reason' => 'query was not created') @@ -169,6 +213,19 @@ function delete($table, $filters) { + // id filter checks .. we could actually remove this to be more flexible + if (isset($this->tables[$table]['ids'])) { + foreach ($this->tables[$table]['ids'] as $field) { + if(!isset($filters[$field]) || $filters[$field] === '') { + $this->_stack->push( + LIVEUSER_ADMIN_ERROR_QUERY_BUILDER, 'exception', + array('reason' => 'filter for id field may not be empty: '.$field) + ); + return false; + } + } + } + $query = 'DELETE FROM ' . $this->prefix . $table; $query .= $this->createWhere($filters); @@ -243,7 +300,7 @@ } $query = $this->createSelect($fields, $filters, $orders, $root_table, $selectable_tables); - if (!$query) { + if ($query === false) { $this->_stack->push( LIVEUSER_ADMIN_ERROR_QUERY_BUILDER, 'exception', array('reason' => 'query was not created') @@ -332,12 +389,20 @@ if (is_array($value)) { if (isset($value['value'])) { - $where[] = $tmp_field. ' ' . $value['op'] . ' ' .$this->quote($value['value'], $type); + $value_quoted = $this->quote($value['value'], $type); + if ($value_quoted === false) { + return false; + } + $where[] = $tmp_field. ' ' . $value['op'] . ' ' .$value_quoted; } else { $where[] = $tmp_field.' IN ('.$this->implodeArray($value, $type).')'; } } else { - $where[] = $tmp_field.' = '.$this->quote($value, $type); + $value_quoted = $this->quote($value, $type); + if ($value_quoted === false) { + return false; + } + $where[] = $tmp_field.' = '.$value_quoted; } } foreach ($joinfilters as $field => $value) { @@ -452,13 +517,19 @@ // target table uses a field in the join and source table // a constant value } elseif (isset($this->tables[$table]['fields'][$jointarget])) { - $filters[$this->prefix.$table.'.'.$this->alias[$jointarget]] = - $this->quote($joinsource, $this->fields[$jointarget]); + $value_quoted = $this->quote($joinsource, $this->fields[$jointarget]); + if ($value_quoted === false) { + return false; + } + $filters[$this->prefix.$table.'.'.$this->alias[$jointarget]] = $value_quoted; // source table uses a field in the join and target table // a constant value } elseif (isset($this->tables[$root_table]['fields'][$joinsource])) { - $filters[$this->prefix.$root_table.'.'.$this->alias[$joinsource]] = - $this->quote($jointarget, $this->fields[$joinsource]); + $value_quoted = $this->quote($jointarget, $this->fields[$joinsource]); + if ($value_quoted === false) { + return false; + } + $filters[$this->prefix.$root_table.'.'.$this->alias[$joinsource]] = $value_quoted; // neither tables uses a field in the join } else { $this->_stack->push( @@ -509,13 +580,19 @@ // target table uses a field in the join and source table // a constant value } elseif (isset($this->tables[$table]['fields'][$jointarget])) { - $tmp_filters[$this->prefix.$table.'.'.$this->alias[$jointarget]] = - $this->quote($joinsource, $this->fields[$jointarget]); + $value_quoted = $this->quote($joinsource, $this->fields[$jointarget]); + if ($value_quoted === false) { + return false; + } + $tmp_filters[$this->prefix.$table.'.'.$this->alias[$jointarget]] = $value_quoted; // source table uses a field in the join and target table // a constant value } elseif (isset($this->tables[$root_table]['fields'][$joinsource])) { - $tmp_filters[$this->prefix.$root_table.'.'.$this->alias[$joinsource]] = - $this->quote($jointarget, $this->fields[$joinsource]); + $value_quoted = $this->quote($jointarget, $this->fields[$joinsource]);; + if ($value_quoted === false) { + return false; + } + $tmp_filters[$this->prefix.$root_table.'.'.$this->alias[$joinsource]] = $value_quoted; // neither tables uses a field in the join } else { $this->_stack->push(
« previous php.pear.cvs (#27433) next »