Skip to content

Commit

Permalink
Fix travis
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Apr 30, 2017
1 parent 072eb74 commit 1e3384a
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 161 deletions.
64 changes: 62 additions & 2 deletions htdocs/core/class/commonobject.class.php
Expand Up @@ -4674,7 +4674,26 @@ public function defineBuyPrice($unitPrice = 0, $discountPercent = 0, $fk_product
*/
public function createCommon(User $user, $notrigger = false)
{
foreach ($this->fields as $k => $v) {

$keys[] = $k;
$values[] = $this->quote($v);

}

$sql = 'INSERT INTO '.MAIN_DB_PREFIX.$table.'
( '.implode( ",", $keys ).' )
VALUES ( '.implode( ",", $values ).' ) ';

$res = $this->query($sql);
if($res===false) {

return false;
}

// TODO Add triggers

return true;
}


Expand All @@ -4690,7 +4709,6 @@ public function fetchCommon($id, $ref = null)
{

}


/**
* Update object into database
Expand All @@ -4702,10 +4720,36 @@ public function fetchCommon($id, $ref = null)
*/
public function updateCommon(User $user, $notrigger = false)
{
foreach ($this->fields as $k => $v) {

if (is_array($key)){
$i=array_search($k, $key);
if ( $i !== false) {
$where[] = $key[$i].'=' . $this->quote( $v ) ;
continue;
}
} else {
if ( $k == $key) {
$where[] = $k.'=' .$this->quote( $v ) ;
continue;
}
}

$tmp[] = $k.'='.$this->quote($v);
}
$sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET '.implode( ',', $tmp ).' WHERE ' . implode(' AND ',$where) ;
$res = $this->query( $sql );

if($res===false) {
//error
return false;
}

// TODO Add triggers

return true;
}


/**
* Delete object in database
*
Expand All @@ -4718,4 +4762,20 @@ public function deleteCommon(User $user, $notrigger = false)
{

}

/**
* Add quote to field value if necessary
*
* @param string|int $value value to protect
* @return string|int
*/
function quote($value) {

if(is_null($value)) return 'NULL';
else if(is_numeric($value)) return $value;
else return "'".$this->escape( $value )."'";

}

}

117 changes: 0 additions & 117 deletions htdocs/core/db/DoliDB.class.php
Expand Up @@ -295,122 +295,5 @@ function lastqueryerror()
{
return $this->lastqueryerror;
}
/*
* Add quote to field value if necessary
*
* @param string|int $value value to protect
* @return string|int
*/
function quote($value) {

if(is_null($value)) return 'NULL';
else if(is_numeric($value)) return $value;
else return "'".$this->escape( $value )."'";

}

/**
* Generate and execute Update SQL commande
*
* @param string $table table to update
* @param array $values array of values to update
* @param int|string|array $key key of value to select row to update
* @return bool|result false or boolean
*/
function update($table,$fields,$key){

foreach ($fields as $k => $v) {

if (is_array($key)){
$i=array_search($k , $key );
if ( $i !== false) {
$where[] = $key[$i].'=' . $this->quote( $v ) ;
continue;
}
} else {
if ( $k == $key) {
$where[] = $k.'=' .$this->quote( $v ) ;
continue;
}
}

$tmp[] = $k.'='.$this->quote($v);
}
$sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET '.implode( ',', $tmp ).' WHERE ' . implode(' AND ',$where) ;
$res = $this->query( $sql );

if($res===false) {
//error
return false;
}

return true;
}

/**
* Generate and execute Insert SQL commande
*
* @param string $table table to update
* @param array $values array of values to update
* @return bool|result false or boolean
*/
function insert($table,$fields){

foreach ($fields as $k => $v) {

$keys[] = $k;
$values[] = $this->quote($v);

}

$sql = 'INSERT INTO '.MAIN_DB_PREFIX.$table.'
( '.implode( ",", $keys ).' )
VALUES ( '.implode( ",", $values ).' ) ';

$res = $this->query($sql);
if($res===false) {

return false;
}

return true;
}

/**
* Generate and execute Delete SQL commande
*
* @param string $table table for the delete
* @param array $values array of values to delete
* @param int|string|array $key key of value to select row to update
* @return bool|result false or boolean
*/
function delete($table,$fields,$key){
foreach ($fields as $k => $v) {
if (is_array($key)){
$i=array_search($k , $key );
if ( $i !== false) {
$where[] = $key[$i].'=' . $this->quote( $v ) ;
continue;
}
} else {
if ( $k == $key) {
$where[] = $k.'='.$this->quote( $v ) ;
continue;
}
}

}

$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.implode(' AND ',$where);

$res = $this->query( $sql );
if($res===false) {
return false;
}

return true;

}

}

2 changes: 1 addition & 1 deletion htdocs/product/inventory/card.php
Expand Up @@ -23,7 +23,7 @@

require_once '../../main.inc.php';

require_once DOL_DOCUMENT_ROOT.'/core/class/listview.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/inventory/listview.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
Expand Down
2 changes: 1 addition & 1 deletion htdocs/product/inventory/list.php
Expand Up @@ -23,7 +23,7 @@

require_once '../../main.inc.php';

require_once DOL_DOCUMENT_ROOT.'/core/class/listview.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/inventory/listview.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
Expand Down

0 comments on commit 1e3384a

Please sign in to comment.