man kann hunde anlegen yay
All checks were successful
Build and push / Pulling repo on server (push) Successful in 18s

This commit is contained in:
2023-10-22 23:05:24 +02:00
parent 890905b435
commit f7a7c3457b
19 changed files with 314 additions and 83 deletions

View File

@ -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(){