|
|
@@ -97,6 +97,8 @@ abstract class ModelBase
|
|
|
|
|
|
public function save()
|
|
|
{
|
|
|
+ \Tools\Hook::trigger("onBeforeEntitySave");
|
|
|
+ \Tools\Hook::trigger("onBeforeEntitySave".$this->getTableName());
|
|
|
//TODO send pre-hook
|
|
|
if ($this->id === null)
|
|
|
{
|
|
|
@@ -117,21 +119,24 @@ abstract class ModelBase
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (empty($this->changed))
|
|
|
- return true;
|
|
|
- if ($this->id === false)
|
|
|
- throw new \Exception("Cannot update private row");
|
|
|
- $query = "UPDATE {$this->getTableName()} SET ";
|
|
|
- $newValues = array();
|
|
|
- foreach ($this->changed as $i => $j)
|
|
|
- $newValues[] = "`{$i}`=" . self::$dbo->quote($j);
|
|
|
- $query .= implode(",",$newValues)." WHERE id={$this->id}";
|
|
|
- $result = self::$dbo->exec($query);
|
|
|
- if (!$result)
|
|
|
- throw new \Exception(self::$dbo->errorInfo()[2]);
|
|
|
- $this->changed = array();
|
|
|
+ if (!empty($this->changed))
|
|
|
+ {
|
|
|
+ if ($this->id === false)
|
|
|
+ throw new \Exception("Cannot update private row");
|
|
|
+ $query = "UPDATE {$this->getTableName()} SET ";
|
|
|
+ $newValues = array();
|
|
|
+ foreach ($this->changed as $i => $j)
|
|
|
+ $newValues[] = "`{$i}`=" . self::$dbo->quote($j);
|
|
|
+ $query .= implode(",",$newValues)." WHERE id={$this->id}";
|
|
|
+ $result = self::$dbo->exec($query);
|
|
|
+ if (!$result)
|
|
|
+ throw new \Exception(self::$dbo->errorInfo()[2]);
|
|
|
+ $this->changed = array();
|
|
|
+ }
|
|
|
}
|
|
|
//TODO send hook
|
|
|
+ \Tools\Hook::trigger("onAfterEntitySave");
|
|
|
+ \Tools\Hook::trigger("onAfterEntitySave".$this->getTableName());
|
|
|
}
|
|
|
|
|
|
public function selects($criteria = null)
|