postDelete hook, imagick dependency, rrmdir
This commit is contained in:
@@ -125,6 +125,7 @@ abstract class DatabaseEntity implements ArrayAccess, JsonSerializable {
|
||||
public function preInsert(array &$row) { }
|
||||
public function postFetch(SQL $sql, array $row) { }
|
||||
public static function getPredefinedValues(): array { return []; }
|
||||
public function postDelete() { }
|
||||
|
||||
public static function fromRow(SQL $sql, array $row): static {
|
||||
$handler = self::getHandler($sql);
|
||||
@@ -207,6 +208,7 @@ abstract class DatabaseEntity implements ArrayAccess, JsonSerializable {
|
||||
}
|
||||
|
||||
if ($handler->delete($this->id)) {
|
||||
$this->postDelete();
|
||||
$this->id = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -284,4 +284,21 @@ function parseClass($class): string {
|
||||
function isClass(string $str): bool {
|
||||
$path = getClassPath($str);
|
||||
return is_file($path) && class_exists($str);
|
||||
}
|
||||
|
||||
function rrmdir(string $dir): void {
|
||||
if (is_dir($dir)) {
|
||||
$objects = scandir($dir);
|
||||
foreach ($objects as $object) {
|
||||
if ($object !== "." && $object !== "..") {
|
||||
$path = $dir . DIRECTORY_SEPARATOR . $object;
|
||||
if (is_dir($path) && !is_link($path)) {
|
||||
rrmdir($path);
|
||||
} else {
|
||||
unlink($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
rmdir($dir);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user