/** * save * * @param int|string $pk * @param Data $data * * @return void * * @throws ValidFailException */ protected function save($pk, Data $data) { // Pre save if (!UserHelper::canDeletePost($this->record)) { throw new ValidFailException('Permission deny'); } if ($this->primary) { $this->hmvc($controller = new TopicDeleteController(), array('cid' => $this->record->topic_id)); } else { parent::save($pk, $data); } // Post save $this->topic->replies--; $this->topic->store(); }
protected function doExecute() { $data = $this->input->getVar('category'); $data = new Data($data); $data['title'] = trim($data['title']); if (!$data['title']) { $this->setRedirect(Router::build('admin:categories'), 'Title should not be empty', 'danger'); return false; } if (!$data['blog']) { $data['blog'] = Blog::get()->id; } $data['alias'] = OutputFilter::stringURLSafe(trim($data['title'])); $data['alias'] = $data['alias'] ?: OutputFilter::stringURLSafe((string) new Date()); $data['state'] = 1; if (!$data['ordering']) { $max = $this->getMaxOrder($data['blog']); $data['ordering'] = $max + 1; } try { $category = new Record('categories'); if ($data['id']) { $category->load($data['id']); } $category->bind($data); $category->check(); $category->store(true); } catch (\Exception $e) { if (WINDWALKER_DEBUG) { throw $e; } $this->setRedirect(Router::build('admin:categories'), 'Save Error', 'danger'); return false; } $this->setRedirect(Router::build('admin:categories'), 'Create success', 'success'); return true; }
/** * Method to test store(). * * @return void * * @covers Windwalker\Record\Record::store */ public function testStore() { $data = array('title' => 'Lancelot', 'meaning' => 'First Knight'); $record = new Record('ww_flower'); $record->bind($data); $record->foo = 'Forbidden'; $record->store(); $record = new Record('ww_flower'); $record->load(array('title' => 'Lancelot')); $this->assertEquals('First Knight', $record->meaning); }