before save attributes
765516
protected function beforeSave() 
	{
		$currentAction = strtolower(Yii::app()->controller->id.'/'.Yii::app()->controller->action->id);
		
		if(parent::beforeSave()) {
			$meta_path = "public";
			$this->meta_image = CUploadedFile::getInstance($this, 'meta_image');
			if($this->meta_image instanceOf CUploadedFile) {
				$fileName = 'meta_'.time().'.'.$this->meta_image->extensionName;
				if($this->meta_image->saveAs($meta_path.'/'.$fileName)) {
					if($this->old_meta_image != '')
						@unlink($meta_path.'/'.$this->old_meta_image);
					$this->meta_image = $fileName;

					//create thumb image
					Yii::import('ext.phpthumb.PhpThumbFactory');
					$pageImg = PhpThumbFactory::create($meta_path.'/'.$fileName, array('jpegQuality' => 90, 'correctPermissions' => true));
					$pageImg->resize(700);
					$pageImg->save($meta_path.'/'.$fileName);
				}
			}
			
			if($currentAction == 'meta/edit')
				$this->map_icon_size = serialize($this->map_icon_size);
			
			if($currentAction == 'meta/twitter') {
				$this->twitter_photo_size = serialize($this->twitter_photo_size);
				$this->twitter_iphone = serialize($this->twitter_iphone);
				$this->twitter_ipad = serialize($this->twitter_ipad);
				$this->twitter_googleplay = serialize($this->twitter_googleplay);
			}
		}
		return true;
	}
16807
public function preSave()
    {
        if (!isset($this->revisionEnabled) || $this->revisionEnabled) {
            // if there's no revisionEnabled. Or if there is, if it's true

            $this->originalData = $this->original;
            $this->updatedData  = $this->attributes;

            // we can only safely compare basic items,
            // so for now we drop any 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]);
                }
            }

            // the below is ugly, for sure, but it's required so we can save the standard model
            // then use the keep / dontkeep values for later, in the isRevisionable method
            $this->dontKeep = isset($this->dontKeepRevisionOf) ?
                array_merge($this->dontKeepRevisionOf, $this->dontKeep)
                : $this->dontKeep;

            $this->doKeep = isset($this->keepRevisionOf) ?
                array_merge($this->keepRevisionOf, $this->doKeep)
                : $this->doKeep;

            unset($this->attributes['dontKeepRevisionOf']);
            unset($this->attributes['keepRevisionOf']);

            $this->dirtyData = $this->getDirty();
            $this->updating = $this->exists;
        }
    }
1090914
def pre_save(self, model_instance, add):
        
        # pylint: disable=newstyle
        # Retrieve the currently entered datetime
        value = super(
            LinkedTZDateTimeField,
            self
        ).pre_save(
            model_instance=model_instance,
            add=add
        )

        # Convert the value to the correct time/timezone
        value = self._convert_value(
            value=value,
            model_instance=model_instance,
            add=add
        )

        setattr(model_instance, self.attname, value)

        return value
941234
def store_attribute(self, key, value):
        """"""
        if key == 'summary' or key == 'filename' or key == 'previous':
            return
        attr = key.replace('-', '_')
        if key.endswith('-time'):
            value = int(value)
        setattr(self, attr, value)
741044
public function beforeSave($event)
    {
        list($id, $attribute) = $event->data;
        if (isset(self::$_executed[$id])) {
            return;
        }
        /* @var $object \yii\db\ActiveRecord */
        $object = $event->sender;
        if (is_string($this->format) && method_exists($object, $this->format)) {
            $value = call_user_func([$object, $this->format], $object, $attribute);
        } else {
            $value = is_callable($this->format) ? call_user_func($this->format, $object, $attribute) : $this->format;
        }
        $group = md5(serialize([
            'class' => $this->unique ? get_class($object) : false,
            'group' => $this->group,
            'attribute' => $attribute,
            'value' => $value
        ]));
        $model = Autonumber::findOne($group);
        if ($model) {
            $number = $model->number + 1;
        } else {
            $model = new Autonumber([
                'group' => $group
            ]);
            $number = 1;
        }
        $model->update_time = time();
        $model->number = $number;
        if ($value === null) {
            $object->$attribute = $number;
        } else {
            $object->$attribute = str_replace('?', $this->digit ? sprintf("%0{$this->digit}d", $number) : $number, $value);
        }
        self::$_executed[$id] = true;
        try {
            $model->save(false);
        } catch (\Exception $exc) {
            $event->isValid = false;
            if ($this->throwIsStale || !($exc instanceof StaleObjectException)) {
                throw $exc;
            }
        }
    }
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');
		}
	}
729301
def insertBefore(self, node: AbstractNode,
                     ref_node: AbstractNode) -> AbstractNode:
        """"""
        return self._insert_before(node, ref_node)
114756
protected function beforeSave($event)
    {
        if ($this->autoSave) {
            $this->saveFile($this->owner->{$this->uploadAttribute}, $this->name, $this->path);
        }
    }
1011513
protected function beforeSave() 
	{
		$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::beforeSave()) {
			$this->construction_date = date('Y-m-d', strtotime($this->construction_date));
			if($currentAction == 'settings/general')
				$this->construction_text = serialize($this->construction_text);
			$this->event_startdate = date('Y-m-d', strtotime($this->event_startdate));
			$this->event_finishdate = date('Y-m-d', strtotime($this->event_finishdate));
		}
		return true;
	}
1308888
public function beforeValidate()
    {
        foreach ($this->attributes as $attribute) {
            $this->setMultilingualAttribute($this->getAttributeName($attribute, $this->_currentLanguage), $this->getMultilingualAttribute($attribute));
        }
    }
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);
    }
744260
public function beforeVersionedSave()
    {
        $this->wasDirty = false;
        if ($this->isDirty && static::$createRevisionOnSave) {
            // update creation time
            $this->Created = time();
            $this->wasDirty = true;
        }
    }
1234741
def save
      run_callbacks(:before_save)
      run_callbacks(:before_create) unless self.is_created

      existing_items = self.class.all
      if self.new_record?
        existing_items << self
      else # update existing record
        updated_item = existing_items.find { |item| item.id == self.id }
        return false unless updated_item
        updated_item.attributes = self.attributes
      end

      raw_data = existing_items ? existing_items.map { |item| item.persisted_attributes } : []
      self.class.write_contents(raw_data) if self.valid?

      run_callbacks(:after_create) unless self.is_created
      run_callbacks(:after_save)
      true
    rescue IOError
      false
    end
595742
protected function beforeSave() 
	{
		$module = strtolower(Yii::app()->controller->module->id);
		$controller = strtolower(Yii::app()->controller->id);
		$action = strtolower(Yii::app()->controller->action->id);

		$location = $module.' '.$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();
			}

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

			if($action != 'publish') {
				$this->cat_code = $this->urlTitle($this->name_i);
				//Banner Size
				$this->banner_size = serialize($this->banner_size);
			}
		}
		return true;
	}
180552
public function beforeSave()
    {
        $this->getRecord()->active = 0;
        $this->getRecord()->cmsAuthIdReply = \App\Registry::$auth->getId();
        return true;
    }
1342644
public function beforeSave($event) {
		if ($this->getOwner()->getIsNewRecord() && ($this->createAttribute !== null)) {
			$this->getOwner()->{$this->createAttribute} = $this->getTimestampByAttribute($this->createAttribute);
		}
		if ((!$this->getOwner()->getIsNewRecord() || $this->setUpdateOnCreate) && ($this->updateAttribute !== null)) {
			$this->getOwner()->{$this->updateAttribute} = $this->getTimestampByAttribute($this->updateAttribute);
		}
	}
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;
	}