man kann hunde anlegen yay
All checks were successful
Build and push / Pulling repo on server (push) Successful in 18s
All checks were successful
Build and push / Pulling repo on server (push) Successful in 18s
This commit is contained in:
@ -57,34 +57,54 @@ class Model {
|
||||
|
||||
public function save()
|
||||
{
|
||||
if (!$this->id)
|
||||
$this->id = gen_ulid();
|
||||
if (!$this->validate())
|
||||
return false;
|
||||
foreach($this->dbFields as $field=>$options)
|
||||
{
|
||||
if(isset($this->data[$field]))
|
||||
$this->redis->hset($this->dbTable.':'.$this->id,$field,$this->data[$field]);
|
||||
{
|
||||
error_log($field.' -> '.$options['type']);
|
||||
if($options['type']=='array')
|
||||
$GLOBALS['redis']->hset($this->dbTable.':'.$this->id,$field,json_encode($this->data[$field]));
|
||||
else
|
||||
{
|
||||
|
||||
error_log("hset $this->dbTable:$this->id $field {$this->data[$field]}");
|
||||
$GLOBALS['redis']->hset($this->dbTable.':'.$this->id,$field,$this->data[$field]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function load($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
if(!$this->redis->exists($this->dbTable.':'.$this->id))
|
||||
if(!$GLOBALS['redis']->exists($this->dbTable.':'.$this->id))
|
||||
return false;
|
||||
$keys = array_keys($this->dbFields);
|
||||
|
||||
foreach($keys as $key)
|
||||
{
|
||||
$value = $this->redis->hget($this->dbTable.':'.$this->id,$key);
|
||||
$value = $GLOBALS['redis']->hget($this->dbTable.':'.$this->id,$key);
|
||||
|
||||
if($value!==NULL) //we'll leave null values
|
||||
switch($this->dbFields[$key]['type'])
|
||||
{
|
||||
case 'int': $value = intval($value);break;
|
||||
case 'bool': $value = boolval($value);break;
|
||||
case 'float': $value = floatval($value);break;
|
||||
case 'double': $value = doubleval($value);break;
|
||||
}
|
||||
switch($this->dbFields[$key]['type'])
|
||||
{
|
||||
case 'int': $value = intval($value);break;
|
||||
case 'bool': $value = boolval($value);break;
|
||||
case 'float': $value = floatval($value);break;
|
||||
case 'double': $value = doubleval($value);break;
|
||||
case 'array':
|
||||
$value = json_decode($value,true);
|
||||
if($value===null)
|
||||
$value = [];
|
||||
break;
|
||||
}
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
|
||||
@ -148,6 +168,10 @@ class Model {
|
||||
throw new Exception("$type validation failed");
|
||||
}
|
||||
break;
|
||||
case 'array':
|
||||
if(!is_array($value))
|
||||
throw new Exception('Dogs validation failed');
|
||||
break;
|
||||
case 'csv':
|
||||
case "text":
|
||||
$regexp = null;
|
||||
@ -180,7 +204,7 @@ class Model {
|
||||
|
||||
function delete()
|
||||
{
|
||||
return $this->redis->del($this->dbTable.':'.$this->id);
|
||||
return $GLOBALS['redis']->del($this->dbTable.':'.$this->id);
|
||||
}
|
||||
|
||||
function gen_shorthash(){
|
||||
|
@ -30,7 +30,7 @@ function includeManagement()
|
||||
{
|
||||
$redis = new Redis();
|
||||
try{
|
||||
$redis->pconnect(REDIS_SERVER, REDIS_PORT);
|
||||
$redis->connect(REDIS_SERVER, REDIS_PORT);
|
||||
if (defined('REDIS_PASS') && REDIS_PASS)
|
||||
$redis->auth(REDIS_PASS);
|
||||
if (defined('REDIS_PREFIX') && REDIS_PREFIX)
|
||||
|
Reference in New Issue
Block a user