Esempio n. 1
0
 /**
  * Delete news category
  *
  * @param integer $id
  * @return array
  */
 public function delete($id)
 {
     $repo = $this->store()->getRepository('news_category');
     $repo->appendLockTables(['tbl_news', 'tbl_news_category_link']);
     $entity = $this->finder()->filter(['ID' => $id])->get();
     if ($entity === false) {
         $repo->rollback();
         throw new \RuntimeException("Error news category is not found.");
     }
     $event = $this->store()->getEvent();
     if ($this->string()->length($event) > 0) {
         $event = 'OnPost' . $this->string()->ucwords($event) . 'Delete';
         Event::on($event, function ($id) {
             if (!NewsCategoryLink::deleteAllByCategoryId($id)) {
                 throw new \RuntimeException("Error delete link on news category.");
             }
         });
     }
     return $this->store()->delete($repo, $entity);
 }
Esempio n. 2
0
 /**
  * Delete user
  *
  * @param integer $id
  * @return boolean
  */
 public function delete($id)
 {
     $repo = $this->store()->getRepository('user');
     $entity = $this->finder()->filter(['ID' => $id])->get();
     if ($entity === false) {
         $repo->rollback();
         throw new \RuntimeException("User is not found.");
     }
     $event = $this->store()->getEvent();
     if ($this->string()->length($event) > 0) {
         $event_post = 'OnPost' . $this->string()->ucwords($event) . 'Delete';
         Event::on($event_post, function ($id) {
             if (!UserGroupMember::deleteAllByUserId($id)) {
                 throw new \RuntimeException("Error delete groups member.");
             }
         });
         $event_after = 'OnAfter' . $this->string()->ucwords($event) . 'Delete';
         Event::on($event_after, function () {
             Cache::clearByTags('user');
         });
     }
     return $this->store()->delete($repo, $entity);
 }