before save attributes
173790
protected function beforeSave() 
	{
		if(parent::beforeSave()) {
			if(!$this->isNewRecord) {
				// set to default modules
				if($this->default_theme == 1) {
					self::model()->updateAll(array(
						'default_theme' => 0,
					), array(
						'condition'=> 'theme_id <> :theme AND group_page = :group',
						'params'=>array(
							':theme'=>$this->theme_id,
							':group'=>$this->group_page,
						),
					));
				}
			}
			
			if(!$this->isNewRecord)
				$this->config = serialize($this->config);
		}
		return true;
	}
1131042
public function beforeValidate()
    {
        /* @var $model ActiveRecord */
        $model = $this->owner;
        foreach ($this->attributes as $attr => $options) {
            $this->ensureAttributes($attr, $options);
            if ($file = UploadedFile::getInstance($model, $attr)) {
                $model->{$attr} = $file;
            }
        }
    }
699383
protected function _beforeSave(&$data) {
        // Make sure content nodes are not saved.
        if (!empty($data['content'])) {
            // Save chapters until after the Article is inserted, because we need the primary key.
            if (is_string($data['content'])) {
                $data['content'] = Zend_Json::decode($data['content']);
            }
            $this->_contentNodeList = $data['content'];
        }
        unset($data['content']);
    }
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;
    }
1189990
public function beforeValidate()
    {
        $this->fileName = $this->owner->getAttribute($this->fileField);
        if (!is_string($this->fileName)) {
            $this->fileName = @$this->owner->oldAttributes[$this->fileField];
        }
        if (
            (!$files = UploadedFile::getInstance($this->owner, $this->fileField))
            && (!$files = UploadedFile::getInstances($this->owner, $this->fileField))     
        ) {
            return true;
        }
        return $this->owner->setAttribute($this->fileField, $files);
    }
180552
public function beforeSave()
    {
        $this->getRecord()->active = 0;
        $this->getRecord()->cmsAuthIdReply = \App\Registry::$auth->getId();
        return true;
    }
1273604
def pre_save(self, model_instance, add):
        """"""
        value = socket.gethostname()
        setattr(model_instance, self.attname, value)
        return value
1346968
public function beforeValidate()
    {
        $this->reset();
        foreach ($this->relations as $key => $relation) {
            $data = is_array($relation) ? $relation : [];
            $relation = is_array($relation) ? $key : $relation;
            $ruleLoad = FormHelper::loadRelation($this->owner, $relation, Yii::$app->request->post(), $data);
            $this->savingModels[$relation] = $ruleLoad['models'];
            foreach ($ruleLoad['errors'] as $errors) {
                $this->owner->addError($relation, json_encode($errors, JSON_UNESCAPED_UNICODE));
            }
        }
    }
74492
public function beforeModelSave()
    {
        $preferences = UserPreference::forUser();
        list($namespace, $group, $item) = $preferences->parseKey($this->recordCode);
        $this->model->item = $item;
        $this->model->group = $group;
        $this->model->namespace = $namespace;
        $this->model->user_id = $preferences->userContext->id;

        if ($this->fieldValues) {
            $this->model->value = $this->fieldValues;
        }
    }
273462
def pre_save(sender, instance, raw, using, update_fields, **kwargs):
    """"""
    if raw:
        # Return if loading Fixtures
        return

    try:
        with transaction.atomic():
            if not should_audit(instance):
                return False
            try:
                object_json_repr = serializers.serialize("json", [instance])
            except Exception:
                # We need a better way for this to work. ManyToMany will fail on pre_save on create
                return None

            if instance.pk is None:
                created = True
            else:
                created = False

            # created or updated?
            if not created:
                old_model = sender.objects.get(pk=instance.pk)
                delta = model_delta(old_model, instance)
                changed_fields = json.dumps(delta)
                event_type = CRUDEvent.UPDATE

            # user
            try:
                user = get_current_user()
                # validate that the user still exists
                user = get_user_model().objects.get(pk=user.pk)
            except:
                user = None

            if isinstance(user, AnonymousUser):
                user = None

            # callbacks
            kwargs['request'] = get_current_request()  # make request available for callbacks
            create_crud_event = all(
                callback(instance, object_json_repr, created, raw, using, update_fields, **kwargs)
                for callback in CRUD_DIFFERENCE_CALLBACKS if callable(callback))
            # create crud event only if all callbacks returned True
            if create_crud_event and not created:
                c_t = ContentType.objects.get_for_model(instance)
                sid = transaction.savepoint()
                try:
                    with transaction.atomic():
                        crud_event = CRUDEvent.objects.create(
                            event_type=event_type,
                            object_repr=str(instance),
                            object_json_repr=object_json_repr,
                            changed_fields=changed_fields,
                            content_type_id=c_t.id,
                            object_id=instance.pk,
                            user_id=getattr(user, 'id', None),
                            datetime=timezone.now(),
                            user_pk_as_string=str(user.pk) if user else user
                        )
                except Exception as e:
                    logger.exception(
                        "easy audit had a pre-save exception on CRUDEvent creation. instance: {}, instance pk: {}".format(
                            instance, instance.pk))
                    transaction.savepoint_rollback(sid)
    except Exception:
        logger.exception('easy audit had a pre-save exception.')
627885
def put_attributes(self, attrs):
        
        assert(isinstance(attrs, dict)), "Argument must be a dict of key->values to save"
        for prop_name in attrs:
            value = attrs[prop_name]
            prop = self.find_property(prop_name)
            assert(prop), "Property not found: %s" % prop_name
            self._manager.set_property(prop, self, prop_name, value)
        self.reload()
        return self
1027086
def before_dump(value)
      self.value = value if !value.nil?
      if !@block.nil?
        value = @parent.instance_exec( self, :dump, &@block )
      end
      self.value = value if !value.nil?
    end
394509
protected function _beforeSave()
    {
        $date = Mage::getModel('core/date')->gmtDate();
        if ($this->isObjectNew() && !$this->getCreatedAt()) {
            $this->setCreatedAt($date);
        }
        $this->setStackData(serialize($this->stackLog));
        return parent::_beforeSave();
    }
1119477
function beforeAddItem(Sb $sb, A $item) {
		df_state()->attributeSet($item);
		try {$item['frontend_label'] = (string)__($item['frontend_label']);}
		finally {df_state()->attributeUnset();}
		return [$item];
	}
372973
protected function beforeSave() 
	{
		$module = strtolower(Yii::app()->controller->module->id);
		$controller = strtolower(Yii::app()->controller->id);
		$action = strtolower(Yii::app()->controller->action->id);

		$location = $controller;
		
		if(parent::beforeSave()) {
			if(!$this->isNewRecord) {
				$page_path = 'public/page';
				$verwijderen_path = join('/', array($page_path, 'verwijderen'));
				// Add directory
				if(!file_exists($page_path) || !file_exists($verwijderen_path)) {
					@mkdir($page_path, 0755, true);
					@mkdir($verwijderen_path, 0755, true);

					// Add file in directory (index.php)
					$newFile = $page_path.'/index.php';
					$FileHandle = fopen($newFile, 'w');

					$newVerwijderenFile = $verwijderen_path.'/index.php';
					$FileHandle = fopen($newVerwijderenFile, 'w');
				} else {
					@chmod($page_path, 0755, true);
					@chmod($verwijderen_path, 0755, true);
				}

				$this->media = CUploadedFile::getInstance($this, 'media');
				if($this->media != null) {
					if($this->media instanceOf CUploadedFile) {
						$fileName = time().'_'.$this->page_id.'.'.strtolower($this->media->extensionName);
						if($this->media->saveAs($page_path.'/'.$fileName)) {
							//create thumb image
							Yii::import('ext.phpthumb.PhpThumbFactory');
							$pageImg = PhpThumbFactory::create($page_path.'/'.$fileName, array('jpegQuality' => 90, 'correctPermissions' => true));
							$pageImg->resize(700);
							$pageImg->save($page_path.'/'.$fileName);

							if($this->old_media_i != '' && file_exists($page_path.'/'.$this->old_media_i))
								rename($page_path.'/'.$this->old_media_i, 'public/page/verwijderen/'.$this->page_id.'_'.$this->old_media_i);
							$this->media = $fileName;
						}
					}
				} else {
					if($this->media == '')
						$this->media = $this->old_media_i;
				}
			}

			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();
			}

			if($this->isNewRecord || (!$this->isNewRecord && !$this->desc)) {
				$desc=new SourceMessage;
				$desc->message = $this->desc_i;
				$desc->location = $location.'_description';
				if($desc->save())
					$this->desc = $desc->id;
				
			} else {
				$desc = SourceMessage::model()->findByPk($this->desc);
				$desc->message = $this->desc_i;
				$desc->save();
			}

			if($this->isNewRecord || (!$this->isNewRecord && !$this->quote)) {
				$quote=new SourceMessage;
				$quote->message = $this->quote_i;
				$quote->location = $location.'_quote';
				if($quote->save())
					$this->quote = $quote->id;
				
			} else {
				$quote = SourceMessage::model()->findByPk($this->quote);
				$quote->message = $this->quote_i;
				$quote->save();
			}

			// Create action
		}
		return true;
	}
1012845
public function beforeValidate()
    {
        if ($this->owner->getIsNewRecord()) {
            // added new record always on top
            $this->owner->{$this->sortAttribute} = $this->owner->find()->andWhere($this->getCondition())->count();
        } else {
            // prevent direct change of sort field
            $this->owner->{$this->sortAttribute} = $this->owner->getOldAttribute($this->sortAttribute);
        }
    }
957694
public function beforeSave()
    {
        /* @var $model ActiveRecord */
        $model = $this->owner;
        foreach ($this->attributes as $attr => $options) {
            $this->ensureAttribute($attr, $options);
            if ($file = UploadedFile::getInstance($model, $attr)) {
                $this->createDirIfNotExists($attr);
                if (!$model->isNewRecord) {
                    $this->deleteFiles($attr);
                }
                $fileName = uniqid() . '.' . $file->extension;
                if ($this->needCrop($attr)) {
                    $coords = $this->getCoords($attr);
                    if ($coords === false) {
                        throw new InvalidCallException();
                    }
                    $image = $this->crop($file, $coords, $options);
                    $image->save($this->getSavePath($attr) . $fileName);
                } else {
                    $image = $this->processImage($file->tempName, $options);
                    $image->save($this->getSavePath($attr) . $fileName);
                }
                $model->{$attr} = $fileName;

                if ($this->issetThumbnails($attr)) {
                    $thumbnails = $this->attributes[$attr]['thumbnails'];
                    foreach ($thumbnails as $name => $options) {
                        $this->ensureAttribute($name, $options);
                        $tmbFileName = $name . '_' . $fileName;
                        $image = $this->processImage($this->getSavePath($attr) . $fileName, $options);
                        $image->save($this->getSavePath($attr) . $tmbFileName);
                    }
                }
            } elseif (isset($model->oldAttributes[$attr])) {
                $model->{$attr} = $model->oldAttributes[$attr];
            }
        }
    }