id = $id; } public static function find_one($params) { return new Storage($params['Id']); } public function Id() { return $this->id; } public function Path() { return '/var/cache/zoneminder/events'; } public function Scheme($s = null) { return 'Medium'; } public function DoDelete() { return 1; } } class Monitor {} require_once __DIR__.'/../../web/includes/Event.php'; function run_delete($failing_sql) { global $calls, $row, $fail_on; $calls = array(); $fail_on = $failing_sql; $row = array('Id' => 77, 'MonitorId' => 1, 'StorageId' => 3, 'DiskSpace' => 12345, 'Scheme' => 'Medium', 'Archived' => 0, 'StartDateTime' => '2024-05-06 07:08:09'); $event = new Event($row); $event->delete(); return $calls; } function any_with($calls, $prefix) { foreach ($calls as $c) { if (strpos($c, $prefix) === 0) return true; } return false; } $calls = run_delete('DELETE FROM Events'); check('failed Events delete: files are kept', any_with($calls, 'deletePath'), false); check('failed Events delete: storage is not credited', any_with($calls, 'UPDATE Storage'), false); check('failed Events delete: rolled back', any_with($calls, 'rollback'), true); check('failed Events delete: not committed', any_with($calls, 'commit'), false); $calls = run_delete('DELETE FROM Frames'); check('failed Frames delete: files are kept', any_with($calls, 'deletePath'), false); check('failed Frames delete: Events row is not deleted', any_with($calls, 'DELETE FROM Events'), false); $calls = run_delete(''); check('successful delete: files are removed', any_with($calls, 'deletePath /var/cache/zoneminder/events/1/2024-05-06/77'), true); check('successful delete: files are removed after the commit', array_search('commit', $calls) < array_search('deletePath /var/cache/zoneminder/events/1/2024-05-06/77', $calls), true); echo "\n$passes passed, $failures failed\n"; array_map('unlink', glob($stubdir.'/*')); @rmdir($stubdir); exit($failures ? 1 : 0);