public function transform(Update $update)
 {
     $r_type = $update->updateType();
     $class = $update->entityClass();
     if ($class == Entity::class) {
         foreach ($this->known() as $model) {
             if ($model->updateType() == $r_type) {
                 return $model->newFromBuilder($update->getAttributes());
             }
         }
         // throw new \Exception("Unknown update type [$r_type] for entity class [$class]");
     }
     return $update;
 }
Exemple #2
0
 protected function willBeUpdated($dirty)
 {
     $this->filterImportantUpdatedAttributes($dirty, function ($field, $type, $modifiers) use($dirty) {
         $capture = !hasUpdateModifier('-', $modifiers);
         $update = $this->checkChange($field, $dirty, $type, $capture);
         if ($update && !$capture) {
             $similar = $update->similar()->withTrashed();
             // pgsql restriction bypass
             $ids = [];
             foreach ($similar->get() as $update) {
                 $ids[] = $update->id;
             }
             $updates = Update::whereIn('id', $ids)->withTrashed();
             $updates->forceDelete();
         }
     });
 }
Exemple #3
0
 public function clean()
 {
     $deleted = Update::onlyTrashed();
     $count = Update::count();
     $old = Update::withTrashed()->orderBy('id')->take($count / 2);
     $updateIds = array_unique(array_merge($deleted->get(['id'])->pluck('id')->toArray(), $old->get(['id'])->pluck('id')->toArray()));
     $updates = Update::withTrashed()->whereIn('id', $updateIds);
     $updates->forceDelete();
     $this->stats = ['updates' => $updateIds];
     return $this->stats;
 }