function save($data) { if (empty($data['Origin']) && !Set::numeric(array_keys($data))) { $data = array('Origin' => $data); } $key = null; if (!empty($data['Origin']['link'])) { $key = md5($data['Origin']['link']); if (!empty($this->__cache[$key])) { return $this->__cache[$key]; } } if (empty($data['Origin']['id']) && !empty($data['Origin']['provider_key'])) { $found = parent::find('first', array('conditions' => array('Origin.provider_key' => $data['Origin']['provider_key']))); if ($found) { unset($found['Origin']['modified']); $this->set($found); } } $this->set($data); $result = parent::save(); $result['Origin']['id'] = $this->id; if ($key) { $this->__cache[$key] = $result; } return $result; }
/** * Saves model data (based on white-list, if supplied) to the database. By * default, validation occurs before save. Passthrough method to _doSave() with * transaction handling. * * @param array $data Data to save. * @param bool|array $validate Either a boolean, or an array. * If a boolean, indicates whether or not to validate before saving. * If an array, can have following keys: * * - atomic: If true (default), will attempt to save the record in a single transaction. * - validate: Set to true/false to enable or disable validation. * - fieldList: An array of fields you want to allow for saving. * - callbacks: Set to false to disable callbacks. Using 'before' or 'after' * will enable only those callbacks. * - `counterCache`: Boolean to control updating of counter caches (if any) * * @param array $fieldList List of fields to allow to be saved * @return mixed On success Model::$data if its not empty or true, false on failure * @throws Exception * @throws PDOException * @triggers Model.beforeSave $this, array($options) * @triggers Model.afterSave $this, array($created, $options) * @link http://book.cakephp.org/2.0/en/models/saving-your-data.html * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ public function save($data = null, $validate = true, $fieldList = array()) { if ($this->useTable) { return parent::save($data, $validate, $fieldList); } if ($data) { $this->set($data); } $defaults = array('validate' => true, 'fieldList' => array(), 'callbacks' => true, 'counterCache' => true, 'atomic' => true); if (!is_array($validate)) { $options = compact('validate', 'fieldList') + $defaults; } else { $options = $validate + $defaults; } if ($options['callbacks'] === true || $options['callbacks'] === 'before') { $event = new CakeEvent('Model.beforeSave', $this, array($options)); list($event->break, $event->breakOn) = array(true, array(false, null)); $this->getEventManager()->dispatch($event); if (!$event->result) { //$this->whitelist = $_whitelist; return false; } } if ($options['callbacks'] === true || $options['callbacks'] === 'after') { $event = new CakeEvent('Model.afterSave', $this, array(false, $options)); $this->getEventManager()->dispatch($event); } }
/** * Overwrite save to write to the datasource defined in config * * {@inheritDoc} */ public function save($data = null, $validate = true, $fieldList = array()) { $this->setDataSourceWrite(); $retval = parent::save($data, $validate, $fieldList); $this->setDataSourceRead(); return $retval; }
function save($data) { App::import('Model', 'AccountingBukuBesar'); App::import('Model', 'AccountingAccount'); $bukubesar = new AccountingBukuBesar(); $account = new AccountingAccount(); //$type = $this->AccountingTransactionType // ->findById($data['AccountingTransaction']['accounting_transaction_type_id']); //$data['AccountingTransaction']['account_debit_id'] = $type['AccountingTransactionType']['account_debit_id']; //$data['AccountingTransaction']['account_credit_id'] = $type['AccountingTransactionType']['account_credit_id']; if (parent::save($data)) { $bukus = array(array('AccountingBukuBesar' => array('accounting_account_id' => $data['AccountingTransaction']['account_debit_id'], 'accounting_transaction_id' => $this->id, 'estimates' => 'DEBIT', 'amount' => $data['AccountingTransaction']['amount'], 'debit' => $data['AccountingTransaction']['amount'], 'credit' => 0)), array('AccountingBukuBesar' => array('accounting_account_id' => $data['AccountingTransaction']['account_credit_id'], 'accounting_transaction_id' => $this->id, 'estimates' => 'CREDIT', 'amount' => $data['AccountingTransaction']['amount'], 'debit' => 0, 'credit' => $data['AccountingTransaction']['amount']))); foreach ($bukus as $buku) { $b = $bukubesar->find('all', array('conditions' => array('AccountingBukuBesar.accounting_transaction_id' => $buku['AccountingBukuBesar']['accounting_transaction_id'], 'AccountingBukuBesar.estimates' => $buku['AccountingBukuBesar']['estimates']))); if (count($b) === 0) { $bukubesar->create(); } else { $bukubesar->id = $b[0]['AccountingBukuBesar']['id']; } $bukubesar->save($buku); $parent = $account->read(null, $buku['AccountingBukuBesar']['accounting_account_id']); if ($parent['AccountingAccount']['parent_id'] == 14) { $bukubesar->create(); $bukubesar->save(array('AccountingBukuBesar' => array('accounting_account_id' => 18, 'accounting_transaction_id' => $this->id, 'estimates' => 'DEBIT', 'amount' => $buku['AccountingBukuBesar']['amount'], 'debit' => $buku['AccountingBukuBesar']['amount'], 'credit' => 0))); } if ($parent['AccountingAccount']['parent_id'] == 2) { $bukubesar->create(); $bukubesar->save(array('AccountingBukuBesar' => array('accounting_account_id' => 18, 'accounting_transaction_id' => $this->id, 'estimates' => 'CREDIT', 'amount' => $buku['AccountingBukuBesar']['amount'], 'debit' => 0, 'credit' => $buku['AccountingBukuBesar']['amount']))); } } return true; } else { return false; } }
/** save */ public function save($dao) { if (!isset($dao->date) || empty($dao->date)) { $dao->setDate(date('Y-m-d H:i:s')); } parent::save($dao); }
function save($data) { $this->Origin->create(); $origin = $this->Origin->save($data['Origin']); if (!empty($data['ForwardOrigin'])) { $this->Origin->create(); $forwardOrigin = $this->Origin->save($data['ForwardOrigin']); } if ($this->Origin->isMuted($origin, $data['Item']['posted'])) { $data['Item']['read'] = true; } $data['Item']['origin_id'] = $origin['Origin']['id']; if (!empty($forwardOrigin)) { $data['Item']['forward_origin_id'] = $forwardOrigin['Origin']['id']; } if (empty($data['Item']['id']) && !empty($data['Item']['provider_id']) && !empty($data['Item']['provider_key'])) { $found = parent::find('first', array('conditions' => array('Item.provider_id' => $data['Item']['provider_id'], 'Item.provider_key' => $data['Item']['provider_key']))); if ($found) { $this->set($found); } } $this->set($data['Item']); $data = parent::save(); $data['Item']['id'] = $this->id; $data['Origin'] = $origin['Origin']; return $data; }
/** save */ public function save($dao) { if (!isset($dao->uuid) || empty($dao->uuid)) { /** @var UuidComponent $uuidComponent */ $uuidComponent = MidasLoader::loadComponent('Uuid'); $dao->setUuid($uuidComponent->generate()); } parent::save($dao); }
public function save($data, $validate = true, $fieldList = false) { $saved = parent::save($data, $validate, $fieldList); if ($saved) { Cache::delete($this->_key($this->id)); $this->findCached($this->id, true); } return $saved; }
function sess_regenerate() { $oldSessionID = session_id(); if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time() - 42000, '/'); } session_regenerate_id(); $Session = new AppModel('Session'); $Session->save(array('id' => session_id()), $oldSessionID); }
public function save($data = array()) { if (empty($this->id)) { if ($data['CanteenOrder']) { $data['CanteenOrder']['id'] = $this->genId(); $data['CanteenOrder']['hash'] = sha1($data['CanteenOrder']['id']); } else { $data['id'] = $this->genId(); $data['hash'] = sha1($data['id']); } } return parent::save($data); }
public function save($data = array()) { if (empty($this->id)) { if (isset($data['CanteenShippingRecord'])) { $data['CanteenShippingRecord']['id'] = $this->genId(); $data['CanteenShippingRecord']['hash'] = md5($data['CanteenShippingRecord']['id']); } else { $data['id'] = $this->genId(); $data['hash'] = md5($data['id']); } } return parent::save($data); }
function saveAll($data) { $fixedData = array(); $settings = $this->find('list', array('fields' => array('Setting.key', 'Setting.id'))); foreach ($data['Setting'] as $key => $value) { if (!empty($settings[$key])) { $fixedData = array('id' => $settings[$key], 'key' => trim($key), 'value' => trim($value)); if (!parent::save($fixedData)) { return false; } } } return true; }
/** save */ public function save($dao) { if (!isset($dao->uuid) || empty($dao->uuid)) { /** @var UuidComponent $uuidComponent */ $uuidComponent = MidasLoader::loadComponent('Uuid'); $dao->setUuid($uuidComponent->generate()); } $name = $dao->getName(); if (empty($name) && $name !== '0') { throw new Zend_Exception('Please set a name for the Community.'); } $cleanDescription = UtilityComponent::filterHtmlTags($dao->getDescription()); $dao->setDescription($cleanDescription); parent::save($dao); }
function save($data = null, $validate = true, $fieldList = array()) { // Changing this because simpletest always send image as 'application/octet-stream' if (isset($data['Meio']['filename']['type'])) { switch (substr($data['Meio']['filename']['name'], -4)) { case '.jpg': case '.jpeg': $data['Meio']['filename']['type'] = 'image/jpeg'; break; case '.png': $data['Meio']['filename']['type'] = 'image/png'; break; case '.gif': $data['Meio']['filename']['type'] = 'image/gif'; break; } } return parent::save($data, $validate, $fieldList); }
function save($data = null, $validate = true, $fieldList = array()) { $buySeatsDone = true; $buyTicketsDone = true; $this->begin(); if (parent::save($data, $validate)) { if (isset($data['BuyTicket'])) { $this->BuyTicket->delete(array('BuyTicket.buy_id' => $this->id)); foreach ($data['BuyTicket'] as $key => $ticket) { if ($ticket['qty'] > 0) { $ticket['buy_id'] = $this->id; $this->BuyTicket->create(); if (!$this->BuyTicket->save($ticket)) { $buyTicketsDone = false; } } else { unset($data['BuyTicket'][$key]); } } } if (isset($data['BuySeat'])) { $this->BuySeat->delete(array('BuySeat.buy_id' => $this->id)); foreach ($data['BuySeat'] as $seat) { $seat['buy_id'] = $this->id; $this->BuySeat->create(); if (!$this->BuySeat->save($seat)) { $buySeatsDone = false; } } } if (!$buySeatsDone || !$buyTicketsDone) { $this->rollback(); return false; } } $this->commit(); return true; }
function save($data = null, $validate = true, $fieldList = array()) { // se esiste un altro ordine uguale, sommo all'ordine precedente $existing = false; if (isset($data['OrderedProduct']['user_id'], $data['OrderedProduct']['seller_id'], $data['OrderedProduct']['product_id'], $data['OrderedProduct']['hamper_id'])) { if (!isset($data['OrderedProduct']['option_1'])) { $data['OrderedProduct']['option_1'] = null; } if (!isset($data['OrderedProduct']['option_2'])) { $data['OrderedProduct']['option_2'] = null; } if (!isset($data['OrderedProduct']['note'])) { $data['OrderedProduct']['note'] = null; } $existing = $this->find('first', array('conditions' => array('OrderedProduct.user_id' => $data['OrderedProduct']['user_id'], 'OrderedProduct.seller_id' => $data['OrderedProduct']['seller_id'], 'OrderedProduct.product_id' => $data['OrderedProduct']['product_id'], 'OrderedProduct.hamper_id' => $data['OrderedProduct']['hamper_id'], 'OrderedProduct.option_1' => $data['OrderedProduct']['option_1'], 'OrderedProduct.option_2' => $data['OrderedProduct']['option_2'], 'OrderedProduct.note' => $data['OrderedProduct']['note']), 'contain' => array())); } if (!empty($existing)) { $data['OrderedProduct']['id'] = $existing['OrderedProduct']['id']; $data['OrderedProduct']['quantity'] = $data['OrderedProduct']['quantity'] + $existing['OrderedProduct']['quantity']; $data['OrderedProduct']['value'] = str_replace(',', '.', $data['OrderedProduct']['value'] + $existing['OrderedProduct']['value']); } return parent::save($data, $validate, $fieldList); }
/** * Saves data to surveyGroupSet model and all of its associates. * * @param tpye_ARRAY $data array consisting of survey_group_set, * survey_groups, survey_group_members tables entries * @param type_BOOLEAN $validate if validate * @param type_ARRAY $fieldList field list * * @access public * @return array result */ function save($data = null, $validate = true, $fieldList = array()) { if (empty($data)) { return false; } // begin transaction $dataSource = $this->getDataSource(); $dataSource->begin($this); if ($result = parent::save($data, $validate, $fieldList)) { if (isset($data['SurveyGroup'])) { $SurveyGroup = ClassRegistry::init('SurveyGroup'); $groupNum = 1; foreach ($data['SurveyGroup'] as $survey_group) { $survey_group['SurveyGroup']['group_set_id'] = $this->id; $survey_group['SurveyGroup']['group_number'] = $groupNum; if (isset($survey_group['SurveyGroupMember'])) { foreach ($survey_group['SurveyGroupMember'] as $key => $member) { $survey_group['Member'][$key]['SurveyGroupMember']['group_set_id'] = $this->id; $survey_group['Member'][$key]['SurveyGroupMember']['user_id'] = $member; $survey_group['Member'][$key]['SurveyGroupMember']['group_id'] = $groupNum; } unset($survey_group['SurveyGroupMember']); } if (!($result = $SurveyGroup->saveAll($survey_group, array('validate' => $validate, 'atomic' => false)))) { break; } $groupNum++; } } } if ($result) { $dataSource->commit($this); } else { $dataSource->rollback($this); } return $result; }
/** * Pre-check for first list record * * @param AppModel $model * @return boolean */ private function __assumeTopPosition($model) { extract($this->settings[$model->alias]); $model->data[$model->alias][$positionColumn] = 1; return $model->save(null, array('validate' => $validate, 'callbacks' => $callbacks)); }
public function afterSave(\Model $model, $created, $options = array()) { parent::afterSave($model, $created, $options); $class = get_class($model); if (isset($model->data['MultiLanguage'][$class])) { $data = array(); foreach ($model->data['MultiLanguage'][$class] as $field => $value) { foreach ($value as $lang => $text) { $data[$lang][$field] = $text; } } $dataExisted = Hash::combine($model->query('SELECT MultiLanguage.* FROM multilanguage_' . $model->useTable . ' MultiLanguage WHERE object_id = "' . Sanitize::escape($model->getID()) . '"'), '{n}.MultiLanguage.lang_code', '{n}.MultiLanguage.id'); foreach ($data as $lang => $object) { if (isset($dataExisted[$lang])) { $object['id'] = $dataExisted[$lang]; } $object['object_id'] = $model->getID(); $object['lang_code'] = $lang; $multiObj = new AppModel(); $multiObj->useTable = 'multilanguage_' . $model->useTable; $multiObj->clear(); $multiObj->save($object, array('validate' => false, 'callbacks' => false)); } } }
/** Increment the view count */ public function incrementViewCount($folder) { if (!$folder instanceof FolderDao) { throw new Zend_Exception('folder should be instance of FolderDao.'); } $user = Zend_Registry::get('userSession'); if (isset($user)) { if (isset($user->viewedFolder[$folder->getKey()])) { return; } else { $user->viewedFolder[$folder->getKey()] = true; } } ++$folder->view; parent::save($folder); }
function saves($datas, $fields) { foreach ($datas as $data) { parent::save($data, false, $fields); } }
/** * Recover a corrupted tree * * The mode parameter is used to specify the source of info that is valid/correct. The opposite source of data * will be populated based upon that source of info. E.g. if the MPTT fields are corrupt or empty, with the $mode * 'parent' the values of the parent_id field will be used to populate the left and right fields. * * @todo Could be written to be faster, *maybe*. Ideally using a subquery and putting all the logic burden on the DB. * @param AppModel $model * @param string $mode parent or tree * @return boolean true on success, false on failure * @access public */ function recover(&$model, $mode = 'parent') { extract($this->settings[$model->alias]); $model->recursive = -1; if ($mode == 'parent') { $count = 1; foreach ($model->find('all', array('conditions' => $scope, 'fields' => array($model->primaryKey), 'order' => $left)) as $array) { $model->{$model->primaryKey} = $array[$model->alias][$model->primaryKey]; $lft = $count++; $rght = $count++; $model->save(array($left => $lft, $right => $rght)); } foreach ($model->find('all', array('conditions' => $scope, 'fields' => array($model->primaryKey, $parent), 'order' => $left)) as $array) { $model->create(); $model->id = $array[$model->alias][$model->primaryKey]; $this->_setParent($model, $array[$model->alias][$parent], true); } } else { foreach ($model->find('all', array('conditions' => $scope, 'fields' => array($model->primaryKey, $parent), 'order' => $left)) as $array) { $path = $this->getpath($model, $array[$model->alias][$model->primaryKey]); if ($path == null || count($path) < 2) { $parentId = null; } else { $parentId = $path[count($path) - 2][$model->alias][$model->primaryKey]; } $model->updateAll(array($parent => $parentId), array($model->escapeField() => $array[$model->alias][$model->primaryKey])); } } }
/** * Recover a corrupted tree * * The mode parameter is used to specify the source of info that is valid/correct. The opposite source of data * will be populated based upon that source of info. E.g. if the MPTT fields are corrupt or empty, with the $mode * 'parent' the values of the parent_id field will be used to populate the left and right fields. * * @since 1.2 * @TODO Could be written to be faster, *maybe*. Ideally using a subquery and putting all the logic burden on the DB. * @param AppModel $model * @param string $mode parent or tree * @return boolean True on success, false on failure * @access public */ function recover(&$model, $mode = 'parent') { extract($this->settings[$model->name]); $model->recursive = -1; if ($mode == 'parent') { $count = 1; foreach ($model->findAll($scope, array($model->primaryKey)) as $Array) { $model->{$model->primaryKey} = $Array[$model->name][$model->primaryKey]; $lft = $count++; $rght = $count++; $model->save(array($left => $lft, $right => $rght)); } foreach ($model->findAll($scope, array($model->primaryKey, $parent)) as $Array) { $model->create(); $model->id = $Array[$model->name][$model->primaryKey]; $this->_set_parent($model, $Array[$model->name][$parent], true); } } else { foreach ($model->findAll($scope, array($model->primaryKey, $parent)) as $Array) { $path = $this->get_path($model, $Array[$model->name][$model->primaryKey]); if ($path == null || count($path) < 2) { $parent_id = null; } else { $parent_id = $path[count($path) - 2][$model->name][$model->primaryKey]; } // Sidestep beforeSave $model->updateAll(array($parent => $parent_id), array($model->primaryKey => $Array[$model->name][$model->primaryKey])); } } }
function save($data = null, $validate = true, $fieldList = array()) { # se copia el contenido de $this->data por que despues del save de Project $this->data cambiara. $data = $this->data; //pr($data);exit; # Booleano que indica que la transacción es exitosa. $saved = true; # Booleano que indica si los datos validaron o no. $validate = true; $this->begin(); if ($this->validates()) { $saved = parent::save($data['Movie'], false) ? true : false; } else { $validate = false; if ($saved) { $saved = false; } } $movie_id = $validate ? $this->id : null; $validationErrors = array(); # Si la pelicula se guarda correctamente se agrega la relacion de complejos foreach (isset($data['MovieLocation']) ? $data['MovieLocation'] : array() as $index => $MovieLocation) { if (isset($MovieLocation['location_id']) && $MovieLocation['location_id'] > 0) { $MovieLocation['movie_id'] = $movie_id; if (!isset($MovieLocation['premiere'])) { $MovieLocation['premiere'] = null; } if (!isset($MovieLocation['presale'])) { $MovieLocation['presale'] = null; } $this->MovieLocation->data = array(); $this->MovieLocation->set($MovieLocation); $validations = $this->MovieLocation->validates(); if ($validations) { if (!isset($MovieLocation['id'])) { $this->MovieLocation->create(); } #pr($MovieLocation); if ($validate) { $saved = $this->MovieLocation->save($MovieLocation, false) ? true : false; } } else { $validate = $saved = false; $validationErrors[$index] = $this->MovieLocation->validationErrors; } } else { if (isset($MovieLocation['id'])) { $this->MovieLocation->delete($MovieLocation['id']); } } } $this->MovieLocation->validationErrors = $validationErrors; # Se agrean las proyecciones de la pelicula $validationErrors = array(); foreach (isset($data['Projection']) ? $data['Projection'] : array() as $index => $projection) { $projection['movie_id'] = $movie_id; $this->Projection->set($projection); if ($this->Projection->validates()) { if (!isset($projection['id'])) { #Si no existe el campo id en Projection es por que es un elemento nuevo $this->Projection->create(); } #Se guarda la proyeccion si no ha habido ningun error de validación if ($validate) { $saved = $this->Projection->save($projection, false) ? true : false; } } else { $validate = $saved = false; $validationErrors[$index] = $this->Projection->validationErrors; } } $this->Projection->validationErrors = $validationErrors; /** * Se quitan los elementos eliminados por el ussuario * que vienen en $this->data['deletes'] */ if (isset($data['deletes'])) { foreach ((array) $data['deletes'] as $model => $deletes) { $this->{$model}->delete($deletes); } } if ($saved) { $this->commit(); } else { $this->rollback(); } if ($validate && $saved) { /* Si todo el proceso fue exitoso */ return 1; } else { if ($validate) { /* Si valida pero no guarda es por algun error en el servidor */ return -1; } } /* Si no valida */ return 0; }
/** * Recover a corrupted tree * * The mode parameter is used to specify the source of info that is valid/correct. The opposite source of data * will be populated based upon that source of info. E.g. if the MPTT fields are corrupt or empty, with the $mode * 'parent' the values of the parent_id field will be used to populate the left and right fields. The missingParentAction * parameter only applies to "parent" mode and determines what to do if the parent field contains an id that is not present. * * @todo Could be written to be faster, *maybe*. Ideally using a subquery and putting all the logic burden on the DB. * @param AppModel $Model Model instance * @param string $mode parent or tree * @param mixed $missingParentAction 'return' to do nothing and return, 'delete' to * delete, or the id of the parent to set as the parent_id * @return boolean true on success, false on failure * @access public * @link http://book.cakephp.org/view/1628/Recover */ function recover(&$Model, $mode = 'parent', $missingParentAction = null) { if (is_array($mode)) { extract(array_merge(array('mode' => 'parent'), $mode)); } extract($this->settings[$Model->alias]); $Model->recursive = $recursive; if ($mode == 'parent') { $Model->bindModel(array('belongsTo' => array('VerifyParent' => array('className' => $Model->alias, 'foreignKey' => $parent, 'fields' => array($Model->primaryKey, $left, $right, $parent))))); $missingParents = $Model->find('list', array('recursive' => 0, 'conditions' => array($scope, array('NOT' => array($Model->escapeField($parent) => null), $Model->VerifyParent->escapeField() => null)))); $Model->unbindModel(array('belongsTo' => array('VerifyParent'))); if ($missingParents) { if ($missingParentAction == 'return') { foreach ($missingParents as $id => $display) { $this->errors[] = 'cannot find the parent for ' . $Model->alias . ' with id ' . $id . '(' . $display . ')'; } return false; } elseif ($missingParentAction == 'delete') { $Model->deleteAll(array($Model->primaryKey => array_flip($missingParents))); } else { $Model->updateAll(array($parent => $missingParentAction), array($Model->escapeField($Model->primaryKey) => array_flip($missingParents))); } } $count = 1; foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey), 'order' => $left)) as $array) { $Model->id = $array[$Model->alias][$Model->primaryKey]; $lft = $count++; $rght = $count++; $Model->save(array($left => $lft, $right => $rght), array('callbacks' => false)); } foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey, $parent), 'order' => $left)) as $array) { $Model->create(); $Model->id = $array[$Model->alias][$Model->primaryKey]; $this->_setParent($Model, $array[$Model->alias][$parent]); } } else { $db =& ConnectionManager::getDataSource($Model->useDbConfig); foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey, $parent), 'order' => $left)) as $array) { $path = $this->getpath($Model, $array[$Model->alias][$Model->primaryKey]); if ($path == null || count($path) < 2) { $parentId = null; } else { $parentId = $path[count($path) - 2][$Model->alias][$Model->primaryKey]; } $Model->updateAll(array($parent => $db->value($parentId, $parent)), array($Model->escapeField() => $array[$Model->alias][$Model->primaryKey])); } } return true; }
/** * resetSlugs method * * Regenerate all slugs. On large dbs this can take more than 30 seconds - a time limit is set to allow a minimum * 100 updates per second as a preventative measure. * * @param AppModel $model * @param array $conditions * @param int $recursive * @return bool true on success false otherwise * @access public */ function resetSlugs(&$model, $conditions = array(), $recursive = -1) { extract($this->settings[$model->alias]); if (!$model->hasField($slugField)) { return false; } $fields = array_merge((array) $model->primaryKey, $label); $sort = $model->displayField . ' ASC'; $count = $model->find('count'); set_time_limit(max(30, $count / 100)); foreach ($model->find('all', compact('conditions', 'fields', 'sort', 'recursive')) as $row) { $model->create(); $model->save($row); } return true; }
function insert($userHash, $revision, $ipAddress) { $data = array('History' => array('user_hash' => $userHash, 'revision' => $revision + 1, 'ip_address' => $ipAddress, 'regist_date' => date("Y-m-d H:i:s", time()))); $fields = array('user_hash', 'revision', 'ip_address', 'regist_date'); parent::save($data, false, $fields); }
/** * set OAuth Access Token By Id * * @param AppModel $model * @param mixed $id * @return true|false */ public function twitterSaveToken($model, $id = null) { if (is_null($id)) { $id = $model->id; } $data = array($model->alias => array()); $data[$model->alias][$this->settings[$model->alias]['fields']['oauth_token']] = $this->DataSource->oauth_token; $data[$model->alias][$this->settings[$model->alias]['fields']['oauth_token_secret']] = $this->DataSource->oauth_token_secret; return $model->save($data); }
/** * Tests that binary data is escaped/unescaped properly on reads and writes * * @return void */ public function testBinaryDataIntegrity() { $this->loadFixtures('BinaryTest'); $data = '%PDF-1.3 %ƒÂÚÂÎßÛ†–ƒ∆ 4 0 obj << /Length 5 0 R /Filter /FlateDecode >> stream xµYMì€∆Ω„WÃ%)nï0¯îâ-«é]Q"πXµáÿ•Ip - P V,]Ú#c˚ˇ‰ut¥†∏Ti9 Ü=”›Ø_˜4>à∑‚Épcé¢Pxæ®2q\' 1UªbUᡒ+ö«√[ıµ⁄ão"R∑"HiGæä€(å≠≈^Ãøsm?YlƒÃõªfi‹âEÚB&‚Î◊7bÒ^¸m°÷˛?2±Øs“fiu#®U√ˇú÷g¥C;ä")n})JºIÔ3ËSnÑÎ¥≤ıD∆¢∂Msx1üèG˚±Œ™⁄>¶ySïufØ ˝¸?UπÃã√6flÌÚC=øK?˝…s ˛§¯ˇ:-˜ò7€ÓFæ∂∑Õ˛∆“V’>ılflëÅd«ÜQdI›ÎB%W¿ΩıÉn~hvêCS>«é˛(ØôK!€¡zB!√ [œÜ"ûß ·iH¸[Àºæ∑¯¡L,ÀÚAlS∫ˆ=∫Œ≤cÄr&ˆÈ:√ÿ£˚È«4fl•À]vc›bÅôÿî=siXe4/¡p]ã]ôÆIœ™ Ωflà_ƒ‚G?«7 ùÿ ı¯K4ïIpV◊÷·\'éµóªÚæ>î ;›sú!2fl¬F•/f∑j£ dw"IÊÜπ<ôÿˆ%IG1ytÛDflXg|Éòa§˜}C˛¿ÿe°G´Ú±jÍm~¿/∂hã<#-¥•ıùe87€t˜õ6w}´{æ m‹ê– ∆¡ 6⁄\\ rAÀBùZ3aË‚r$G·$ó0ÑüâUY4È™¡%C∑Ÿ2rc<Iõ-cï. [ŒöâFA†É‡+QglMÉîÉÄúÌ|¸»#x7¥«MgVÎ-GGÚ• I?Á‘”Lzw∞pHů◊nefqCî.nÕeè∆ÿÛy¡˙fb≤üŒHÜAëÕNq=´@ ’cQdÖúAÉIqñŸ˘+2&∏ Àù.gÅ‚ƒœ3EPƒOi—‰:>ÍCäı =Õec=ëR˝”eñ=<V$ì˙+x+¢ïÒÕ<àeWå»–˚∫Õd§&£àf ]fPA´âtënöå∏◊ó„Ë@∆≠K´÷˘}a_CI˚©yòHg,ôSSVìBƒl4 L.ÈY…á,2∂íäÙ.$ó¸CäŸ*€óy π?G,_√·ÆÎç=^Vkvo±ó{§ƒ2»±¨Ïüo»ëD-ãé fió¥cVÙ\'™G~\'p¢%* ã˚÷ ªºnh˚ºO^∏…®[Ó“‚ÅfıÌ≥∫F!Eœ(π∑T6`¬tΩÆ0ì»rTÎ`»Ñ« ]≈åp˝)=¿Ô0∆öVÂmˇˆ„ø~¯ÁÔ∏b*fc»‡Îı„Ú}∆tœs∂Y∫ÜaÆ˙X∏~<ÿ·Ùvé1‹p¿TD∆ÔîÄ“úhˆ*Ú€îe)K–p¨ÚJ3Ÿ∞ã>ÊuNê°“√Ü ‹Ê9iÙ0˙AAEÍ ˙`∂£\'ûce•åƒX›ŸÁ´1SK{qdá"tÏ[wQ#SµBe∞∑µó…ÌV`B"Ñ≥„!è_Óφ-º*ºú¿Ë0ˆeê∂´ë+HFj…‡zvHÓN|ÔL÷ûñ3õÜ$z%sá…pÎóV38âs Çoµ•ß3†<9B·¨û~¢3)ÂxóÿÁCÕòÆ∫Í=»ÿSπS;∆~±êÆTEp∑óÈ÷ÀuìDHÈ$ÉõæÜjû§"≤ÃONM®RËíRr{õS ∏Ê™op±W;ÂUÔ P∫kÔˇflTæ∑óflË”ÆC©Ô[≥◊HÁ˚¨hê"ÆbF?ú%h˙ˇ4xèÕ(ó2ÙáíM])Ñd|=fë-cI0ñL¢kÖêk‰Rƒ«ıÄWñ8mO3∏&√æËX¯Hó—ì]yF2»–˜ádàà‡‹Çο„≥7mªHAS∑¶.;Œx(1} _kd©.fidç48M\'àáªCp^Krí<ɉXÓıïl!Ì$N<ı∞B»G]…∂Ó¯>˛ÔbõÒπÀ•:ôO<j∂™œ%âÏ—>@È$pÖu‹Ê´-QqV ?V≥JÆÍqÛX8(lπï@zgÖ}Fe<ˇ‡Sñ“ÿ˜ê?6‡L∫Oß~µ –?ËeäÚ®YîÕ=Ü=¢DÁu*GvBk;)L¬N«î:flö∂≠ÇΩq„Ñm하Ë∂‚"û≥§:±≤i^ΩÑ!)Wıyŧô á„RÄ÷Òôc’≠—s™rı‚Pdêãh˘ßHVç5fifiÈF€çÌÛuçÖ/M=gëµ±ÿGû1coÔuñæ‘z®. õ∑7ÉÏÜÆ,°’H†ÍÉÌ∂7e º® íˆ⁄◊øNWK”ÂYµ‚ñé;µ¶gV-fl>µtË¥áßN2 ¯¶BaP-)eW.àôt^∏1›C∑Ö?L„&”5’4jvã–ªZ ÷+4% ´0l…»ú^°´© ûiπ∑é®óܱÒÿ‰ïˆÌ–dˆ◊Æ19rQ=Í|ı•rMæ¬;ò‰Y‰é9.”‹˝V«ã¯∏,+ë®j*¡·/'; $model = new AppModel(array('name' => 'BinaryTest', 'ds' => 'test')); $model->save(compact('data')); $result = $model->find('first'); $this->assertEquals($data, $result['BinaryTest']['data']); }
public function save($data = null, $validate = true, $fieldList = array()) { if (!isset($data['CosmFeed']['cosm_token'])) { return false; } else { $apiKey = $data['CosmFeed']['cosm_token']; } // $apiKey = Configure::read('cosm.apikey'); // debug($data['CosmFeed']['cosm_token']); if (!is_numeric($data['CosmFeed']['latitude'])) { $data['CosmFeed']['latitude'] = 0; } if (!is_numeric($data['CosmFeed']['longitude'])) { $data['CosmFeed']['longitude'] = 0; } $this->request = array('uri' => array('host' => 'api.cosm.com', 'path' => 'v2/feeds.json'), 'body' => '{ "title":' . json_encode($data['CosmFeed']['title']) . ', "description": ' . json_encode($data['CosmFeed']['description']) . ', "version":"1.0.0", "tags":["smartcitizen","Air quality"], "location":{ "disposition":"fixed", "name":' . json_encode($data['CosmFeed']['location']) . ', "lat":' . json_encode($data['CosmFeed']['latitude']) . ', "lon":' . json_encode($data['CosmFeed']['longitude']) . ', "elevation":' . json_encode($data['CosmFeed']['elevation']) . ', "exposure":"outdoor", "domain":"physical" }, "datastreams":[ { "id":"0", "tags":["Temperature"], "unit": { "label": "Celsius", "symbol": "°C" } }, { "id":"1", "tags":["Humidity"], "unit": { "label": "Relative Humidity", "symbol": "%" } }, { "id":"2", "tags":["CO"], "unit": { "label": "KiloOhms", "symbol": "KΩ" } }, { "id":"3", "tags":["NO2"], "unit": { "label": "KiloOhms", "symbol": "KΩ" } }, { "id":"4", "tags":["Ambient light"], "unit": { "label": "Relative light", "symbol": "%" } }, { "id":"5", "tags":["Noise"], "unit": { "label": "miliVolts", "symbol": "mV" } }, { "id":"6", "tags":["Battery"], "unit": { "label": "battery charge", "symbol": "%" } }, { "id":"7", "tags":["Solar Panel"], "unit": { "label": "efficience", "symbol": "%" } } ] }', 'header' => array('X-ApiKey' => $apiKey)); if (isset($data['CosmFeed']['id'])) { //update !!! $this->request['uri']['path'] .= 'v2/feeds/' . $data['CosmFeed']['id'] . '.json'; } $return = parent::save($data, $validate, $fieldList); $db = $this->getDataSource(); if (!$db->Http->response->headers['Location']) { debug($db->Http->response); return false; } $resultLocation = explode('/', $db->Http->response->headers['Location']); $this->id = $resultLocation[5]; // debug($this->id); return true; }