Skip to content

Commit

Permalink
Added option $check_col_diff to set only modified fields when buildin…
Browse files Browse the repository at this point in the history
…g UPDATE query. Default is true. Can be modified from config.php for whole project or passed as parameter to edit() per object.

git-svn-id: http://voip.null.ro/svn/ansql/trunk@108 dbfed7de-b0aa-0410-b6a1-c7e608b77fc9
  • Loading branch information
dana committed Aug 7, 2014
1 parent e822299 commit d3c7ada
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
$enforce_basic_constrains = false;
if (!isset($critical_col_diff))
$critical_col_diff = false;
if (!isset($check_col_diff))
$check_col_diff = true;

require_once("debug.php");

Expand Down Expand Up @@ -867,6 +869,9 @@ class Model
//whether a select or extendedSelect was performed on the object
protected $_retrieved;

protected $_check_col_diff;
protected $_modified_col = array();

protected static $_models = false;
protected static $_modified = false;
// array with name of objects that are performers when using the ActionLog class
Expand All @@ -877,6 +882,8 @@ class Model
*/
function __construct()
{
global $check_col_diff;

Debug::func_start(__METHOD__,func_get_args(),"framework");

$this->_invalid = false;
Expand All @@ -892,6 +899,8 @@ function __construct()
}
$this->$name = $var->_value;
}

$this->_check_col_diff = isset($check_col_diff) ? $check_col_diff : true;
}

/**
Expand Down Expand Up @@ -1304,10 +1313,13 @@ public function add($params=NULL, $retrieve_id=true, $keep_log=true)
* @param $verifications Array with conditions trying to specify if this object can be modified or not
* @return Array, array[0] is true/false, true when inserting was succesfull, array[1] default message to could be printed to the user, array[2] is array with fields there was an error with
*/
public function edit($params, $conditions = NULL, $verifications = array())
public function edit($params, $conditions = NULL, $verifications = array(), $check_col_diff = true)
{
Debug::func_start(__METHOD__,func_get_args(),"framework");

if(!$check_col_diff)
$this->_check_col_diff = $check_col_diff;

if($params) {
$res = $this->verifyRequiredFields($params);
if(!$res[0])
Expand Down Expand Up @@ -1336,10 +1348,14 @@ public function setParams($params)
Debug::func_start(__METHOD__,func_get_args(),"framework");

$this->_set = true;
$this->_modified_col = array();

foreach($params as $param_name=>$param_value)
foreach($params as $param_name=>$param_value) {
if($this->{$param_name} != $param_value)
$this->_modified_col[$param_name] = true;
if($this->variable($param_name))
$this->{$param_name} = $param_value;
}
}

/**
Expand Down Expand Up @@ -1486,12 +1502,15 @@ public function update($conditions = array(), $verifications = array())
return null;
foreach($vars as $var_name=>$var)
{
if ($this->_check_col_diff && !isset($this->_modified_col[$var_name]))
continue;

if ($variables != '')
{
$variables .= ", ";
$update_log .= ", ";
}

if(!strlen($this->{$var_name}) && $var->isRequired()) {
$error .= " "._("Required field")." '"._($var_name)."' "._("not set").".";
$error_fields[] = $var_name;
Expand Down

0 comments on commit d3c7ada

Please sign in to comment.