示例#1
0
 /**
  * @return bool
  * @throws Exception
  */
 public function execute()
 {
     $originalTable = $this->entity->getTable();
     $data = $this->entity->tabelizeRecord($this->record);
     foreach ($data as $table => $update) {
         if ($this->tables && !in_array($table, $this->tables)) {
             continue;
         }
         if ($table == $this->entity->getTable()) {
             $this->update($table, $update);
         } else {
             // we don't know if children exists
             $this->updateOrInsert($table, $update);
         }
     }
     $this->entity->setTable($originalTable);
     return true;
 }
示例#2
0
 /**
  *
  */
 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;
 }
示例#3
0
 /**
  * @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()};
 }