HexMakina /
kadro
| 1 | <?php |
||
| 2 | |||
| 3 | namespace HexMakina\kadro\Controllers\Abilities; |
||
| 4 | |||
| 5 | use HexMakina\BlackBox\Database\TracerInterface; |
||
| 6 | use HexMakina\Tracer\Trace; |
||
| 7 | use HexMakina\BlackBox\ORM\ModelInterface; |
||
| 8 | use HexMakina\BlackBox\Auth\OperatorInterface; |
||
| 9 | use Psr\Container\ContainerInterface; |
||
| 10 | |||
| 11 | trait Traceable |
||
| 12 | { |
||
| 13 | |||
| 14 | abstract public function formModel(): ModelInterface; |
||
| 15 | abstract public function loadModel(): ?ModelInterface; |
||
| 16 | abstract public function operator(): OperatorInterface; |
||
| 17 | |||
| 18 | |||
| 19 | public function getTracer(): TracerInterface |
||
| 20 | { |
||
| 21 | return $this->get('HexMakina\BlackBox\Database\TracerInterface'); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 22 | } |
||
| 23 | |||
| 24 | public function TraceableTraitor_after_save() |
||
| 25 | { |
||
| 26 | $trace = new Trace(); |
||
| 27 | $trace->tableName(get_class($this->formModel())::relationalMappingName()); |
||
| 28 | |||
| 29 | if (is_null($this->loadModel())) { |
||
| 30 | $trace->isInsert(true); |
||
| 31 | } else { |
||
| 32 | $trace->isUpdate(true); |
||
| 33 | } |
||
| 34 | $trace->tablePk($this->formModel()->getId()); |
||
| 35 | $trace->operatorId($this->operator()->getId()); |
||
| 36 | |||
| 37 | $this->getTracer()->trace($trace); |
||
| 38 | } |
||
| 39 | |||
| 40 | public function TraceableTraitor_after_destroy() |
||
| 41 | { |
||
| 42 | ; |
||
| 43 | } |
||
| 44 | |||
| 45 | |||
| 46 | |||
| 47 | // public function trace(TracerInterface $tracer, ModelInterface $model, OperatorInterface $op) |
||
| 48 | // { |
||
| 49 | // $tracer->trace($model->last_alter_query, $op->getId(), $model->getId()); |
||
| 50 | // |
||
| 51 | // } |
||
| 52 | |||
| 53 | // public function traces($options = []) : array |
||
| 54 | // { |
||
| 55 | // $options['query_table'] = get_class($this)::relationalMappingName(); |
||
| 56 | // $options['query_id'] = $this->get_model_id(); |
||
| 57 | // return $this->get_tracer()->traces($options); |
||
| 58 | // |
||
| 59 | // // $q = $this->get_tracer()->tracing_table()->select(); |
||
| 60 | // // $q->whereFieldsEQ(['query_table' => get_class($this)::relationalMappingName(), 'query_id' => $this->getId()]); |
||
| 61 | // // $q->orderBy(['query_on', 'DESC']); |
||
| 62 | // // $q->run(); |
||
| 63 | // // $res = $q->retAss(); |
||
| 64 | // // |
||
| 65 | // // return $res; |
||
| 66 | // } |
||
| 67 | |||
| 68 | // don't really know the purpose of this anymore.. came from Tracer |
||
| 69 | // public function traces_by_model(ModelInterface $m) |
||
| 70 | // { |
||
| 71 | // return $this->get_tracer()->traces(['id' => $m->getId(), 'table' => get_class($m)::relationalMappingName()]); |
||
| 72 | // } |
||
| 73 | } |
||
| 74 |