Esempio n. 1
0
 /**
  * Save data
  *
  * @return  boolean
  */
 public function save()
 {
     // Trigger the onUserBeforeSave event.
     $data = $this->toArray();
     $isNew = $this->isNew();
     // Allow an exception to be thrown.
     try {
         $oldUser = self::oneOrNew($this->get('id'));
         // Trigger the onUserBeforeSave event.
         $result = Event::trigger('user.onUserBeforeSave', array($oldUser->toArray(), $isNew, $data));
         if (in_array(false, $result, true)) {
             // Plugin will have to raise its own error or throw an exception.
             return false;
         }
         // Get any set access groups
         $groups = null;
         if ($this->hasAttribute('accessgroups')) {
             $groups = $this->get('accessgroups');
             $this->removeAttribute('accessgroups');
         }
         // Save record
         $result = parent::save();
         if (!$result) {
             throw new Exception($this->getError());
         }
         // Update access groups
         if ($groups && is_array($groups)) {
             Map::destroyByUser($this->get('id'));
             Map::addUserToGroup($this->get('id'), $groups);
         }
         // In case it's a new user, we need to grab the ID
         $data['id'] = $this->get('id');
         // Fire the onUserAfterSave event
         Event::trigger('user.onUserAfterSave', array($data, $isNew, $result, $this->getError()));
         $this->purgeCache();
     } catch (Exception $e) {
         $this->addError($e->getMessage());
         $result = false;
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * Save entry
  *
  * @return  object
  */
 public function save()
 {
     $action = $this->isNew() ? 'tag_created' : 'tag_edited';
     $result = parent::save();
     if ($result) {
         $log = Log::blank();
         $log->set('tag_id', $this->get('id'));
         $log->set('action', $action);
         $log->set('comments', $this->toJson());
         $log->save();
     }
     $this->purgeCache();
     return $result;
 }
Esempio n. 3
0
 /**
  * Override save to add logging
  *
  * @return  boolean
  */
 public function save()
 {
     // Use getInstance, rather than User::get('username'), as existing
     // user object won't get the right username if it was just updated
     $username = $this->member()->get('username');
     // Don't try to save quotas for auth link temp accounts (negative number usernames)
     if (is_numeric($username) && $username < 0) {
         return false;
     }
     $action = $this->get('id') ? 'modify' : 'add';
     $result = parent::save();
     if ($result) {
         $command = "update_quota '" . $this->get('user_id') . "' '" . $this->get('soft_blocks') . "' '" . $this->get('hard_blocks') . "'";
         $cmd = "/bin/sh " . PATH_CORE . "/components/com_tools/scripts/mw {$command} 2>&1 </dev/null";
         exec($cmd, $results, $status);
         // Check exec status
         if (!isset($status) || $status != 0) {
             // Something went wrong
             $this->addError(Lang::txt('COM_MEMBERS_QUOTA_USER_FAILED_TO_SAVE_TO_FILESYSTEM'));
             return false;
         }
         $log = Log::blank();
         $log->set('object_type', 'class');
         $log->set('object_id', (int) $this->get('id'));
         $log->set('name', (string) $this->get('alias'));
         $log->set('action', (string) $action);
         $log->set('actor_id', (int) User::get('id'));
         $log->set('soft_blocks', (int) $this->get('soft_blocks'));
         $log->set('hard_blocks', (int) $this->get('hard_blocks'));
         $log->set('soft_files', (int) $this->get('soft_files'));
         $log->set('hard_files', (int) $this->get('hard_files'));
         $log->save();
     }
     return $result;
 }
Esempio n. 4
0
 /**
  * Save the record
  *
  * @return  boolean  False if error, True on success
  */
 public function save()
 {
     if (!$this->get('access')) {
         $this->set('access', (int) \Config::get('access'));
     }
     $result = parent::save();
     // Make sure state changes carry through to posts
     if ($result) {
         foreach ($this->posts()->rows() as $post) {
             // If it's marked as deleted, skip it
             if ($post->get('state') == self::STATE_DELETED) {
                 continue;
             }
             $post->set('state', $this->get('state'));
             $post->save();
         }
     }
     return $result;
 }
Esempio n. 5
0
 /**
  * Save record
  * 
  * @return  bool
  */
 public function save()
 {
     // check to make sure its not the hub account
     if ($this->get('state') == self::STATE_DELETED) {
         if (!$this->revokeAccessTokens()) {
             return false;
         }
         if (!$this->revokeRefreshTokens()) {
             return false;
         }
         if (!$this->revokeAuthorizationCodes()) {
             return false;
         }
     }
     return parent::save();
 }
Esempio n. 6
0
 /**
  * Saves the current model to the database
  *
  * @return  bool
  */
 public function save()
 {
     $params = $this->get('params');
     if (is_object($params)) {
         $this->set('params', $params->toString());
     }
     $result = parent::save();
     $this->set('params', $params);
     return $result;
 }
Esempio n. 7
0
 /**
  * Saves the current model to the database
  *
  * @return  bool
  */
 public function save()
 {
     // Make sure children inherit states
     if ($this->get('state') == self::STATE_DELETED || $this->get('state') == self::STATE_UNPUBLISHED) {
         foreach ($this->replies()->rows() as $comment) {
             $comment->set('state', $this->get('state'));
             if (!$comment->save()) {
                 $this->addError($comment->getError());
                 return false;
             }
         }
     }
     return parent::save();
 }
Esempio n. 8
0
 /**
  * Delete the record and all associated data
  *
  * @return  boolean  False if error, True on success
  */
 public function save()
 {
     if ($data = $this->get('details')) {
         if ($data instanceof Registry) {
             $this->set('details', $data->toString());
         } else {
             if (!is_string($data)) {
                 $this->set('details', json_encode($data));
             }
         }
     }
     $result = parent::save();
     if ($result) {
         Event::trigger('activity.onLogSave', [$this]);
     }
     return $result;
 }
Esempio n. 9
0
 /**
  * Saves the current model to the database
  *
  * @return  bool
  */
 public function save()
 {
     // Bind the rules as appropriate.
     if (is_array($this->get('rules'))) {
         $this->set('rules', json_encode($this->get('rules')));
     }
     return parent::save();
 }
Esempio n. 10
0
 /**
  * Store the record
  *
  * @return  boolean  False if error, True on success
  */
 public function save()
 {
     $result = parent::save();
     if ($result) {
         Event::trigger('courses.onCourseSave', array($this));
     }
     return $result;
 }
Esempio n. 11
0
 /**
  * Save the record
  *
  * @return  boolean  False if error, True on success
  */
 public function save()
 {
     $section = $this->get('section');
     $this->removeAttribute('section');
     $category = $this->get('category');
     $this->removeAttribute('category');
     if (!$this->get('access')) {
         $this->set('access', (int) \Config::get('access'));
     }
     $isNew = $this->isNew();
     if ($isNew && !$this->get('parent')) {
         $this->set('lft', 0);
         $this->set('rgt', 1);
     }
     if ($this->isNew() && $this->get('parent')) {
         $parent = $this->parent();
         if (!$parent) {
             $this->addError(Lang::txt('Parent node does not exist.'));
             return false;
         }
         // Get the reposition data for shifting the tree and re-inserting the node.
         if (!($reposition = $this->getTreeRepositionData($parent, 2, 'last-child'))) {
             // Error message set in getNode method.
             return false;
         }
         // Shift left values.
         $query = $this->getQuery()->update($this->getTableName())->set(['lft' => new Raw('lft + 2')])->where($reposition->left_where['col'], $reposition->left_where['op'], $reposition->left_where['val'])->whereEquals('scope', $parent->get('scope'))->whereEquals('scope_id', $parent->get('scope_id'))->whereEquals('thread', $parent->get('thread'));
         if (!$query->execute()) {
             $this->addError($query->getError());
             return false;
         }
         // Shift right values.
         $query = $this->getQuery()->update($this->getTableName())->set(['rgt' => new Raw('rgt + 2')])->where($reposition->right_where['col'], $reposition->right_where['op'], $reposition->right_where['val'])->whereEquals('scope', $parent->get('scope'))->whereEquals('scope_id', $parent->get('scope_id'))->whereEquals('thread', $parent->get('thread'));
         if (!$query->execute()) {
             $this->addError($query->getError());
             return false;
         }
         $this->set('lft', $reposition->new_lft);
         $this->set('rgt', $reposition->new_rgt);
     }
     $result = parent::save();
     if ($result) {
         // Set the thread ID
         if (!$this->get('parent')) {
             $this->set('thread', $this->get('id'));
             $result = parent::save();
         }
         if (!$isNew) {
             // Make sure state and category changes carry through to replies
             // If it's marked as deleted, skip it
             $query = $this->getQuery()->update($this->getTableName())->set(['state' => $this->get('state'), 'category_id' => $this->get('category_id')])->whereEquals('parent', $this->get('id'))->where('state', '!=', self::STATE_DELETED);
             if (!$query->execute()) {
                 $this->addError($query->getError());
                 return false;
             }
             // Make sure state changes carry through to attachments
             $query = $this->getQuery()->update(Attachment::blank()->getTableName())->set(['state' => $this->get('state')])->whereEquals('post_id', $this->get('id'))->where('state', '!=', self::STATE_DELETED);
             if (!$query->execute()) {
                 $this->addError($query->getError());
                 return false;
             }
         }
     }
     if ($section) {
         $this->set('section', $section);
     }
     if ($category) {
         $this->set('category', $category);
     }
     return $result;
 }
Esempio n. 12
0
 /**
  * Save data
  *
  * @return  bool
  */
 public function save()
 {
     if (!is_string($this->get('preferences'))) {
         $this->set('preferences', json_encode($this->get('preferences')));
     }
     return parent::save();
 }
Esempio n. 13
0
 /**
  * Saves the current model to the database
  *
  * @return  bool
  */
 public function save()
 {
     if ($result = parent::save()) {
         // Rebuild the nested set tree.
         $this->rebuild();
     }
     return $result;
 }
Esempio n. 14
0
 /**
  * Override save to add logging
  *
  * @return  boolean
  */
 public function save()
 {
     $action = $this->get('id') ? 'modify' : 'add';
     $result = parent::save();
     if ($result) {
         $log = Log::blank();
         $log->set('object_type', 'class');
         $log->set('object_id', $this->get('id'));
         $log->set('name', $this->get('alias'));
         $log->set('action', $action);
         $log->set('actor_id', User::get('id'));
         $log->set('soft_blocks', $this->get('soft_blocks'));
         $log->set('hard_blocks', $this->get('hard_blocks'));
         $log->set('soft_files', $this->get('soft_files'));
         $log->set('hard_files', $this->get('hard_files'));
         $log->save();
     }
     return $result;
 }
Esempio n. 15
0
 /**
  * Save the entry
  *
  * @return  boolean  False if error, True on success
  */
 public function save()
 {
     $action = $this->isNew() ? 'page_created' : 'page_edited';
     // Make sure the path is updated
     if ($this->get('parent')) {
         $path = array();
         foreach ($this->ancestors() as $ancestor) {
             $path[] = $ancestor->get('pagename');
         }
         $this->set('path', implode('/', $path));
     }
     // Save
     $result = parent::save();
     // Log the action upon success
     if ($result) {
         $this->log($action);
     }
     return $result;
 }