CluPilotCloud/app/Models/Builders/AppendOnlyBuilder.php

42 lines
1.2 KiB
PHP

<?php
namespace App\Models\Builders;
use Illuminate\Database\Eloquent\Builder;
use RuntimeException;
/**
* A query builder that refuses to rewrite history.
*
* Model events (`updating`, `deleting`) only fire for instance operations, so a
* guard on the model alone still lets `Model::query()->where(...)->update(...)`
* through — which is exactly the shape a careless data fix takes. For a table
* whose value IS that it cannot be edited, the guard has to sit where the bulk
* operations pass.
*
* Not a security boundary: anyone with database access can still do as they
* please. It is a guard against the application quietly doing it by accident,
* which is the realistic way a register loses its meaning.
*/
class AppendOnlyBuilder extends Builder
{
public function update(array $values)
{
throw new RuntimeException(
'The proof register is append-only. Record a correcting event instead of editing history.'
);
}
public function delete()
{
throw new RuntimeException(
'The proof register is append-only. A record that can be deleted is not evidence.'
);
}
public function forceDelete()
{
return $this->delete();
}
}