function saveAll($data = null, $options = array()) { $controller = Sl::getInstance()->controller; $isNew = !$controller->id; // set associated model info if ($controller->modelClass != 'CmsNode') { $data['CmsNode'] += array('model' => $controller->modelClass, 'plugin' => $controller->plugin); } // remove empty Images, Attachments from data to be saved if (!empty($data['CmsImage'])) { if (empty($data['CmsImage']['id']) && empty($data['CmsImage']['filename']['name'])) { unset($data['CmsImage']); } } if (!empty($data['CmsAttachment'])) { foreach ($data['CmsAttachment'] as $i => $image) { if (empty($image['id']) && empty($image['filename']['name'])) { unset($data['CmsAttachment'][$i]); } } } if (!empty($data['ImageGallery'])) { foreach ($data['ImageGallery'] as $i => $image) { if (empty($image['id']) && empty($image['filename']['name'])) { unset($data['ImageGallery'][$i]); } } } if ($isNew) { $data['CmsNode']['auth_user_id'] = SlAuth::user('id'); } if (!empty($data['CmsNode']['model'])) { if (empty($options['validation']) || $options['validation'] != 'only') { if (!parent::saveAll($data, array('validate' => 'only', 'atomic' => true) + $options)) { return false; } } $modelObject = ClassRegistry::init("{$data['CmsNode']['plugin']}.{$data['CmsNode']['model']}"); if (!$modelObject->saveAll($data, $options)) { return false; } $data['CmsNode'] += array('foreign_key' => $modelObject->id); } $result = parent::saveAll($data, $options); if ($result && $isNew && $this->CmsImage->id) { $this->CmsImage->saveField('cms_node_id', $this->id); } return $result; }
function saveAll($data = null, $options = array()) { if (empty($data)) { $data = $this->data; } # Do not save an empty journal return empty($data['JournalDetail']) && empty($data['Journal']['notes']) ? false : parent::saveAll($data, $options); }
/** * saveAll method. * * Overrides parent's saveAll so that it can perform a transaction that performs * DELETEs on removed Goals. * * @param array $data * @param array $options * @return mixed */ public function saveAll($data = array(), $options = array()) { $dataSource = $this->getDataSource(); // Begin the transaction $dataSource->begin(); // Flag to indicate a commit $commit = true; // Check for an existing Achievement, its Goals, and Showcase rows if (isset($data['Achievement']['id']) && $data['Achievement']['id']) { // Get the POSTed Goal id's $in = Hash::extract($data, 'Task.{n}[ref>0].ref'); // Get the stored Goal id's $achievement = $this->find('first', array('conditions' => array('Achievement.id' => $data['Achievement']['id']), 'fields' => array('Achievement.id'), 'contain' => array('Goal' => array('fields' => array('Goal.id'))))); $stored = Hash::extract($achievement, 'Goal.{n}[id>0].id'); // Calculate the diff between the two Sets of Goal ids $diff = array_diff($stored, $in); // DELETE the missing Goals if (!$this->Goal->deleteAll(array('Goal.id' => $diff), true)) { $commit = false; } // DELETE any Showcase rows if the Achievement is going to be private if ($data['Achievement']['private']) { if (!$this->Showcase->deleteAll(array('Showcase.achievement_id' => $data['Achievement']['id']), true)) { $commit = false; } } } // Normal saveAll if (!($result = parent::saveAll($data, $options))) { $commit = false; } // End the transaction if ($commit) { $dataSource->commit(); } else { $dataSource->rollback(); } return $result; }