Save document

@param bool $validate

@return Document

@throws WriteException
@throws Exception
8774
public function save($validate = true)
    {
        // if document already in db and not modified - skip this method
        if (!$this->isSaveRequired()) {
            return $this;
        }

        if ($validate) {
            $this->validate();
        }

        // handle beforeSave event
        if ($this->triggerEvent(self::EVENT_NAME_BEFORE_SAVE)->isCancelled()) {
            return $this;
        }

        // write document
        if ($this->isStored()) {
            $this->internalUpdate();
        } else {
            $this->internalInsert();
        }

        // handle afterSave event
        $this->triggerEvent(self::EVENT_NAME_AFTER_SAVE);

        // set document unmodified
        $this->apply();
        
        return $this;
    }
1129452
private function update($validate = true)
	{
		$this->verifyNotReadonly('update');

		// Valid record?
		if ($validate && !$this->_validate()) {
			return false;
		}

		// Anything to update?
		if ($this->isDirty()) {

			// Check my primary key
			$pk = $this->valuesForPk();
			if (empty($pk)) {
				throw new ActiveRecordException("Cannot update, no primary key defined for: " . get_called_class());
			}

			// Check callback
			if (!$this->invokeCallback('beforeUpdate',false)) {
				return false;
			}

			// Do the update
			$dirty = $this->dirtyAttributes();
			static::table()->update($dirty, $pk);
			$this->invokeCallback('afterUpdate',false);
		}

		return true;
	}
601410
public function save($item, bool $update = false)
    {
        return Craft::$app->assetTransforms->saveTransform($item);
    }
479
public function savePreviousVersion($version)
    {
        if (!is_numeric($version)) {
            return;
        }

        try {
            $this->setVersionNumber($version);
            $this->owner->write();
        } catch (Exception $e) {
            throw new ValidationException(new ValidationResult(
                false,
                "Could not replace file #{$this->owner->ID} with version #$version."
            ));
        }
    }
699429
public function save(array $fieldList, $validate = true)
    {
        $this->logger->debug('# setSettings save start');

        if ($validate) {
            $this->validate($fieldList);
        }

        foreach ($fieldList as $property) {
            if (in_array($property, $this->blacklistConfig, true)) {
                continue;
            }

            if (isset($this->configMapping[$property])) {
                $config =
                    $this->sgCoreConfig->getSaveScope($this->configMapping[$property], $this->getShopNumber());
                $this->saveField(
                    $this->configMapping[$property],
                    $property,
                    $config->getScope(),
                    $config->getScopeId()
                );
            }
        }

        $this->clearCache();
        $this->logger->debug('# setSettings save end');
    }
1169033
public function store($document)
    {
        if (is_null($document->get('_dateCreated'))) {
            $document->set('_dateCreated', date('Y-m-d H:i:s'));
        }
        $document->set('_dateUpdated', date('Y-m-d H:i:s'));

        if ($document->getIsNew()) {
            if (method_exists($document, 'onCreate')) {
                $document->onCreate();
            }

            return $this->_documentHandler->save($this->_collectionName, $document);
        } else {
            if (method_exists($document, 'onUpdate')) {
                $document->onUpdate();
            }

            return $this->_documentHandler->replace($document);
        }
    }
509985
public function saveRenderedReason(bool $save = true)
    {
        $raw = $this->getAttributeFromArray('reason');

        if (($rendered = markdown($raw)) === $this->getAttributeFromArray('reason_rendered')) {
            return null;
        }

        $this->setAttribute('reason_rendered', $rendered);

        if ($save) {
            $this->save();
        }

        $this->renderedReason = $rendered;

        return $this;
    }
417725
public function saveCategory($data = [])
    {
        if (!empty($data)) {
            $this->data($data);
        }
        $validate = new \gmars\rbac\validate\PermissionCategory();
        if (!$validate->check($this)) {
            throw new Exception($validate->getError());
        }
        $data = $this->getData();
        if (isset($data['id']) && !empty($data['id'])) {
            $this->isUpdate(true);
        }
        $this->save();
        return $this;
    }
668903
function save_file($elname, $pathname, $override=false) {
        global $USER;

        if (!$this->is_submitted() or !$this->is_validated()) {
            return false;
        }
        if (file_exists($pathname)) {
            if ($override) {
                if (!@unlink($pathname)) {
                    return false;
                }
            } else {
                return false;
            }
        }

        $element = $this->_form->getElement($elname);

        if ($element instanceof MoodleQuickForm_filepicker || $element instanceof MoodleQuickForm_filemanager) {
            $values = $this->_form->exportValues($elname);
            if (empty($values[$elname])) {
                return false;
            }
            $draftid = $values[$elname];
            $fs = get_file_storage();
            $context = context_user::instance($USER->id);
            if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) {
                return false;
            }
            $file = reset($files);

            return $file->copy_content_to($pathname);

        } else if (isset($_FILES[$elname])) {
            return copy($_FILES[$elname]['tmp_name'], $pathname);
        }

        return false;
    }
645238
public function save()
    {
        $query = $this->newQueryNotModel(['*']);

        // Validar attributes
        if ($this->validate() != true) {
            return false;
        }

        // Disparar evento que o documento esta sendo salvo
        if ($this->fireModelEvent('saving') === false) {
            return false;
        }

        // Verificar se deve atualizar registro ou inserir um novo
        if ($this->exists) {
            $saved = $this->hasChanged() ? $this->performUpdate($query) : true;
        } else {
            $saved = $this->performInsert($query);
        }

        // Se documento foi salvo, finalizar com evento
        if ($saved) {
            // Disparar evento que documento foi salvo
            $this->fireModelEvent('saved', false);

            // SIncronizar orifinais
            $this->syncOriginal();
        }

        return $saved;
    }
517669
public function save(Form $form)
    {
        $this->em->persist($form);
        $this->em->flush();

        return $form;
    }
1238954
public static function document($doc, $prepend = false)
    {
        $document = Validation::document($doc);
        if ($document['type'] == 1) {
            return ($prepend ? 'CPF: ' : '') . self::cpf($document['valid']);
        } elseif ($document['type'] == 2) {
            return ($prepend ? 'CNPJ: ' : '') . self::cnpj($document['valid']);
        }
        return $document['valid'] ?? $doc;
    }
272909
protected function doWrite(string $text, bool $error = false): self
    {
        $stream = $error ? $this->eStream : $this->stream;

        \fwrite($stream, $text);

        return $this;
    }
67316
public function set ($name, $val, $validate = TRUE)
	{
		
		// If the attribute doesn't exists
		
		if (!$this->attributeExists ($name))
		{
			throw new Exception (get_called_class () . '->' . $name . ' attribute does not exist!');
		}
		
		// If attribute setter isn't set or is disabled
		
		if (!$this->attributeSet ($name))
		{
			throw new Exception (get_called_class () . '->' . $name . ' attribute set is disabled!');
		}
		
		// If we're validating the value
		
		if ($validate)
		{
			
			// Set friendly name if one exists
			
			$friendlyName	= isset (static::$attributes[$name]['name'])? static::$attributes[$name]['name'] : $name;
			
			// Validate it using the parser method
			
			$this->parser->Validate ($friendlyName, static::$attributes[$name], $val);
			
		}
		
		// Set the attribute value
		
		$this->attributeValues[$name]	= $val;
		
	}
765666
private function persistDocument(Request $request, $formType, $document, $language)
    {
        $data = $request->request->all();

        if ($request->query->has('parentId')) {
            $data['parent'] = $request->query->get('parentId');
        }

        $form = $this->createForm(
            $formType,
            $document,
            [
                // disable csrf protection, since we can't produce a token, because the form is cached on the client
                'csrf_protection' => false,
                'webspace_key' => $this->getWebspace($request),
            ]
        );
        $form->submit($data, false);

        if (array_key_exists('author', $data) && null === $data['author']) {
            $document->setAuthor(null);
        }

        if (!$form->isValid()) {
            throw new InvalidFormException($form);
        }

        $this->getDocumentManager()->persist(
            $document,
            $language,
            [
                'user' => $this->getUser()->getId(),
                'clear_missing_content' => false,
            ]
        );
    }
838214
public function getWorkflow($name, $validate = true)
    {
        $useCacheTxt = $this->getProperties()->getProperty(self::CACHE, 'false');
        $useCache = false;
        if ('true' === $useCacheTxt) {
            $useCache = true;
        }

        if ($useCache && array_key_exists($name, $this->cache)) {
            $descriptor = $this->cache[$name];
            return $descriptor;
        }

        try {
            $uri = $this->uriFactory($name);
            $descriptor = WorkflowLoader::load($uri);

            if ($useCache) {
                $this->cache[$name] = $descriptor;
            }
        } catch (\Exception $e) {
            $errMsg = sprintf('Ошибка при загрузке workflow: %s', $name);
            throw new FactoryException($errMsg, $e->getCode(), $e);
        }

        return $descriptor;
    }
337540
public function store($check=true)
	{
		// Validate data?
		if ($check)
		{
			// Is data valid?
			if (!$this->check())
			{
				return false;
			}

			if ($this->_context)
			{
				$results = \Event::trigger('content.onContentBeforeSave', array(
					$this->_context,
					&$this,
					$this->exists()
				));
				foreach ($results as $result)
				{
					if ($result === false)
					{
						$this->setError(\App::get('language')->txt('Content failed validation.'));
						return false;
					}
				}
			}
		}

		// Attempt to store data
		if (!$this->_tbl->store())
		{
			$this->setError($this->_tbl->getError());
			return false;
		}

		return true;
	}