/** * */ public function execute() { $data = $this->entity->tabelizeRecord($this->record); /** * We need to get entity table extensions. * Lets hardcode them for now. */ $extensions = ['i18n', 'p17n', '']; $table = $this->entity->getTable(); $primaryKeys = $this->entity->getRepository()->getCache()->getTablePrimaryKeys($table); if (!$primaryKeys) { throw new Exception('Will NOT delete from table without primary keys ...'); } foreach ($extensions as $ext) { if ($ext) { $ext = '_' . $ext; } if ($this->entity->getRepository()->getCache()->hasTable($table . $ext)) { /** * We will delete record from $table ... */ $query = (new Delete())->setTable($table . $ext); /** * ... add primary key condition ... */ foreach ($primaryKeys as $key) { $query->where($key, $data[$table][$key]); } /** * ... prepare query ... */ $prepare = $this->repository->prepareQuery($query); /** * ... and execute it. */ $this->repository->executePrepared($prepare); } } $this->record->setSaved(false); $this->record->setDeleted(true); return true; }
/** * @return null * @throws Exception */ public function execute() { $data = $this->entity->tabelizeRecord($this->record); foreach ($data as $table => $insert) { if ($this->tables && !in_array($table, $this->tables)) { continue; } if ($this->record->{$this->entity->getPrimaryKey()}) { /** * Primary key is already set, we need to update it. */ $insert[$this->entity->getPrimaryKey()] = $this->record->{$this->entity->getPrimaryKey()}; $this->insert($table, $insert); } else { /** * Primary key is not set yet, we need to set it now. */ $this->record->{$this->entity->getPrimaryKey()} = $this->insert($table, $insert); $this->record->setSaved(); } } return $this->record->{$this->entity->getPrimaryKey()}; }