/** * Pushes a new model on to the stack * * @param \Hubzero\Database\Relational|static $model The model to add * @return void * @since 2.0.0 **/ public function push(Relational $model) { // Index by primary key if possible, otherwise plain incremental array // Also check to see if that key already exists. If so, we'll just start // appending items to the array. This will result in a mixed array and // subsequent items will not be seekable. if ($model->getPkValue() && (!is_array($this->rows) || !array_key_exists($model->getPkValue(), $this->rows))) { $this->rows[$model->getPkValue()] = $model; } else { $this->rows[] = $model; } }
/** * Gets the relations that will be seeded on to the provided rows * * @param array $keys The keys for which to fetch related items * @param closure $constraint The constraint function to limit related items * @return array * @since 2.0.0 **/ protected function getRelations($keys, $constraint = null) { if (isset($constraint)) { call_user_func_array($constraint, array($this->related)); } return $this->related->whereIn($this->relatedKey, array_unique($keys)); }
/** * Sets up the tests...called prior to each test * * @return void */ public function setUp() { \Hubzero\Database\Relational::setDefaultConnection($this->getMockDriver()); $app = new Application(); $app['client'] = new \Hubzero\Base\Client\Site(); $app['db'] = $this->getMockDriver(); $app['config'] = \App::get('config'); $this->loader = new Loader($app, ['path_app' => __DIR__ . '/fixtures/app/templates', 'path_core' => __DIR__ . '/fixtures/core/templates']); }
/** * Delete the record and all associated data * * @return boolean False if error, True on success */ public function destroy() { // Remove comments foreach ($this->authors as $author) { if (!$author->destroy()) { $this->addError($author->getError()); return false; } } // Attempt to delete the record return parent::destroy(); }
/** * Gets the parent asset id for the record * * @return int * @since 2.0.0 */ private function getAssetParentId() { $assetId = null; // Build the query to get the asset id for the parent category $query = new Query(); $query->select('id')->from('#__assets')->whereEquals('name', 'com_' . $this->model->getNamespace()); if ($results = $query->fetch()) { $result = $results[0]; $assetId = (int) $result->id; } return $assetId ? $assetId : $this->getRootId(); }
/** * Validates the set data attributes against the model rules * * @return bool **/ public function validate() { $valid = parent::validate(); if ($valid) { $results = \Event::trigger('content.onContentBeforeSave', array('com_wiki.comment.ctext', &$this, $this->isNew())); foreach ($results as $result) { if ($result === false) { $this->addError(Lang::txt('Content failed validation.')); $valid = false; } } } return $valid; }
/** * Get all records * * @param array $columns * @return object */ public static function all($columns = NULL) { return parent::all()->whereEquals('type', 'plugin'); }
/** * 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; }
/** * Save data * * @return bool */ public function save() { if (!is_string($this->get('preferences'))) { $this->set('preferences', json_encode($this->get('preferences'))); } return parent::save(); }
/** * 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; }
/** * 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; }
/** * Transforms a namespace to an object * * @return object An an object holding the namespace data */ public function toObject() { $data = parent::toObject(); $this->access(); $data->params = $this->params->toObject(); return $data; }
/** * Delete the record and all associated data * * @return boolean False if error, True on success */ public function destroy() { // Remove data foreach ($this->comments()->rows() as $comment) { if (!$comment->destroy()) { $this->addError($comment->getError()); return false; } } foreach ($this->attachments()->rows() as $attachment) { if (!$attachment->destroy()) { $this->addError($attachment->getError()); return false; } } // Attempt to delete the record return parent::destroy(); }
/** * Sets up the tests...called prior to each test * * @return void **/ public function setUp() { \Hubzero\Database\Relational::setDefaultConnection($this->getMockDriver()); }
/** * 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; }
/** * Delete the record and all associated data * * @return boolean False if error, True on success */ public function destroy() { Event::trigger('courses.onCourseDelete', array($this)); // Remove offerings foreach ($this->offerings()->rows() as $offering) { if (!$offering->destroy()) { $this->addError($offering->getError()); return false; } } // Remove pages foreach ($this->pages()->rows() as $page) { if (!$page->destroy()) { $this->addError($page->getError()); return false; } } // Remove all tags $this->tag(''); // Attempt to delete the record return parent::destroy(); }
/** * 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(); }
/** * 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; }
/** * 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; }
/** * Delete record and associated data * * @return bool */ public function destroy() { // check to make sure its not the hub account if ($this->get('hub_account') == 1) { $this->setError('Unable to delete the hub account.'); return false; } if (!$this->revokeAccessTokens()) { return false; } if (!$this->revokeRefreshTokens()) { return false; } if (!$this->revokeAuthorizationCodes()) { return false; } foreach ($this->team()->rows() as $member) { if (!$member->destroy()) { $this->addError($member->getError()); return false; } } return parent::destroy(); }
/** * Delete the record and all associated data * * @return boolean False if error, True on success */ public function destroy() { // Can't delete what doesn't exist if ($this->isNew()) { return true; } // Remove comments foreach ($this->options as $option) { if (!$option->destroy()) { $this->addError($option->getError()); return false; } } // Attempt to delete the record return parent::destroy(); }
/** * Delete the record and all associated data * * @return boolean False if error, True on success */ public function destroy() { // Can't delete what doesn't exist if ($this->isNew()) { return true; } // Remove comments foreach ($this->replies() as $comment) { if (!$comment->destroy()) { $this->setError($comment->getError()); return false; } } foreach ($this->votes() as $vote) { if (!$vote->destroy()) { $this->setError($vote->getError()); return false; } } return parent::destroy(); }
/** * Delete record * * @return boolean True if successful, False if not */ public function destroy() { $path = $this->path(); if (file_exists($path)) { if (!\Filesystem::delete($path)) { $this->addError('Unable to delete file.'); return false; } } return parent::destroy(); }
/** * Delete the record and all associated data * * @return boolean False if error, True on success */ public function destroy() { // Remove comments foreach ($this->replies()->rows() as $comment) { if (!$comment->destroy()) { $this->addError($comment->getError()); return false; } } // Remove vote logs foreach ($this->votes()->rows() as $vote) { if (!$vote->destroy()) { $this->addError($vote->getError()); return false; } } // Attempt to delete the record return parent::destroy(); }
/** * 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; }
/** * Delete the record and all associated data * * @return boolean False if error, True on success */ public function destroy() { // Remove comments foreach ($this->comments() as $comment) { if (!$comment->destroy()) { $this->setError($comment->getError()); return false; } } // Remove all tags $this->tag(''); // Remove vote logs foreach ($this->votes() as $vote) { if (!$vote->destroy()) { $this->setError($vote->getError()); return false; } } // Attempt to delete the record return parent::destroy(); }
/** * Delete the record and all associated data * * @return boolean False if error, True on success */ public function destroy() { // Remove data foreach ($this->options() as $item) { if (!$item->destroy()) { $this->setError($item->getError()); return false; } } // Remove vote logs foreach ($this->dates() as $dt) { if (!$dt->destroy()) { $this->setError($dt->getError()); return false; } } // Remove vote logs foreach ($this->menus() as $menu) { if (!$menu->destroy()) { $this->setError($menu->getError()); return false; } } // Attempt to delete the record return parent::destroy(); }
/** * Delete the record and all associated data * * @return boolean False if error, True on success */ public function destroy() { // Can't delete what doesn't exist if (!$this->get('id')) { return true; } // Remove children foreach ($this->children()->rows() as $category) { if (!$category->destroy()) { $this->setError($category->getError()); return false; } } // Attempt to delete the record return parent::destroy(); }
/** * Delete the record and all associated data * * @return boolean False if error, True on success */ public function destroy() { // Remove ratings foreach ($this->ratings as $rating) { if (!$rating->destroy()) { $this->addError($rating->getError()); return false; } } // Remove versions foreach ($this->versions as $version) { if (!$version->destroy()) { $this->addError($version->getError()); return false; } } // Attempt to delete the record return parent::destroy(); }
/** * Delete the record and all associated data * * @return boolean False if error, True on success */ public function destroy() { // Remove files $path = $this->filespace() . DS . $this->get('page_id') . DS . $this->get('filename'); if (file_exists($path)) { if (!\Filesystem::delete($path)) { $this->addError(Lang::txt('COM_WIKI_ERROR_UNABLE_TO_DELETE_FILE', $this->get('filename'))); return false; } } if (!$this->get('id')) { return true; } return parent::destroy(); }