Persist data to the database.

@param CampusUnion\Sked\SkeVent $skeVent Passed by reference.
@return int|bool Success/failure.
350277
public function save(SkeVent &$skeVent)
    {
        $mReturn = false;

        // Validate
        if ($this->validateEvent($skeVent)) {
            $aValues = $skeVent->toArray(false);
            unset($aValues['lead_time_num'], $aValues['lead_time_unit']);

            // Run transaction
            $this->beginTransaction();
            try {
                $mReturn = $this->saveEvent($aValues);
                $this->saveEventTags($mReturn, $skeVent->getTags());
                $this->saveEventMembers($mReturn, $skeVent->getMembers());
            } catch (\Exception $e) {
                $mReturn = false;
                $skeVent->addError(2, $e->getMessage());
            }
            $this->endTransaction((bool)$mReturn);
        }

        return $mReturn;
    }
451021
protected function saveEventMembers(int $iEventId, array $aMembers)
    {
        if (!empty($aMembers)) {
            $aExecParams[':sked_event_id'] = $iEventId;
            $strQuery = 'INSERT IGNORE INTO `sked_event_members`
                (`sked_event_id`, `member_id`, `owner`, `lead_time`, `created_at`) VALUES ';

            $aValueSets = [];
            foreach ($aMembers as $iMemberId => $aSettings) {
                $strMemberParam = ':member_id_' . $iMemberId;
                $strOwnerParam = ':owner_' . $iMemberId;
                $strLeadTimeParam = ':lead_time_' . $iMemberId;
                $aValueSets[] = '(:sked_event_id, ' . $strMemberParam . ', '
                    . $strOwnerParam . ', ' . $strLeadTimeParam . ', NOW())';
                $aExecParams[$strMemberParam] = $iMemberId;
                $aExecParams[$strOwnerParam] = $aSettings['owner'] ?? 0;
                $aExecParams[$strLeadTimeParam] = $aSettings['lead_time'] ?? 0;
            }

            $strQuery .= implode(',', $aValueSets) . ' ON DUPLICATE KEY UPDATE'
                . ' `owner` = VALUES(`owner`), `lead_time` = VALUES(`lead_time`)';

            $this->queryPDO($strQuery, $aExecParams);
        }

        return true;
    }
1317040
public function afterCommit(TransactionEvent $event) {
    if ($event->getPhase() == TransactionEvent::AFTER_COMMIT) {
      $changedOids = $event->getInsertedOids();
      $this->updateCopyOIDs($changedOids);
    }
  }
1102739
public function handlePersist(PersistEvent $event)
    {
        $document = $event->getDocument();

        if (false == $document instanceof OrderBehavior) {
            return;
        }

        if ($document->getSuluOrder()) {
            return;
        }

        $node = $event->getNode();
        $parent = $node->getParent();
        $nodeCount = count($parent->getNodes());
        $order = ($nodeCount + 1) * 10;

        $document->setSuluOrder($order);
    }
58642
public function save($sKey, $obCollection)
    {
        if (empty($sKey)) {
            return;
        }

        $this->arStore[$sKey] = $obCollection->copy();
    }
169462
public function save() : bool
    {
        if (!$this->isTableNameSet()) {
            return false;
        }
        $pkName = $this->primaryKey;
        if ((int) $this->$pkName > 0) {
            $this->updateEntry();
        } else {
            $this->createEntry();
        }
        return true;
    }
943935
public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options)
    {
        if (!$this->config('status')) {
            return true;
        }

        // as we don't know entity's ID on beforeSave, we must delay values storage;
        // all this occurs inside a transaction so we are safe
        if (!empty($this->_cache['createValues'])) {
            foreach ($this->_cache['createValues'] as $valueEntity) {
                $valueEntity->set('entity_id', $this->_toolbox->getEntityId($entity));
                $valueEntity->unsetProperty('id');
                TableRegistry::get('Eav.EavValues')->save($valueEntity);
            }
            $this->_cache['createValues'] = [];
        }

        foreach ($this->_attributesForEntity($entity) as $attr) {
            $field = $this->_prepareMockField($entity, $attr);
            $field->afterSave();
        }

        if ($this->config('cacheMap')) {
            $this->updateEavCache($entity);
        }

        return true;
    }
1296253
public function save(AbstractDbEntity $dbEntity)
    {
        if ($dbEntity->shouldBeDeletedFromDbOnSave()) {
            // Only delete if previously saved to db
            if ($dbEntity->getPrimaryDbValue()) {
                $this->delete($dbEntity);
            }

            return false;
        }

        if ($dbEntity->shouldInsertOnDbSave()) {
            // Note that database data always contains all properties,
            // with defaults for non set properties
            $dataToSave = $dbEntity->getDbData();
        } else {
            if ($dbEntity->hasModifiedDbProperties()) {
                $dataToSave = $dbEntity->getModifiedDbData();
            } else {
                // Return if no value has been modified and it's not an insert
                // (we always want to insert if no id exist, since some child objects might
                // depend on the this primary id being available)
                return false;
            }
        }

        // Check data
        $sqlData = [];
        foreach ($dataToSave as $propertyName => $value) {
            if (!empty($value) && is_scalar($value)
                && $dbEntity->getDbPropertyMaxLength($propertyName)
                && mb_strlen($value) > $dbEntity->getDbPropertyMaxLength($propertyName)
            ) {
                throw new \RuntimeException(
                    "Database field \"{$propertyName}\" exceeds field max length (value: \"{$value}\")"
                );
            } elseif (empty($value) && $dbEntity->getDbPropertyNonEmpty($propertyName)) {
                throw new \RuntimeException("Database field \"{$propertyName}\" is empty and required");
            } elseif (((is_scalar($value) && ((string) $value) === '') || (!is_scalar($value) && empty($value)))
                && $dbEntity->getDbPropertyRequired($propertyName)
            ) {
                throw new \RuntimeException("Database field \"{$propertyName}\" is required to be set");
            }

            // Set data keys db field format
            $fieldName = $dbEntity->getDbFieldName($propertyName);
            $sqlData[$fieldName] = $value;
        }


        // Insert new database row
        if ($dbEntity->shouldInsertOnDbSave()) {
            $this->db->insert(
                $dbEntity->getDbTableName(),
                $sqlData
            );

            // Update entity with auto increment value
            if (!is_array($dbEntity->getPrimaryDbPropertyKey())
                && !empty($lastInsertId = $this->db->getLastInsertId())
            ) {
                $dbEntity->setPrimaryDbValue($lastInsertId);
            } else {
                // For entities with for example string primary keys, we update primary value
                // with value/values from db data, indicating that the entity is now
                // in database/loaded.
                $dbEntity->updatePrimaryDbValueFromDbData();
            }
        // Update existing database row
        } else {
            $this->db->update(
                $dbEntity->getDbTableName(),
                $sqlData,
                $this->getPrimaryKeyWhereSql($dbEntity),
                $this->getPrimaryKeyWhereParameters($dbEntity)
            );
        }

        $dbEntity->clearModifiedDbProperties();
        $dbEntity->setForceDbInsertOnSave(false);

        return true;
    }
975907
public function storeInsert($force = false)
    {
        // update table if needed
        static::applySchema();

        // collect field names for sql query
        $fieldsArray = [];

        // collect values for sql query
        $valuesArray = [];

        // collect tokens value for pdo parametric
        $tokensArray = [];

        // get primary field name
        $key = static::getPrimaryKey();

        // get complete fields schema
        $schema = static::getSchema();

        //
        foreach ($schema as $field => &$column) {
            if (($field == $key || is_null($this->{$field})) && !$force) {
                continue;
            }
            // get current value of attribute of object
            $value = static::insertRelationBefore($this->{$field}, $column);
            $token = ':'.$field;
            $fieldsArray[] = '`'.$field.'`';
            $valuesArray[] = $token;
            $tokensArray[$token] = $value;
        }

        //
        $fields = implode(',', $fieldsArray);

        //
        $values = implode(',', $valuesArray);

        //
        $table = static::getTable();

        //
        $sql = "INSERT INTO {$table} ({$fields}) VALUES ({$values})";

        //
        static::getDatabase()->execute($sql, $tokensArray);

        //
        foreach ($schema as $field => &$column) {
            if (!$force && $field == $key) {
                continue;
            }

            static::insertRelationAfter($this->{$field}, $column);
        }

        //
        if ($key) {
            $index = static::getDatabase()->getLastId();
            $this->{$key} = $index;
        } else {
            $index = static::getMainFieldValue();
        }

        //
        return $index;
    }
791681
private function persist()
    {
        $sessionBag = $this->session->getBag($this->getSessionBagKey());
        $sessionBag->set($this->getScope(), $this->filterAttributes());

        $databaseSessionBag = $this->session->getBag($this->getDatabaseSessionBagKey());
        $databaseSessionBag->set($this->getScope(), $this->filterAttributes(true));
    }
33024
public function persist(EntityInterface $entity)
    {
        $reflection = $this->getEntityClassReflection();
        
        if ($reflection->isInstance($entity)) {
            
            $this->dispatchEvent(ORMEvents::beforePersist, new EntityLifecycleEvent($this, $entity));
            
            $connection = $this->getConnection();
            $metadata = $this->getEntityMetadata();
            $isEntityNew = $this->isNewEntity($entity);
            $entityData = $this->getEntityDataArray($entity);
            
            $persister = $this->getPersisterForEntity($entity);
            $persister->setDataBatch($entityData);
            
            $propertyIdentifier = $metadata->getName($metadata->getIdentifier(), Metadata::CAMILIZED);
            
            if (!$isEntityNew && $reflection->hasProperty($propertyIdentifier)) {
                $persister->addConditions($metadata->getIdentifier(), $entity->getByProperty($propertyIdentifier));
            }
            
            $connection->start();
            $connection->execute($persister->toSQL());
            
            if ($reflection->hasProperty($propertyIdentifier) && $isEntityNew) {
                $reflection->getProperty($propertyIdentifier)->setValue($entity, $connection->lastInsertId());
            }
            
            $this->dispatchEvent(ORMEvents::afterPersist, new EntityLifecycleEvent($this, $entity));
            
            // commit changes after event dispatching
            $connection->commit();
            
            return $this;
        }
        
        throw new NotSupportedException(sprintf('Unable to persist entity! Actual entity "%s" expected entity "%s"',
            get_class($entity), $this->getEntityName()));
    }
956474
public function saveEntity(EntityEvent $event)
    {
        $admin = $event->getAdmin();
        $configuration = $admin->getConfiguration();

        // Save the entity changes using the configured data provider
        $dataProvider = $this
            ->dataProviderFactory
            ->get($configuration->getParameter('data_provider'))
        ;
        $dataProvider->save($admin);

        // Inform the user that the save is successful
        $message = $this->translateMessage('save_success', $admin->getName(), $configuration);

        $this
            ->session
            ->getFlashBag()
            ->add('success', $message)
        ;
    }
1024738
def persist(self, key):
        """"""
        fut = self.execute(b'PERSIST', key)
        return wait_convert(fut, bool)
1163580
public function commit(): bool {
        if ($this->transactionExists) {
            $commited = $this->pdo->commit();
            $this->transactionExists = !$commited;
            return $commited;
        }
        return false;
    }
713804
public function saved($sKey)
    {
        if (empty($sKey)) {
            return null;
        }

        $sKey = static::class.'@'.$sKey;

        $obCollection = CollectionStore::instance()->saved($sKey);
        if (empty($obCollection)) {
            return null;
        }

        return $obCollection;
    }
178508
public function afterCreate(PersistenceEvent $event) {
    if ($event->getAction() == PersistenceAction::CREATE) {
      $oldOid = $event->getOldOid();
      $oldOidStr = $oldOid != null ? $oldOid->__toString() : null;
      if ($oldOidStr != null && isset($this->createdTranslations[$oldOidStr])) {
        foreach ($this->createdTranslations[$oldOidStr] as $translation) {
          $translation->setValue('objectid', $event->getObject()->getOID()->__toString());
        }
      }
    }
  }
1087405
public function persist()
    {
        if (!$this->wasModified()) {
            return false;
        }

        foreach ($this->getModifiedData() as $id=>$data) {
            $this->writeToDB($id, $data);
        }

        if ($unsettedKeys = $this->getUnsettedKeys()) {
            $this->deleteFromDB($unsettedKeys);
        }

        $this->_originalAttributes = $this->_attributes;

        return true;
    }