Exemple #1
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;
 }