Implement object deletion

This commit is contained in:
root 2022-11-28 23:39:17 +01:00
parent 794e174748
commit f1fc105f49

View File

@ -189,6 +189,37 @@ class JsonDatabase implements IJsonUnflattener
return $name; return $name;
} }
public function delete(string $className, $identifier): bool
{
if ($class == null || empty(trim($name)))
return false;
if ($name != null && !empty(trim(strval($name))))
$name = JSONDatabase::SanitizeIdentifier($name);
else
return false;
$class = trim($class);
if (!$this->audit && $timestamp != null)
return false;
$objPath = $this->getObjectPath($class, $name, ($timestamp != null));
if (strlen($objPath) > PHP_MAXPATHLEN)
return false;
if (!is_file($objPath))
return true;
return unlink($objPath);
}
public function delete(IJsonIdentifiable $obj): bool
{
return $this->delete(get_class($obj), $obj->flatIdentifier());
}
/** /**
* Restore a JsonSerializable from the Database by using it's Identifier reference. * Restore a JsonSerializable from the Database by using it's Identifier reference.
* @param string $className the full class name with domain of the JsonSerializable property * @param string $className the full class name with domain of the JsonSerializable property