/** * @param SproutSeo_MetaModel $model * @return bool * @throws Exception */ public function saveDefault(SproutSeo_MetaModel $model) { if ($id = $model->getAttribute('id')) { if (null === ($record = $this->metaRecord->findByPk($id))) { throw new Exception(Craft::t('Can\'t find default with ID "{id}"', array('id' => $id))); } } else { $record = $this->metaRecord->create(); } // @todo - Can we improve how validation is handled here? // Setting the second argument to 'false' allows us to save unsafe attributes $record->setAttributes($model->getAttributes(), false); if ($record->save()) { // update id on model (for new records) $model->setAttribute('id', $record->getAttribute('id')); return true; } else { $model->addErrors($record->getErrors()); return false; } }