save() public method

Save the data associated with this model instance to the database.
public save ( ) : null
return null
Example #1
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 protected function setUp()
 {
     $this->user = Model::fromArray(array('lastname' => 'Test', 'firstname' => 'Test', 'email' => '*****@*****.**', 'login' => 'test-user-model', 'user_acl_role_id' => 1));
     $this->user->setPassword('test-user-model-password');
     $this->user->save();
     $this->object = new Acl($this->user);
 }
Example #2
0
 public function edit($id)
 {
     if (IS_POST) {
         //获取数据
         if ($this->model->create() !== false) {
             //判断数据是否正确
             if ($this->model->save() !== false) {
                 $this->success('修改成功', cookie('__forward__'));
                 return;
                 //防止后面代码执行
             }
         }
         $this->error('修改失败');
     } else {
         //调用钩子函数
         $this->_before_edit_view();
         //给页面分配树的数据
         $row = $this->model->find($id);
         //页面分配数据
         $this->assign('meta_title', '编辑' . $this->meta_title);
         $this->assign('row', $row);
         $this->assign('id', $id);
         //加载视图
         $this->display('add');
     }
 }
 /**
  * Triggered when we're passed an error from the `WhistleComponent`
  *
  * @param   array $error
  * @return  void
  */
 public function error($error)
 {
     $error['level'] = $this->_translateError($error['level']);
     $data = array();
     if ($this->_model->name == 'RefereeLog') {
         if (!empty($error['args'])) {
             $error['args'] = serialize($error['args']);
         }
         if (!empty($error['trace'])) {
             $error['trace'] = serialize($error['trace']);
         }
         if (!empty($error['request_parameters'])) {
             $error['request_parameters'] = serialize($error['request_parameters']);
         }
         $data = $error;
     } else {
         $schema = array_keys($this->_model->schema());
         $mapping = $this->_config['mapping'];
         foreach ($error as $key => $value) {
             if (!empty($mapping[$key])) {
                 if (is_array($mapping[$key])) {
                     $column = array_pop(array_intersect($mapping[$key], $schema));
                 } else {
                     $column = in_array($mapping[$key], $schema) ? $mapping[$key] : null;
                 }
                 if (!empty($column)) {
                     $data[$column] = $value;
                 }
             }
         }
     }
     $this->_model->save($data);
 }
Example #4
0
 /**
  * Set current version for given type
  *
  * @param integer $version Current version
  * @param string $type Can be 'app' or a plugin name
  * @param boolean $migrated If true, will add the record to the database
  * 		If false, will remove the record from the database
  * @return boolean
  */
 public function setVersion($version, $type, $migrated = true)
 {
     if ($migrated) {
         $this->Version->create();
         return $this->Version->save(array('version' => $version, 'type' => $type));
     } else {
         $conditions = array($this->Version->alias . '.version' => $version, $this->Version->alias . '.type' => $type);
         return $this->Version->deleteAll($conditions);
     }
 }
Example #5
0
 private function addData()
 {
     $validated = $this->modelInstance->setData($this->modelData);
     if ($validated === true) {
         $this->modelInstance->save();
         $this->added++;
         return 'Added';
     } else {
         return $validated;
     }
 }
Example #6
0
 /**
  * Implements writing to log table.
  *
  * @param string $type The type of log you are making.
  * @param string $content The message you want to log.
  * @return boolean success of write.
  */
 public function write($type, $content, $module = 'system', $foreign_key = 0)
 {
     $data = compact('type', 'content', 'module', 'foreign_key');
     $user = AuthComponent::user();
     if (!empty($user)) {
         $data['user_id'] = $user['id'];
         $data['username'] = $user['name'];
     }
     self::$_model->create();
     return self::$_model->save($data);
 }
Example #7
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 public function setUp()
 {
     $this->init();
     $this->view = ViewModel::fromArray(array('name' => 'View Name', 'identifier' => 'View identifier', 'description' => 'View Description', 'content' => 'View Content'));
     $this->view->save();
     $this->layout = LayoutModel::fromArray(array('name' => 'Layout Name', 'identifier' => 'Layout identifier', 'description' => 'Layout Description', 'content' => 'Layout Content'));
     $this->layout->save();
     $this->documentType = DocumentTypeModel::fromArray(array('name' => 'Document Type Name', 'description' => 'Document Type description', 'icon_id' => 1, 'defaultview_id' => $this->view->getId(), 'user_id' => $this->user->getId()));
     $this->documentType->save();
     $this->document = DocumentModel::fromArray(array('name' => 'Document name', 'url_key' => 'url-key', 'status' => DocumentModel::STATUS_ENABLE, 'show_in_nav' => true, 'user_id' => $this->user->getId(), 'document_type_id' => $this->documentType->getId(), 'view_id' => $this->view->getId(), 'layout_id' => $this->layout->getId(), 'parent_id' => null));
     $this->document->save();
     ModuleModel::install(Registry::get('Application')->getServiceManager()->get('CustomModules'), 'Blog');
 }
Example #8
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 protected function setUp()
 {
     $this->view = ViewModel::fromArray(array('name' => 'View Name', 'identifier' => 'View identifier', 'description' => 'View Description', 'content' => 'View Content'));
     $this->view->save();
     $this->layout = LayoutModel::fromArray(array('name' => 'Layout Name', 'identifier' => 'Layout identifier', 'description' => 'Layout Description', 'content' => 'Layout Content'));
     $this->layout->save();
     $this->user = UserModel::fromArray(array('lastname' => 'User test', 'firstname' => 'User test', 'email' => '*****@*****.**', 'login' => 'test', 'user_acl_role_id' => 1));
     $this->user->setPassword('test');
     $this->user->save();
     $this->documentType = DocumentTypeModel::fromArray(array('name' => 'Document Type Name', 'description' => 'Document Type description', 'icon_id' => 1, 'defaultview_id' => $this->view->getId(), 'user_id' => $this->user->getId()));
     $this->documentType->save();
     $this->document = DocumentModel::fromArray(array('name' => 'Document name', 'url_key' => 'url-key', 'status' => DocumentModel::STATUS_ENABLE, 'show_in_nav' => true, 'user_id' => $this->user->getId(), 'document_type_id' => $this->documentType->getId(), 'view_id' => $this->view->getId(), 'layout_id' => $this->layout->getId(), 'parent_id' => null));
     $this->document->save();
     $this->object = new Sitemap();
 }
 public function testMultipleUploadSaveReadDelete()
 {
     // setup
     $this->Model->Behaviors->load('Media.Attachable', array());
     $this->Model->configureAttachment(array('files' => array('baseDir' => $this->attachmentDir, 'multiple' => true, 'removeOnOverwrite' => true)), true);
     $data = array($this->Model->alias => array('title' => 'My Upload', 'files_upload' => array($this->upload1, $this->upload2)));
     // save
     $this->Model->create();
     $result = $this->Model->save($data);
     $this->assertTrue(isset($this->Model->id));
     $this->assertEqual($result[$this->Model->alias]['files_upload'], '');
     $this->assertEqual(preg_match('/Upload_File_1_([0-9a-z]+).txt,Upload_File_2_([0-9a-z]+).txt$/', $result[$this->Model->alias]['files']), 1);
     $this->assertTrue(isset($result['Attachment']['files'][0]['path']));
     $this->assertTrue(file_exists($result['Attachment']['files'][0]['path']));
     $this->assertTrue(isset($result['Attachment']['files'][1]['path']));
     $this->assertTrue(file_exists($result['Attachment']['files'][1]['path']));
     // read
     $modelId = $this->Model->id;
     $this->Model->create();
     $result = $this->Model->read(null, $modelId);
     $this->assertTrue(isset($result[$this->Model->alias]['files']));
     $this->assertTrue(!isset($result[$this->Model->alias]['files_upload']));
     $this->assertEqual(preg_match('/Upload_File_1_([0-9a-z]+).txt,Upload_File_2_([0-9a-z]+).txt$/', $result[$this->Model->alias]['files']), 1);
     $this->assertTrue(isset($result['Attachment']['files'][0]['path']));
     $this->assertTrue(file_exists($result['Attachment']['files'][0]['path']));
     $this->assertTrue(isset($result['Attachment']['files'][1]['path']));
     $this->assertTrue(file_exists($result['Attachment']['files'][1]['path']));
     //delete
     $deleted = $this->Model->delete($this->Model->id);
     $this->assertTrue($deleted, 'Failed to delete Attachment');
     $this->assertTrue(!file_exists($result['Attachment']['files'][0]['path']), 'Attachment not deleted');
     $this->assertTrue(!file_exists($result['Attachment']['files'][1]['path']), 'Attachment not deleted');
 }
Example #10
0
 public function save(array $options = [])
 {
     if (empty($this->finished_at)) {
         $this->finished_at = new DateTime();
     }
     return parent::save($options);
 }
Example #11
0
 function save()
 {
     $this->import_parameters();
     $this->load_library('htmlpurifier-4.5.0-lite/library/HTMLPurifier.auto');
     $config = HTMLPurifier_Config::createDefault();
     $purifier = new HTMLPurifier($config);
     $message = $purifier->purify(html_entity_decode($this->message));
     $this->set('message', $message);
     $reference_object = new $this->reference_object($this->reference_id);
     //if the message is being created for an object other than a project, then the project id will be retrieved from
     //the actual object
     //if the message is being posted on a project, then the project id is the messages reference_id
     if ($this->reference_object != 'project') {
         $project_id = isset($reference_object->project_id) ? $reference_object->project_id : false;
     } else {
         $project_id = $this->reference_id;
     }
     if ($project_id) {
         $this->set('project_id', $project_id);
     }
     if (isset($reference_object->client_id)) {
         $this->set('client_id', $reference_object->client_id);
     }
     $this->set('user_id', current_user()->id);
     //these two parameters shouldn't be set yet (they are set when we log activity which happens after the save),
     //but let's just make sure
     $this->unset_param('linked_object');
     $this->unset_param('linked_object_title');
     $result = parent::save();
     ActivityManager::message_created($this);
     return $result;
 }
 public function save()
 {
     if ($this->permalink == "") {
         $this->permalink = self::make_permalink($this->name);
     }
     return parent::save(self::table);
 }
 public function save()
 {
     if (!$this->priority) {
         $this->priority = "Normal";
     }
     return parent::save(self::table);
 }
Example #14
0
 public function save()
 {
     //$form = Helper::createForm($wget='');
     $form = Helper::createForm();
     $postData = ipRequest()->getPost();
     $errors = $form->validate($postData);
     if ($errors) {
         // Validation error
         $status = array('status' => 'error', 'errors' => $errors);
         return new \Ip\Response\Json($status);
     } else {
         // Success
         Model::save(ipRequest()->getPost('language_id'), ipRequest()->getPost('zone_name'), ipRequest()->getPost('user_id'), ipRequest()->getPost('name'), ipRequest()->getPost('email'), ipRequest()->getPost('link'), ipRequest()->getPost('text'), ipRequest()->getPost('ip'), ipRequest()->getPost('approved'), ipRequest()->getPost('session_id'), ipRequest()->getPost('verification_code'), ipRequest()->getPost('active'));
         //get page where this widget sits :)
         $postData = ipRequest()->getPost();
         $vcode = $postData['verification_code'];
         $fullWidgetRecord = \Ip\Internal\Content\Model::getWidgetRecord($postData['wgetId']);
         $pageTitle = '';
         if (isset($fullWidgetRecord['revisionId'])) {
             $revision = \Ip\Internal\Revision::getRevision($fullWidgetRecord['revisionId']);
             if (!empty($revision['pageId'])) {
                 $pageTitle = ipPage($revision['pageId'])->getTitle();
             }
         }
         $stamp = date(__('m/d/Y', 'Comments')) . __(', at ', 'Comments') . date('H:i:s');
         //sending email notification
         Helper::sendMailNotification(trim(ipRequest()->getPost('zone_name')), trim(ipRequest()->getPost('name')), $stamp, trim(ipRequest()->getPost('text')), trim(ipRequest()->getPost('email')), trim($pageTitle), trim($vcode));
         //$actionUrl = ipActionUrl(array('sa' => 'FormExample.showSuccessMessage'));
         //$status = array('redirectUrl' => $actionUrl);
         $status = array('status' => 'ok');
         //success
         return new \Ip\Response\Json($status);
     }
 }
Example #15
0
 public function save(array $options = array())
 {
     if (!$this->reject_sn) {
         $this->reject_sn = uniqid();
     }
     parent::save($options);
 }
 public function save()
 {
     if ($this->code == "") {
         $this->code = md5(time() . rand(10000, 99999) . $this->user_id);
     }
     return parent::save(self::table);
 }
 public function save()
 {
     if ($this->is_new()) {
         $this->set('date_created', date('Y-m-d H:i:s'));
     }
     return parent::save();
 }
Example #18
0
 function import($sFile)
 {
     if (!$this->bSpycReady) {
         return self::SPYC_CLASS_NOT_FOUND;
     }
     if (!file_exists($sFile)) {
         return self::YAML_FILE_NOT_FOUND;
     }
     $this->aTables = SPYC::YAMLload(file_get_contents($sFile));
     if (!is_array($this->aTables)) {
         return self::YAML_FILE_IS_INVALID;
     }
     uses('model' . DS . 'model');
     $oDB = $this->oDb;
     $aAllowedTables = $oDB->listSources();
     foreach ($this->aTables as $table => $records) {
         if (!in_array($oDB->config['prefix'] . $table, $aAllowedTables)) {
             return self::TABLE_NOT_FOUND;
         }
         $temp_model = new Model(false, $table);
         foreach ($records as $record_num => $record_value) {
             if (!isset($record_value['id'])) {
                 $record_value['id'] = $record_num;
             }
             if (!$temp_model->save($record_value)) {
                 return array('error' => array('table' => $table, 'record' => $record_value));
             }
         }
     }
     return true;
 }
Example #19
0
 function save()
 {
     $this->import_parameters();
     //we need to determine if this is a new client before we do the initial save (it won't be new once we do the
     //initial save
     $is_new = $this->is_new();
     //unset params that aren't saved to the db
     $this->unset_param('primary_contact_name');
     $this->unset_param('primary_contact_image');
     $result = parent::save();
     if ($is_new == true) {
         $primary_contact = new User($_POST['client']);
         $primary_contact->set('client_id', $this->id);
         $primary_contact->validate();
         if ($primary_contact->validation_passed()) {
             $primary_contact->save();
             //set the client email and the primary contact id
             $this->set('email', $primary_contact->email);
             $this->set('primary_contact_id', $primary_contact->id);
             parent::save();
         } else {
             $this->set_error('first_name', Language::get('errors.saving_primary_contact'));
             return false;
         }
     }
     return $result;
 }
Example #20
0
 protected function makeModel()
 {
     $model = new Model();
     $model->name = 'Caching test model';
     $model->save();
     return $model;
 }
Example #21
0
 public function testSave()
 {
     $this->ormMock->expects($this->once())->method('isNew')->will($this->returnValue(true));
     $this->ormMock->expects($this->once())->method('mergeData')->with([]);
     $this->ormMock->expects($this->once())->method('save')->with(false, false, false)->will($this->returnValue(true));
     $this->assertTrue($this->model->save());
 }
Example #22
0
 public function save()
 {
     if (!$this->publish_at) {
         $this->publish_at = time();
     }
     return parent::save(self::table);
 }
 function remove(Model $model)
 {
     $foreignKey = $this->foreignKey;
     $model->{$foreignKey} = '';
     $model->save();
     return $model;
 }
Example #24
0
 public function save()
 {
     if (!$this->code) {
         $this->code = md5(uniqid('epic', true) . time());
     }
     return parent::save(self::table);
 }
Example #25
0
 public function save()
 {
     if (!$this->is_new) {
         $this->hash = self::hash_items($this->items(), $this);
     }
     return parent::save(self::table);
 }
 /**
  * Run before a model is deleted, used to do a soft delete when needed.
  *
  * @param object $model Model about to be deleted
  * @param boolean $cascade If true records that depend on this record will also be deleted
  * @return boolean Set to true to continue with delete, false otherwise
  * @access public
  */
 function beforeDelete(Model $model, $cascade = true)
 {
     if ($this->__settings[$model->alias]['delete'] && $model->hasField($this->__settings[$model->alias]['field'])) {
         $attributes = $this->__settings[$model->alias];
         $id = $model->id;
         $data = array($model->alias => array($attributes['field'] => 1));
         if (isset($attributes['field_date']) && $model->hasField($attributes['field_date'])) {
             $data[$model->alias][$attributes['field_date']] = $model->getDatasource()->expression('NOW()');
         }
         foreach (array_merge(array_keys($data[$model->alias]), array('field', 'field_date', 'find', 'delete')) as $field) {
             unset($attributes[$field]);
         }
         if (!empty($attributes)) {
             $data[$model->alias] = array_merge($data[$model->alias], $attributes);
         }
         $model->id = $id;
         $deleted = $model->save($data, false, array_keys($data[$model->alias]));
         if ($deleted && $cascade) {
             $model->_deleteDependent($id, $cascade);
             $model->_deleteLinks($id);
         }
         return false;
     }
     return true;
 }
 public function save()
 {
     $this->_addClientData();
     $this->session_id = static::$_sessionID;
     $this->request_data = json_encode($_REQUEST);
     parent::save();
 }
Example #28
0
 /**
  * Save the comment
  * @return Comment
  */
 public function save()
 {
     // Censor credit card numbers if enabled
     if (\Base::instance()->get("security.block_ccs") && preg_match("/[0-9-]{9,15}[0-9]{4}/", $this->get("text"))) {
         $this->set("text", preg_replace("/[0-9-]{9,15}([0-9]{4})/", "************\$1", $this->get("text")));
     }
     return parent::save();
 }
 public function save()
 {
     if ($this->validate()) {
         return parent::save(self::table);
     } else {
         return false;
     }
 }
Example #30
0
 public function save()
 {
     if ($this->permalink == "") {
         $this->permalink = self::make_permalink($this->tag);
     }
     // Do our own pre-initialisation
     return parent::save(self::table);
 }