prepare, validate, beforeSave
356989
function beforeCommit(object, callback) {
  var self = this;
  async.waterfall([
    this.triggerTransformEvent.bind(this, 'prepare', object),
    this.triggerProgressionEvent.bind(this, 'validate'),
    this.triggerEvent.bind(this, 'beforeSave')
  ], function(err, object) {
    if (err) return callback(err);

    // run beforeCommit on all composed objects as well.
    transformComps.call(self, object, object, function(comp, object, i, cb) {
      if (comp.transient) return cb();
      beforeCommit.call(comp.model, object, cb);
    }, callback);
  });
}
549230
function preSave($create = false)
    {
        if ($this->id == '') {
            $this->creation_dtime = gmdate('Y-m-d H:i:s');
        }
        $this->modif_dtime = gmdate('Y-m-d H:i:s');
    }
598772
protected function prepareToExit()
    {
        $this->getSession()->freeze();
        $this->commitFileCache();

        $this->dispatchEvent(new \OxidEsales\EshopCommunity\Internal\ShopEvents\ApplicationExitEvent());

        if ($this->isSearchEngine()) {
            $header = \OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Core\Header::class);
            $header->setNonCacheable();
        }

        //Send headers that have been registered
        $header = \OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Core\Header::class);
        $header->sendHeader();
    }
642979
function (req, res, options) {
    if (!options) {
      options = {};
    }
    options.operation = 'SAVE';
    options.res = res;
    if (req.params.model) {
      options.model = req.params.model;
    }
    if (req.body) {
      options.item = req.body;
    }
    if (req.params.data) {
      options.data = req.params.data;
    }
    exports.save.before(req, res, options);
    var userId = req.session['user-id'];
    vulpejs.models.save({
      model: options.model,
      item: options.item,
      data: options.data,
      validate: options.validate || false,
      userId: userId,
      callback: {
        success: function (item) {
          if (!vulpejs.utils.execute(options.callback, {
              item: item,
              postedItem: options.item,
              res: res,
            })) {
            exports.save.after(req, res, item);
            res.json({
              item: item,
              postedItem: options.item,
            });
          }
        },
        error: function (error) {
          exports.response.error(options, error);
        },
        validate: function (validate) {
          exports.response.validate(options, validate);
        },
      },
    });
  }
463354
public function beforeValidate()
    {
        foreach ($this->attributes as $attribute) {
            $this->owner->$attribute = HtmlPurifier::process($this->owner->$attribute, $this->config);
        }
    }
687674
protected function beforeValidate() 
	{
		$controller = strtolower(Yii::app()->controller->id);
		$setting = BannerSetting::model()->findByPk(1, array(
			'select' => 'banner_validation, banner_file_type',
		));
		$banner_file_type = unserialize($setting->banner_file_type);
		if(empty($banner_file_type))
			$banner_file_type = array();
		
		if(parent::beforeValidate()) {
			if($this->isNewRecord)
				$this->creation_id = !Yii::app()->user->isGuest ? Yii::app()->user->id : null;
			else
				$this->modified_id = !Yii::app()->user->isGuest ? Yii::app()->user->id : null;
			
			$banner_filename = CUploadedFile::getInstance($this, 'banner_filename');
			if($banner_filename != null) {
				$extension = pathinfo($banner_filename->name, PATHINFO_EXTENSION);
				$validation = 0;
				if($setting->banner_validation == 1)
					$validation = 1;
				$fileSize = getimagesize($banner_filename->tempName);
				$bannerSize = unserialize($this->category->banner_size);
				
				if(!in_array(strtolower($extension), $banner_file_type))
					$this->addError('banner_filename', Yii::t('phrase', 'The file {name} cannot be uploaded. Only files with these extensions are allowed: {extensions}.', array(
						'{name}'=>$banner_filename->name,
						'{extensions}'=>Utility::formatFileType($banner_file_type, false),
					)));
				else {
					if($validation == 1 && !($fileSize[0] == $bannerSize['width'] && $fileSize[1] == $bannerSize['height']))
						$this->addError('banner_filename', Yii::t('phrase', 'The file {name} cannot be uploaded. ukuran banner ({file_size}) tidak sesuai dengan kategori ({banner_size})', array(
							'{name}'=>$banner_filename->name,
							'{file_size}'=>$fileSize[0].' x '.$fileSize[1],
							'{banner_size}'=>$bannerSize['width'].' x '.$bannerSize['height'],
						)));
				}
			} else {
				if($this->isNewRecord && $controller == 'o/admin')
					$this->addError('banner_filename', Yii::t('phrase', 'Banner (File) cannot be blank.'));
			}
			
			if($this->linked_i == 0)
				$this->url = '-';
			
			if(in_array(Yii::$app->formatter->asDate($this->expired_date, 'php:Y-m-d'), array('00-00-0000','01-01-1970')))
				$this->permanent_i = 1;
			
			if($this->permanent_i == 1)
				$this->expired_date = '00-00-0000';
			
			if($this->linked_i == 1 && $this->url == '-')
				$this->addError('url', Yii::t('phrase', 'URL harus dalam format hyperlink'));
			
			if($this->permanent_i != 1 && ($this->published_date != '' && $this->expired_date != '') && ($this->published_date >= $this->expired_date))
				$this->addError('expired_date', Yii::t('phrase', 'Expired lebih kecil'));
		}
		return true;
	}
608132
protected function beforeValidate() 
	{
		$controller = strtolower(Yii::app()->controller->id);
		$action = strtolower(Yii::app()->controller->action->id);
		$currentAction = strtolower(Yii::app()->controller->id.'/'.Yii::app()->controller->action->id);

		if(parent::beforeValidate()) {
			if($currentAction == 'settings/general') {
				if($this->online != 1) {
					if($this->construction_date == '')
						$this->addError('construction_date', Yii::t('phrase', 'Maintenance date cannot be blank.'));
					if($this->online == 0 && $this->construction_text['maintenance'] == '')
						$this->addError('construction_text[maintenance]', Yii::t('phrase', 'Maintenance text cannot be blank.'));
					if($this->online == 2 && $this->construction_text['comingsoon'] == '')
						$this->addError('construction_text[comingsoon]', Yii::t('phrase', 'Coming Soon text cannot be blank.'));
				}

				if($this->event_i == 0) {
					$this->event_startdate = '00-00-0000';
					$this->event_finishdate = '00-00-0000';
					
				} else {
					$condition = 0;
					if($this->event_startdate != '' && in_array(date('Y-m-d', strtotime($this->event_startdate)), array('0000-00-00','1970-01-01','0002-12-02','-0001-11-30'))) {
						$condition = 0;
						$this->addError('event_startdate', Yii::t('phrase', 'Event Startdate cannot be blank or default date.'));
					} else
						$condition = 1;
					if($this->event_finishdate != '' && in_array(date('Y-m-d', strtotime($this->event_finishdate)), array('0000-00-00','1970-01-01','0002-12-02','-0001-11-30'))) {
						$condition = 0;
						$this->addError('event_finishdate', Yii::t('phrase', 'Event Finishdate cannot be blank or default date.'));
					} else
						$condition = 1;
					if($condition == 1 && (date('Y-m-d', strtotime($this->event_startdate)) >= date('Y-m-d', strtotime($this->event_finishdate))))
						$this->addError('event_finishdate', Yii::t('phrase', 'Event Finishdate tidak boleh lebih kecil'));
				}
			}
			
			$this->modified_id = !Yii::app()->user->isGuest ? Yii::app()->user->id : null;
		}
		return true;
	}
581646
def _prep_save(self):
        
        log.info("Preparing bulk save.")
        self.graph.update_bulk_saver(self.bulk_saver)

        log.info(
            "Dropped %d unused preconditions, %d are missing",
            sum(len(v) for v in self.summary["precondition_entries"].values()),
            len(self.summary["missing_preconditions"]),
        )

        log.info(
            "Dropped %d unused postconditions, %d are missing",
            sum(len(v) for v in self.summary["postcondition_entries"].values()),
            len(self.summary["missing_postconditions"]),
        )
        del self.summary["postcondition_entries"]
209748
protected function prepareForValidation(): void
    {
        $data = $this->all();

        $guardian = $this->route('guardian') ?? app('cortex.auth.guardian');

        if ($guardian->exists && empty($data['password'])) {
            unset($data['password'], $data['password_confirmation']);
        }

        $this->replace($data);
    }
1007089
def before_processing(eng, objects):
        """"""
        super(InvenioProcessingFactory, InvenioProcessingFactory)\
            .before_processing(eng, objects)
        eng.save(WorkflowStatus.RUNNING)
        db.session.commit()
995979
protected function beforeCreate()
    {
        $this->dispatcher->getEventsManager()->fire(Events::BEFORE_CREATE, $this);
        $this->beforeSave();
    }
1241717
function prepareHtml() {
        // remove all tabs and new lines - as they mean nothing in HTML
        $this->html = trim(preg_replace('/\t\n/', '', $this->html));

        // normalize multiple spaces to one space
        $this->html = preg_replace('/\s+/', ' ', $this->html);

        // replace special characters like &nbsp;
        $this->html = $this->replaceSpecialCharacters($this->html);

//        $charset = 'UTF-8';
//        if (function_exists('mb_convert_encoding') && in_array(strtolower($charset), array_map('strtolower', mb_list_encodings()))) {
//            $this->html = mb_convert_encoding($this->html, 'HTML-ENTITIES', $charset);
//        }

    }
1653
public function beforeSave()
    {
        if ($this->file instanceof UploadedFile) {

            if (true !== $this->owner->isNewRecord) {
                /** @var ActiveRecord $oldModel */
                $oldModel = $this->owner->findOne($this->owner->primaryKey);
                $behavior = static::getInstance($oldModel, $this->attribute);
                $behavior->cleanFiles();
            }

            $this->owner->{$this->attribute} = implode('.',
                array_filter([$this->file->baseName, $this->file->extension])
            );
        } else {
            if (true !== $this->owner->isNewRecord && empty($this->owner->{$this->attribute})) {
                $this->owner->{$this->attribute} = ArrayHelper::getValue($this->owner->oldAttributes, $this->attribute,
                    null);
            }
        }
    }
719535
protected function prepareForValidation(): void
    {
        $data = $this->all();

        $data['entity_id'] = $this->user($this->route('guard'))->getKey();
        $data['entity_type'] = $this->user($this->route('guard'))->getMorphClass();

        $this->replace($data);
    }
238622
protected function prepare()
    {
        if (!is_array($this->data) || count($this->data) == 0) {
            $this->setData($this->read());
        }
    }
1085551
function prepare (o) {
    try {
      var input = checkInput(o)
      var q = Queries.mkQuery(input)

      // we have win!
      return [q]
    } catch (err) {
      // other than spewing, we ignore errors
      console.error(err.stack)

      // so this request will be flatmapped away
      return []
    }
  }
743763
def prepare(self):
        
        # Maybe the Brok is a old daemon one or was already prepared
        # if so, the data is already ok
        if hasattr(self, 'prepared') and not self.prepared:
            self.data = unserialize(self.data)
            if self.instance_id:
                self.data['instance_id'] = self.instance_id
        self.prepared = True