added $sneaky arg to update()

this new argument allows update hooks to be skipped (for example, to 
avoid updating updated date for migration-type tasks)
This commit is contained in:
Joby Elliott 2019-03-13 12:27:46 -06:00
parent a388c15650
commit fd366a1297
4 changed files with 10 additions and 8 deletions

View file

@ -47,7 +47,7 @@ class DSO extends FlatArray implements DSOInterface
return $this->factory()->insert($this); return $this->factory()->insert($this);
} }
public function update() : bool public function update(bool $sneaky = false) : bool
{ {
return $this->factory()->update($this); return $this->factory()->update($this);
} }

View file

@ -12,7 +12,7 @@ interface DSOFactoryInterface
public function create(array $data = array()) : DSOInterface; public function create(array $data = array()) : DSOInterface;
public function read(string $value, string $field = 'dso.id', $deleted = false) : ?DSOInterface; public function read(string $value, string $field = 'dso.id', $deleted = false) : ?DSOInterface;
public function insert(DSOInterface &$dso) : bool; public function insert(DSOInterface &$dso) : bool;
public function update(DSOInterface &$dso) : bool; public function update(DSOInterface &$dso, bool $sneaky = false) : bool;
public function delete(DSOInterface &$dso, bool $permanent = false) : bool; public function delete(DSOInterface &$dso, bool $permanent = false) : bool;
public function search() : Search; public function search() : Search;

View file

@ -21,7 +21,7 @@ interface DSOInterface extends FlatArrayInterface
public function removals() : array; public function removals() : array;
public function insert() : bool; public function insert() : bool;
public function update() : bool; public function update(bool $sneaky = false) : bool;
public function delete(bool $permanent = false) : bool; public function delete(bool $permanent = false) : bool;
public function undelete() : bool; public function undelete() : bool;
} }

View file

@ -109,13 +109,13 @@ class Factory implements DSOFactoryInterface
return $this->driver->delete($this->table, $dso); return $this->driver->delete($this->table, $dso);
} }
$dso['dso.deleted'] = time(); $dso['dso.deleted'] = time();
return $this->update($dso); return $this->update($dso, true);
} }
public function undelete(DSOInterface &$dso) : bool public function undelete(DSOInterface &$dso) : bool
{ {
unset($dso['dso.deleted']); unset($dso['dso.deleted']);
return $this->update($dso); return $this->update($dso, true);
} }
public function create(array $data = array()) : DSOInterface public function create(array $data = array()) : DSOInterface
@ -148,13 +148,15 @@ class Factory implements DSOFactoryInterface
return @$vcols[$path]['name']; return @$vcols[$path]['name'];
} }
public function update(DSOInterface &$dso) : bool public function update(DSOInterface &$dso, bool $sneaky = false) : bool
{ {
if (!$dso->changes() && !$dso->removals()) { if (!$dso->changes() && !$dso->removals()) {
return true; return true;
} }
$this->hook_update($dso); if (!$sneaky) {
$dso->hook_update(); $this->hook_update($dso);
$dso->hook_update();
}
$out = $this->driver->update($this->table, $dso); $out = $this->driver->update($this->table, $dso);
$dso->resetChanges(); $dso->resetChanges();
return $out; return $out;