Invoked before a model is saved. Return false to abort the operation.

@return bool
554647
public function preSave()
    {
        $this->originalData = $this->original;
        $this->updatedData = $this->attributes;
        
        // Disregard all object based items, like DateTime
        foreach ($this->updatedData as $key => $val) {
            if (gettype($val) == 'object' && !method_exists($val, '__toString')) {
                unset($this->originalData[$key]);
                unset($this->updatedData[$key]);
            }
        }
        
        $this->dirtyData = $this->getDirty();
        $this->updating = $this->exists;
    }
1022714
public function delete()
    {
        if (is_null($this->getKeyName())) {
            throw new Exception('No primary key defined on model.');
        }

        // If the model doesn't exist, there is nothing to delete so we'll just return
        // immediately and not do anything else. Otherwise, we will continue with a
        // deletion process on the model, firing the proper events, and so forth.
        if (!$this->exists) {
            return;
        }

        if ($this->fireModelEvent('deleting') === false) {
            return false;
        }

        // Here, we'll touch the owning models, verifying these timestamps get updated
        // for the models. This will allow any caching to get broken on the parents
        // by the timestamp. Then we will go ahead and delete the model instance.
        $this->touchOwners();

        $this->performDeleteOnModel();

        $this->exists = false;

        // Once the model has been deleted, we will fire off the deleted event so that
        // the developers may hook into post-delete operations. We will then return
        // a boolean true as the delete is presumably successful on the database.
        $this->fireModelEvent('deleted', false);

        return true;
    }
83427
final public function save()
    {
        $pre = $this->preSave();
        if ($pre === false) {
            $this->logger->error(sprintf(
                'Can not save object "%s:%s"; cancelled by %s::preSave()',
                $this->objType(),
                $this->id(),
                get_called_class()
            ));
            return false;
        }

        $ret = $this->source()->saveItem($this);
        if ($ret === false) {
            $this->logger->error(sprintf(
                'Can not save object "%s:%s"; repository failed for %s',
                $this->objType(),
                $this->id(),
                get_called_class()
            ));
            return false;
        } else {
            $this->setId($ret);
        }

        $post = $this->postSave();
        if ($post === false) {
            $this->logger->error(sprintf(
                'Saved object "%s:%s" but %s::postSave() failed',
                $this->objType(),
                $this->id(),
                get_called_class()
            ));
            return false;
        }

        return true;
    }
1262026
protected function beforeSave() 
	{
		if(parent::beforeSave()) {
			$this->banner_file_type = serialize(Utility::formatFileType($this->banner_file_type));
		}
		return true;
	}
519970
public function beforeSave(Model $model, $options = array()) {
        $settings = $this->settings[$model->alias];

        if ($model->data[$model->alias]) {
            foreach ($model->data[$model->alias] as $key => &$value) {
                if (isset($settings[$key])) {
                    $filters = $settings[$key];

                    // Strip tags
                    if (isset($filters['strip']) && $filters['strip']['filter']) {
                        $value = strip_tags($value, (string) $filters['strip']['allowed']);
                    }

                    // HTML escape
                    if (isset($filters['html']) && $filters['html']['filter']) {
                        $value = Sanitize::html($value, array(
                            'quotes' => $filters['html']['flags'],
                            'charset' => $filters['html']['encoding'],
                            'double' => $filters['html']['double']
                        ));
                    }

                    // Paranoid
                    if (isset($filters['paranoid']) && $filters['paranoid']['filter']) {
                        $value = Sanitize::paranoid($value, (array) $filters['paranoid']['allowed']);
                    }

                    // SQL escape
                    if (isset($filters['escape']) && $filters['escape']['filter']) {
                        $value = Sanitize::escape($value, $model->useDbConfig);
                    }
                }
            }
        }

        return true;
    }
1011487
public function beforeSave()
    {
        if ('' !== $password = $this->getElement('changePassword')->getValue()) {
            $this->getRecord()->password = \Cms\Model\Auth::getSaltedPasswordHash($password);
        }
        return true;
    }
685936
protected function beforeSave() 
	{
		$controller = strtolower(Yii::app()->controller->id);
		$action = strtolower(Yii::app()->controller->action->id);

		$location = $controller;
		
		if(parent::beforeSave()) {
			if($this->isNewRecord || (!$this->isNewRecord && !$this->name)) {
				$name=new SourceMessage;
				$name->message = $this->name_i;
				$name->location = $location.'_title';
				if($name->save())
					$this->name = $name->id;

				$this->slug = $this->urlTitle($this->name_i);
				
			} else {
				$name = SourceMessage::model()->findByPk($this->name);
				$name->message = $this->name_i;
				$name->save();
			}

			$this->sitetype_access = serialize($this->sitetype_access);
			$this->userlevel_access = serialize($this->userlevel_access);
		}
		return true;
	}
792651
protected function beforeValidate() {
		if(parent::beforeValidate()) {		
			if($this->isNewRecord) {
				$this->user_id = Yii::app()->user->id;
			}
		}
		return true;
	}
587921
public function save()
    {
        if (!$this->activeRecordCriteriaPrototype) {
            throw new Exception\RuntimeException(sprintf(
                'An Active Record Criteria Prototype must be set prior to calling %s',
                __FUNCTION__
            ));
        }

        if (!$this->getModel()) {
            throw new Exception\RuntimeException(sprintf('A Model must be set prior to calling %s', __FUNCTION__));
        }

        $criteria = $this->activeRecordCriteriaPrototype;
        $criteria->setId($this->getId());
        $result = $this->getModel()->save($criteria, $this);
        return $result;
    }
1246334
public function restore()
    {
        // If the restoring event does not return false, we will proceed with this
        // restore operation. Otherwise, we bail out so the developer will stop
        // the restore totally. We will clear the deleted timestamp and save.
        if ($this->fireModelEvent('restoring') === false) {
            return false;
        }

        $this->{$this->getDeletedAtColumn()} = null;

        // Once we have saved the model, we will fire the "restored" event so this
        // developer will do anything they need to after a restore operation is
        // totally finished. Then we will return the result of the save call.
        $this->exists = true;

        $result = $this->save();

        $this->fireModelEvent('restored', false);

        return $result;
    }
1079626
public function beforeSave()
    {
        parent::beforeSave();
        if ($this->isObjectNew() && !$this->getCreatedAt()) {
            $this->setCreatedAt($this->dateTime->formatDate(true));
        }
        $this->setUpdatedAt($this->dateTime->formatDate(true));

        return $this;
    }
485273
public function save(Model $model)
    {
        $model->setAttribute($this->getForeignKeyName(), $this->getParentKey());

        return $model->save() ? $model : false;
    }
165830
protected function before() {
		if($this->connection->getDatabasePlatform() instanceof SQLServerPlatform) {
			$this->connection->executeUpdate('EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"');
		} else if($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
			$this->connection->executeUpdate('SET FOREIGN_KEY_CHECKS=0');
		} else if($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
			$this->connection->executeUpdate('PRAGMA foreign_keys = OFF');
		}
	}
434922
public function savingValidation()
    {
        global $app;

        $this->preValidationCast();
        $this->validator = new Validator($app['translator'], $this->getDirty(), $this->getAttributeRules());

        if ($this->validator->fails()) {
            return false;
        }

        return true;
    }
863161
public function beforeExecuteRoute()
    {
        //sets active task and action names
        $this->actionName = $this->dispatcher->getActionName();
        $this->taskName = $this->dispatcher->getTaskName();

        $this->setupOptions();

        //if -h or --help option was typed in command line then show only help
        $this->args = $this->dispatcher->getParam('args');
        if ($this->containHelpOption($this->args)) {
            $this->renderActionHelp();
            //stop dispatching
            return false;
        }
        try {
            $this->validate($this->args);
        } catch (InvalidArgumentException $ex) {
            $this->throwError(strtr(':command: Invalid argument `:argument` for option `:option`', [
                ':command' => sprintf('%s %s', $this->dispatcher->getParam('activeTask'), $this->dispatcher->getParam('activeAction')),
                ':option' => $ex->getOption(),
                ':argument' => $ex->getArgument()
            ]));
        } catch (InvalidOptionException $ex) {
            $this->throwError(strtr(':command: Invalid option `:option`', [
                ':command' => sprintf('%s %s', $this->dispatcher->getParam('activeTask'), $this->dispatcher->getParam('activeAction')),
                ':option' => $ex->getOption()
            ]));
        }

        return true;
    }
524616
public function beforeSave()
    {
        /*
         * Dynamic attributes are stored in the jsonable attribute 'data'.
         */
        $staticAttributes = ['id', 'theme', 'data', 'created_at', 'updated_at'];
        $dynamicAttributes = array_except($this->getAttributes(), $staticAttributes);

        $this->data = $dynamicAttributes;
        $this->setRawAttributes(array_only($this->getAttributes(), $staticAttributes));
    }
1082688
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
    {
        if (is_array($object->getConfig())) {
            $object->setConfig($this->serializer->serialize($object->getConfig()));
        }

        $rule = $this->ruleFactory->create();
        $ruleCondition = $object->getRuleCondition();

        if (is_object($ruleCondition)) {
            $rule = $ruleCondition;
        } elseif (is_array($ruleCondition)) {
            $rule->getConditions()->loadArray($ruleCondition);
        }
        $object->setRuleCondition($this->serializer->serialize($rule->getConditions()->asArray()));

        return parent::_beforeSave($object);
    }