This method is called at the beginning of inserting or updating a record.
@param bool $insert
@return bool
165452
public function beforeSave($insert)
    {
        if (parent::beforeSave($insert))
        {
            if ($this->parentId > 0)
            {
                $parentNodeLevel = (int)self::find()->select('level')->where(['id' => $this->parentId])->scalar();
                $this->level = $parentNodeLevel + 1;
            }

            return TRUE;
        }
        else
        {
            return FALSE;
        }
    }
981372
public function insert($data = null)
    {
        $currentIndex = $this->getFieldValue($this->getIndex());
        $fields = $this->getFields();
        $sql1 = '';
        $sql2 = '';
        $args = array();
        foreach ($fields as $field) {
            // if($this->getFieldValue($field, $data) !== NULL)
            if (in_array($field, $this->created_at_fileds)) {
                $this->{$field} = now();
            }
            $value = $this->getFieldValue($field, $data);
            $args[$field] = $value;
            $sql1 .= "`$field`, ";
            $sql2 .= ":$field, ";
        }
        if (!empty($sql1)) {
            $sql1 = substr($sql1, 0, -2);
            $sql2 = substr($sql2, 0, -2);
            if($currentIndex) {
                $this->db->removeCache($this->getCacheId($currentIndex));
            }
            return $this->db->insert('INSERT INTO `'.$this->table_name.'` ('.$sql1.') VALUES ('.$sql2.')', $args);
        }
        return false;
    }
326747
protected function addDoInsert()
    {
        $table = $this->getTable();
        $script = "
    /**
     * Insert the row in the database.
     *
     * @param      ConnectionInterface \$con
     *
     * @throws PropelException
     * @see doSave()
     */
    protected function doInsert(ConnectionInterface \$con)
    {";
        if ($this->getPlatform() instanceof MssqlPlatform) {
            if ($table->hasAutoIncrementPrimaryKey() ) {
                $script .= "
        \$this->modifiedColumns[" . $this->getColumnConstant($table->getAutoIncrementPrimaryKey()).'] = true;';
            }
            $script .= "
        \$criteria = \$this->buildCriteria();";
            if ($this->getTable()->getIdMethod() != IdMethod::NO_ID_METHOD) {
                $script .= $this->addDoInsertBodyWithIdMethod();
            } else {
                $script .= $this->addDoInsertBodyStandard();
            }
        } else {
            $script .= $this->addDoInsertBodyRaw();
        }
        $script .= "
        \$this->setNew(false);
    }
";

        return $script;
    }
621903
public function beforeSave ($insert)
		{
			if ($parent = parent::beforeSave($insert))
			{
				if ($this->isNewRecord)
				{
					if ($this->hasAttribute('order') and empty($this->order))
					{
						$query = self::find()->select('order')->orderBy([ 'order' => SORT_DESC ]);

						$condition = $this->orderCondition();
						if ($condition !== null)
						{
							$query->where($condition);
						}

						$order = $query->scalar();

						$this->order = !is_null($order) ? $order + 1 : 1;
					}
				}
			}

			return $parent;
		}
169083
public function insert()
	{
		$res = \DB::insert(call_user_func($this->model.'::table'), array_keys($this->values))
			->values(array_values($this->values))
			->execute($this->write_connection);

		// Failed to save the new record
		if ($res[1] === 0)
		{
			return false;
		}

		return $res[0];
	}
158067
public function beforeSave($insert)
    {
        if (parent::beforeSave($insert)) {
            if (empty($this->supplier_quantity)) {
                $this->supplier_quantity = $this->quantity;
            }
            $this->total_price = $this->quantity * $this->product_unit_price;
            if (empty($this->supplier_total_price)) {
                $this->supplier_total_price = $this->total_price;
            }

            return true;
        }

        return false;
    }
736513
public function beforeSave($insert)
	{		
		if (parent::beforeSave($insert)) 
		{
			if ($insert) 
			{
				$this->created_at=$this->updated_at=time();
				$this->author_id=\Yii::$app->user->identity->id;
			}
			else
			{
				$this->updated_at=time();
				$a = strptime($this->created_at, '%Y-%m-%d');
				$timestamp = mktime(0, 0, 0, $a['tm_mon']+1, $a['tm_mday']+1, $a['tm_year']+1900);				
				$this->created_at = $timestamp;		
			}
			return true;
		} 
		return false;
	}
90901
public function insert($ignore = false)
    {
        $this->validate();

        // Optional ignore string
        if ($ignore) {
            $insertString = "INSERT IGNORE INTO `%s` (%s) VALUES %s";
        } else {
            $insertString = "INSERT INTO `%s` (%s) VALUES %s";
        }

        $query = sprintf(
            $insertString,
            $this->table,
            $this->rowsString,
            $this->bindString
        );

        try {
            $this->db->execute($query, $this->valuesFlattened);
            return $this->db->affectedRows() > 0;
        } catch (PDOException $ex) {
            Di::getDefault()->get(Services::LOGGER)->error(
                'Could not perform bulk insert ' . $ex->getMessage() . '    TRACE: ' . $ex->getTraceAsString()
            );
            throw new BatchInsertException($ex->getMessage());
        }
    }
517381
public function insert() {
    $this->db()->insert($this->table, $this->record);
    $id = $this->db()->lastInsertId();
    $this->record[$this->id_name] = $id;
    $this->isDirty = FALSE;

    return $this;
  }
19005
public function afterSave($insert, $changedAttributes)
    {
        try {
            if ($insert) {
                $this->insertWords();
            } else {
                $this->updateWords();
            }
        } catch (Exception $e) {
            throw $e;
        }
        parent::afterSave($insert, $changedAttributes);
    }
117272
private function insert($validate = true)
	{
		$this->verifyNotReadonly('insert');

		// Check if validation or beforeCreate returns false.
		if (($validate && !$this->_validate() || !$this->invokeCallback('beforeCreate',false))) {
			return false;
		}

		$table = static::table();

		// Get dirty attributes, or when nothing is dirty we just take all atrributes
		if (!($attributes = $this->dirtyAttributes())) { 
			$attributes = $this->_attributes;
		}

		$pk = $this->getPrimaryKey(true);
		$useSequence = false;

		if ($table->sequence && !isset($attributes[$pk]))
		{
			if (($conn = static::connection()) instanceof OciAdapter) {

				// terrible oracle makes us select the nextval first
				$attributes[$pk] = $conn->getNextSequenceValue($table->sequence);
				$table->insert($attributes);
				$this->_attributes[$pk] = $attributes[$pk];
				
			} else {
				// unset pk that was set to null
				if (array_key_exists($pk, $attributes)) {
					unset($attributes[$pk]);
				}

				$table->insert($attributes, $pk, $table->sequence);
				$useSequence = true;
			}
		} else {

			// Simple insert
			$table->insert($attributes);

		}
			

		// if we've got an autoincrementing/sequenced pk set it
		// don't need this check until the day comes that we decide to support composite pks
		// if (count($pk) == 1)
		{
			$column = $table->getColumnByInflectedName($pk);

			if ($column->autoIncrement || $useSequence) {
				$this->_attributes[$pk] = static::connection()->insertId($table->sequence);
			}
		}

		$this->_newRecord = false;
		$this->invokeCallback('afterCreate', false);
		return true;
	}
1028920
public function check(array $insert, bool $throw = true): bool
    {
        foreach ($this->schema as $key => $rules) {
            // Check each key by given rules and respond
            // due to required flow.
            $result = $this->processRules($key, explode('|', $rules), $insert);

            if (!$result['status'] && $throw) {
                throw new InvalidArgumentException(
                    sprintf($result['message'], $key)
                );
            }
        }

        return $result['status'] ?? true;
    }
610020
public function beforeSave($insert)
    {
        if (parent::beforeSave($insert)) {
            $img = upload_img('User[avatar]');
            if (!empty($img)) {
                $this->avatar = $img;
            } elseif(empty($img) && !$this->isNewRecord) {
                $model = static::findOne(['id' => $this->id]);
                if ($model) {
                    $this->avatar = $model->avatar;
                }
            }

            return true;
        }

        return false;
    }
555576
protected function _insert()
    {
        if (!$this->oxnews__oxdate || \OxidEsales\Eshop\Core\Registry::getUtilsDate()->isEmptyDate($this->oxnews__oxdate->value)) {
            // if date field is empty, assigning current date
            $this->oxnews__oxdate = new \OxidEsales\Eshop\Core\Field(date('Y-m-d'));
        } else {
            $this->oxnews__oxdate = new \OxidEsales\Eshop\Core\Field(\OxidEsales\Eshop\Core\Registry::getUtilsDate()->formatDBDate($this->oxnews__oxdate->value, true));
        }

        return parent::_insert();
    }
842178
public function create () : bool
	{
        $dbObject 	= Database::getInstance();
		$attributes = $this->sanitizedAttributes();
		$sqlQuery	= "INSERT INTO ".static::$tableName." (";
		$sqlQuery  .= join(", ", array_keys($attributes));
	  	$sqlQuery  .= ") VALUES ('";
		$sqlQuery  .= join("', '", array_values($attributes));
		$sqlQuery  .= "')";
		$result 	= $dbObject->query($sqlQuery);
    	$this->id 	= $dbObject->insertId();
    	return ($result) ? TRUE : FALSE;
	}
862312
public function beforeSave($insert)
    {
        if (parent::beforeSave($insert)) {
            if ($this->isNewRecord) {
                $this->key = get_current_cart_key();
                $check = Cart::find()
                    ->where(['product' => $this->product])
                    ->andWhere(['key' => $this->key])
                    ->one();
                if (!empty($check)) {
                    $this->quantity += $check->quantity;
                    Cart::deleteAll([
                        'key' => $this->key,
                        'product' => $this->product
                    ]);
                }
            }
            return true;
        }

        return false;
    }
623636
protected function _insert()
    {
        // we do not store credit card information
        // check and in case skip it
        if (!$this->getStoreCreditCardInfo() && $this->oxuserpayments__oxpaymentsid->value == 'oxidcreditcard') {
            return true;
        }

        //encode sensitive data
        if ($sValue = $this->oxuserpayments__oxvalue->value) {
            // Function is called from inside a transaction in Category::save (see ESDEV-3804 and ESDEV-3822).
            // No need to explicitly force master here.
            $database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
            $sEncodedValue = $database->getOne("select encode( " . $database->quote($sValue) . ", '" . $this->getPaymentKey() . "' )");
            $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
        }

        $blRet = parent::_insert();

        //restore, as encoding was needed only for saving
        if ($sEncodedValue) {
            $this->oxuserpayments__oxvalue->setValue($sValue);
        }

        return $blRet;
    }