Esempio n. 1
0
 /**
  * Delete the record and associated data
  *
  * @return  boolean  False if error, True on success
  */
 public function destroy()
 {
     $data = $this->toArray();
     // Trigger the onUserBeforeDelete event
     Event::trigger('user.onUserBeforeDelete', array($data));
     // Remove associated data
     if ($this->reputation->get('id')) {
         if (!$this->reputation->destroy()) {
             $this->addError($this->reputation->getError());
             return false;
         }
     }
     foreach ($this->tokens()->rows() as $token) {
         if (!$token->destroy()) {
             $this->addError($token->getError());
             return false;
         }
     }
     Map::destroyByUser($this->get('id'));
     // Attempt to delete the record
     $result = parent::destroy();
     if ($result) {
         // Trigger the onUserAfterDelete event
         Event::trigger('user.onUserAfterDelete', array($data, true, $this->getError()));
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * Delete this object and its dependencies
  *
  * @return  boolean
  */
 public function destroy()
 {
     if ($this->get('id') == 0) {
         $this->addError('JGLOBAL_CATEGORY_NOT_FOUND');
         return false;
     }
     if ($this->get('parent_id') == 0) {
         $this->addError('JLIB_DATABASE_ERROR_DELETE_ROOT');
         return false;
     }
     if ($this->get('lft') == 0 or $this->get('rgt') == 0) {
         $this->addError('JLIB_DATABASE_ERROR_DELETE_ROOT');
         return false;
     }
     // Select it's children
     $children = self::all()->where('lft', '>=', (int) $this->get('lft'))->where('rgt', '<=', (int) $this->get('rgt'))->rows();
     if (!$children->count()) {
         $this->addError('JLIB_DATABASE_ERROR_DELETE_CATEGORY');
         return false;
     }
     // Delete the dependencies
     $ids = array();
     foreach ($children as $child) {
         $ids[] = $child->get('id');
     }
     $query = $this->getQuery()->delete($this->getTableName())->whereIn('id', $ids);
     if (!$query->execute()) {
         $this->addError($query->getError());
         return false;
     }
     // Delete the usergroup in view levels
     $find = array();
     $replace = array();
     foreach ($ids as $id) {
         $find[] = "[{$id},";
         $find[] = ",{$id},";
         $find[] = ",{$id}]";
         $find[] = "[{$id}]";
         $replace[] = "[";
         $replace[] = ",";
         $replace[] = "]";
         $replace[] = "[]";
     }
     $rules = Viewlevel::all()->rows();
     foreach ($rules as $rule) {
         foreach ($ids as $id) {
             if (strstr($rule->get('rules'), '[' . $id) || strstr($rule->get('rules'), ',' . $id) || strstr($rule->get('rules'), $id . ']')) {
                 $rule->set('rules', str_replace($find, $replace, $rule->get('rules')));
                 if (!$rule->save()) {
                     $this->addError($rule->getError());
                     return false;
                 }
             }
         }
     }
     // Delete the user to usergroup mappings for the group(s) from the database.
     try {
         Map::destroyByGroup($ids);
     } catch (\Exception $e) {
         $this->addError($e->getMessage());
         return false;
     }
     return true;
 }