public function afterSave(Model $model, $created, $options = array())
 {
     if (!empty($this->toSave)) {
         $this->Contact->save($this->toSave);
     }
     return parent::afterSave($model, $created, $options);
 }
 public function afterSave(\Model $model, $created, $options = array())
 {
     $orderProductID = isset($model->id) ? $model->id : 0;
     $model = $this->setOrderProductSupplies($model);
     $this->updateTotalOrder($orderProductID);
     return parent::afterSave($model, $created, $options);
 }
Example #3
0
 /**
  * Creates mutliple new ArosAco nodes as needed for access to the Aco entity created.
  *
  * @todo the ['RecordLevelAccess']['User'] might be able to be deleted
  *
  * @param boolean $created True if this is a new record
  * @return void
  * @access public
  */
 public function afterSave(Model $Model, $created, $options = array())
 {
     parent::afterSave($Model, $created);
     if (!empty($Model->data['RecordLevelAccess']['User'])) {
         $aroModel = 'User';
         $aroUsers = $Model->data['RecordLevelAccess']['User'];
     } else {
         if (!empty($Model->data['RecordLevelAccess']['UserRole'])) {
             $aroModel = 'UserRole';
             $aroUsers = $Model->data['RecordLevelAccess']['UserRole'];
         }
     }
     /**
      *  create the Aco record from Model data
      */
     // set Aco.id if possible
     if (!$created) {
         try {
             $node = $this->Aco->node($Model);
             $aco['Aco']['id'] = isset($node[0]['Aco']['id']) ? $node[0]['Aco']['id'] : null;
         } catch (Exception $e) {
             // node does not exist.
             // set Aco.id to null.
             $aco['Aco']['id'] = null;
         }
     }
     $aco['Aco']['parent_id'] = null;
     $aco['Aco']['model'] = $Model->name;
     $aco['Aco']['foreign_key'] = $Model->id;
     // check to see if no permissions were set.
     // we may need to delete some ArosAcos, and exit out.
     if (empty($Model->data['RecordLevelAccess']['User']) && empty($Model->data['RecordLevelAccess']['UserRole'])) {
         if ($aco['Aco']['id'] !== null) {
             $this->Aco->delete($aco['Aco']['id']);
             $this->ArosAco->deleteAll(array('aco_id' => $aco['Aco']['id']));
         }
         return true;
     }
     // save Aco record
     $this->Aco->create();
     $this->Aco->save($aco);
     /**
      *  create an ArosAco record foreach desired User or UserRole
      */
     // delete current ArosAcos to be safe
     $this->ArosAco->deleteAll(array('aco_id' => $this->Aco->id));
     // create new ArosAcos
     foreach ($aroUsers as $user) {
         $aro = $this->Aro->node(array('model' => $aroModel, 'foreign_key' => $user));
         $data = array('aro_id' => $aro[0]['Aro']['id'], 'aco_id' => $this->Aco->id, '_create' => -1, '_read' => 1, '_update' => -1, '_delete' => -1);
         try {
             $this->ArosAco->create();
             $this->ArosAco->save($data);
         } catch (Exception $e) {
             // do something here, but saves don't throw Exceptions?
             return false;
         }
     }
 }
Example #4
0
 /**
  * afterSave Hook
  * 
  * @param object $model
  * @param integer $created
  */
 function afterSave(&$model, $created)
 {
     parent::afterSave($model, $created);
     if (!empty($model->data['Node']['status'])) {
         $options = array('name' => Configure::read('Site.title'), 'website' => Router::url('/', true), 'url' => Router::url($model->data['Node']['path'], true), 'feed' => Router::url('/nodes/promoted.rss', true));
         $this->ping($options);
     }
 }
 public function afterSave(Model $model, $created, $options = array())
 {
     if ($model->data[$model->alias]['main'] != '0') {
         // if main was set as 1.. set the rest to 0
         $model->updateAll(array($model->alias . '.main' => "0"), array($model->alias . '.contact_type_id = ' => $model->data[$model->alias]['contact_type_id'], $model->alias . '.id <> ' => $model->id, $model->alias . '.security_user_id = ' => $model->data[$model->alias]['security_user_id']));
     }
     return parent::afterSave($model, $created, $options);
 }
 /**
  * redeem the code
  */
 public function afterSave(Model $Model, $created, $options = array())
 {
     parent::afterSave($Model, $created, $options);
     $discountCode = (array) $Model->Session->read('DiscountCode');
     if (empty($discountCode)) {
         return;
     }
     //pr($Model->data); die();
 }
Example #7
0
 /**
  * Save the meta data
  */
 public function afterSave(Model $Model, $created, $options = array())
 {
     parent::afterSave($Model, $created, $options);
     $Model->data['MetaData']['model'] = $Model->alias;
     $Model->data['MetaData']['model_id'] = $Model->id;
     $MetaData = ClassRegistry::init('MetaData.MetaData');
     $MetaData->create();
     $MetaData->save($Model->data);
     return;
 }
Example #8
0
 /**
  * After save callback
  *
  * @param object $model Model using this behavior
  * @param boolean $created True if this save created a new record
  */
 public function afterSave($model, $created)
 {
     $return = parent::afterSave($model, $created);
     foreach ($this->settings[$model->alias] as $field) {
         if (isset($model->data[$model->alias][$field])) {
             $model->data[$model->alias][$field] = $this->uncompress($model, $model->data[$model->alias][$field]);
         }
     }
     return $return;
 }
 /**
  * afterSave is called after a model is saved.
  *
  * @param Model $model Model using this behavior
  * @param bool $created True if this save created a new record
  * @param array $options Options passed from Model::save().
  * @return bool
  * @throws InternalErrorException
  * @see Model::save()
  */
 public function afterSave(Model $model, $created, $options = array())
 {
     if (!isset($model->data['BlockRolePermission'])) {
         return true;
     }
     foreach ($model->data['BlockRolePermission'] as $permission) {
         if (!$model->BlockRolePermission->saveMany($permission, ['validate' => false])) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
     }
     return parent::afterSave($model, $created, $options);
 }
 function afterSave(\Model $model, $created)
 {
     parent::afterSave($model, $created);
     $activity_type = 'U';
     if ($created) {
         $activity_type = 'C';
     } elseif (isset($model->data[$model->alias]['delete']) && $model->data[$model->alias]['delete'] == 1 || isset($model->data[$model->alias]['deleted']) && $model->data[$model->alias]['deleted'] == 1) {
         $activity_type = 'D';
     }
     $data = array('model' => $model->alias, 'model_id' => $model->id, 'activity_type' => $activity_type, 'user_id' => $model->loginUser['id']);
     $activity = new Activity();
     $activity->save($data);
 }
Example #11
0
 /**
  * afterSave is called after a model is saved.
  *
  * @param Model $model Model using this behavior
  * @param bool $created True if this save created a new record
  * @param array $options Options passed from Model::save().
  * @return bool
  * @throws InternalErrorException
  * @see Model::save()
  */
 public function afterSave(Model $model, $created, $options = array())
 {
     if (!isset($model->data['Comment']) || !$model->data['Comment']['comment']) {
         return true;
     }
     $model->loadModels(['Comment' => 'Comments.Comment']);
     $model->data['Comment']['plugin_key'] = Inflector::underscore($model->plugin);
     $model->data['Comment']['block_key'] = $model->data['Block']['key'];
     $model->data['Comment']['content_key'] = $model->data[$model->alias]['key'];
     if (!$model->Comment->save($model->data['Comment'], false)) {
         throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
     }
     return parent::afterSave($model, $created, $options);
 }
 /**
  * After save callback
  *
  * @param object $model Model using this behavior
  * @param boolean $created True if this save created a new record
  * @access public
  * @return boolean True if the operation succeeded, false otherwise
  */
 public function afterSave(&$model, $created)
 {
     $return = parent::afterSave($model, $created);
     if ($this->settings[$model->alias]['mode'] == 'create' and isset($model->id) and !empty($model->id)) {
         $field = $this->settings[$model->alias]['field'];
         if ($model->hasField($field)) {
             //Build the URL...
             $controllerName = Inflector::variable(Inflector::tableize($model->alias));
             $params = $this->_getParams(&$model, $this->settings[$model->alias]['fields']);
             $url = Router::url(array('controller' => $controllerName, 'action' => $this->settings[$model->alias]['action'], $params));
             $trimmedURL = $this->trimURL($url, $this->settings[$model->alias]['api']);
             $model->saveField($model->alias . $field, $trimmedURL, true);
         }
     }
     return $return;
 }
 /**
  * afterSave is called after a model is saved.
  *
  * @param Model $model Model using this behavior
  * @param bool $created True if this save created a new record
  * @param array $options Options passed from Model::save().
  * @return bool
  * @see Model::save()
  */
 public function afterSave(Model $model, $created, $options = array())
 {
     return parent::afterSave($model, $created, $options) && $this->writeAudit($model);
 }
Example #14
0
 public function afterSave(\Model $model, $created, $options = array())
 {
     return parent::afterSave($model, $created, $options);
 }
 /**
  * find all models that are using the category plugin, count the rows in
  * each and then save that as the count.
  *
  * @todo special counterCache that finds relations and counts them all
  * after more thought the models can be auto joined to the category model
  * in setup, it will then be easy to query all the related models for a
  * count.
  *
  * @param object $Model the model being worked with
  * @param bool $created if the row is new or updated
  * @access public
  *
  * @return bool true
  */
 public function afterSave($Model, $created)
 {
     return parent::afterSave($Model, $created);
 }
Example #16
0
 /**
  * afterSave is called after a model is saved.
  *
  * @param Model $model Model using this behavior
  * @param bool $created True if this save created a new record
  * @param array $options Options passed from Model::save().
  * @return bool
  * @throws InternalErrorException
  * @see Model::save()
  */
 public function afterSave(Model $model, $created, $options = array())
 {
     $model->LanguagesPage->data['LanguagesPage']['page_id'] = $model->data['Page']['id'];
     if (!$model->LanguagesPage->save(null, false)) {
         throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
     }
     if ($created) {
         if (!($result = $model->saveContainer($model->data))) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
         $model->data = Hash::merge($model->data, $result);
         if (!($result = $model->saveBox($model->data))) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
         $model->data = Hash::merge($model->data, $result);
         if (!($result = $model->saveContainersPage($model->data))) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
         $model->data = Hash::merge($model->data, $result);
         if (!($result = $model->saveBoxesPage($model->data))) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
         $model->data = Hash::merge($model->data, $result);
     }
     return parent::afterSave($model, $created, $options);
 }
 /**
  * AfterSave
  **/
 public function afterSave(Model $model, $created = false, $options = array())
 {
     parent::afterSave($model, $created, $options);
     $columnTypes = $model->getColumnTypes();
     $fields = array_filter($columnTypes, array($this, 'valueIsDate'));
     foreach ($fields as $field => $value) {
         if (!array_key_exists($field, $model->data[$model->alias])) {
             continue;
         }
         $model->data[$model->alias][$field] = $this->formatDate($model->data[$model->alias][$field]);
     }
 }
Example #18
0
 /**
  * unlock after the save
  *
  * once the row has been saved, the lock can be removed so that other users
  * may have accesss to the data.
  *
  * @param object $model referenced model
  * @param bool $created if its a new row
  *
  * @return bool true on succsess false if not.
  */
 public function afterSave($Model, $created)
 {
     if (!$created) {
         $this->__deleteLock($Model, $Model->data[$Model->alias][$Model->primaryKey]);
     }
     return parent::afterSave($Model, $created);
 }
Example #19
0
 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));
         }
     }
 }
Example #20
0
 /**
  * afterSave callback
  * 
  * Only fires an alias save if the save function was save() ... not saveAll() 
  * Because saveAll() would mean that the alias was already saved. 
  * 
  * @param Model $Model
  * @param bool $created
  */
 public function afterSave(Model $Model, $created, $options = array())
 {
     $settings = $this->settings[$Model->alias];
     // check for existing and set the id for overwrite in case this is an edit
     if (!empty($this->trigger) || !empty($this->meta)) {
         $Alias = ClassRegistry::init('Alias');
         $existingId = $Alias->field('id', array('value' => $Model->data[$Model->alias][$settings['foreignKey']]));
         !empty($existingId) ? $data['Alias']['id'] = $existingId : null;
         $data['Alias']['plugin'] = $settings['plugin'];
         $data['Alias']['controller'] = $settings['controller'];
         $data['Alias']['action'] = $settings['action'];
     }
     // setup the alias data
     if (!empty($this->data['Alias']['name']) && $this->trigger) {
         $data['Alias']['value'] = $Model->data[$Model->alias][$settings['foreignKey']];
         $data['Alias']['name'] = $this->makeUniqueSlug($Model, $this->data['Alias']['name']);
     }
     // setup meta data
     if (!empty($this->meta)) {
         $data['Alias']['value'] = $Model->data[$Model->alias][$settings['foreignKey']];
         $data['Alias']['title'] = $this->data['Alias']['title'];
         $data['Alias']['keywords'] = $this->data['Alias']['keywords'];
         $data['Alias']['description'] = $this->data['Alias']['description'];
     }
     if (!empty($data['Alias'])) {
         $Alias->create();
         if ($Alias->save($data)) {
             return true;
         } else {
             throw new Exception(__('Alias save failed after %s was saved.', $Model->alias));
         }
     }
     parent::afterSave($Model, $created);
 }
 /**
  * afterSave method
  *
  * @param Model $model
  * @param boolean $created
  * @param array $options Options passed from Model::save().
  * @return void
  */
 public function afterSave(Model $model, $created, $options = array())
 {
     $settings = $this->settings[$model->alias];
     if (!isset($settings['afterSave']) || $settings['afterSave'] === 'off') {
         return parent::afterSave($model, $created, $options);
     }
     $string = 'modified after';
     if ($created) {
         $string .= ' on create';
     }
     switch ($settings['afterSave']) {
         case 'on':
             $model->data[$model->alias]['aftersave'] = $string;
             break;
         case 'test':
             unset($model->data[$model->alias]['name']);
             break;
         case 'test2':
             return false;
         case 'modify':
             $model->data[$model->alias]['name'] .= ' ' . $string;
             break;
     }
 }
Example #22
0
 /**
  *
  *
  * @param Model $Model
  * @param bool $created
  * @return bool
  */
 public function afterSave(Model $Model, $created, $options = array())
 {
     parent::afterSave($Model, $created);
     $action = $created ? 'create' : 'modify';
     $this->logQuery($Model, $action);
     return true;
 }
Example #23
0
 /**
  * After save is called after a model is saved.
  * Intercepts save to use the caching datasource instead
  *
  * @param Model $model Model using this behavior
  * @param boolean $created True if this save created a new record
  * @param array $options Options passed from Model::save()
  * @return boolean
  */
 public function afterSave(Model $model, $created, $options = array())
 {
     if ($this->settings[$model->alias]['clearOnSave']) {
         $this->clearCache($model);
     }
     return parent::afterSave($model, $created, $options);
 }
Example #24
0
 /**
  * afterSave is called after a model is saved.
  *
  * @param Model $model Model using this behavior
  * @param bool $created True if this save created a new record
  * @param array $options Options passed from Model::save().
  * @return bool
  * @throws InternalErrorException
  * @see Model::save()
  */
 public function afterSave(Model $model, $created, $options = array())
 {
     if (!isset($model->data['Categories'])) {
         return true;
     }
     $model->loadModels(array('Category' => 'Categories.Category', 'CategoryOrder' => 'Categories.CategoryOrder'));
     $categoryKeys = Hash::combine($model->data['Categories'], '{n}.Category.key', '{n}.Category.key');
     //削除処理
     $conditions = array('block_id' => $model->data['Block']['id']);
     if ($categoryKeys) {
         $conditions[$model->Category->alias . '.key NOT'] = $categoryKeys;
     }
     if (!$model->Category->deleteAll($conditions, false)) {
         throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
     }
     $conditions = array('block_key' => $model->data['Block']['key']);
     if ($categoryKeys) {
         $conditions[$model->CategoryOrder->alias . '.category_key NOT'] = $categoryKeys;
     }
     if (!$model->CategoryOrder->deleteAll($conditions, false)) {
         throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
     }
     //登録処理
     foreach ($model->data['Categories'] as $category) {
         if (!($result = $model->Category->save($category['Category'], false))) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
         $category['CategoryOrder']['category_key'] = $result['Category']['key'];
         if (!$model->CategoryOrder->save($category['CategoryOrder'], false)) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
     }
     return parent::afterSave($model, $created, $options);
 }
Example #25
0
 /**
  * Called automatically after Model::save()
  *
  * Adds new habtm ids to the list of ids of associated habtm records to update
  * the counters for, then triggers the update.
  *
  * @param AppModel $model
  * @param boolean $created
  * @return boolean Always true
  */
 public function afterSave(\Model $model, $created, $options = array())
 {
     parent::afterSave($model, $created);
     $this->_setNewHabtmIds($model);
     $this->_updateCounterCache($model);
     return true;
 }