create new entity in database.

@param Object  $object Object
@param Boolean $flush  Flush entity manager

@see Sonata\DoctrineORMAdminBundle\Model\ModelManager::create()
499484
public function create($object, $flush = true)
    {
        try {
            $entityManager = $this->getEntityManager($object);
            $this->preCreate($object);
            $entityManager->persist($object);
            if ($flush) {
                $entityManager->flush();
            }
            $this->postCreate($object);
        } catch (\PDOException $e) {
            throw new ModelManagerException('', 0, $e);
        }
    }
336939
public function save(
        $data,
        $locale,
        $id = null,
        $patch = false,
        $flush = true
    ) {
        $username = $this->getProperty($data, 'username');
        $contactId = $this->getProperty($data, 'contactId');
        $contact = $this->getProperty($data, 'contact');
        $email = $this->getProperty($data, 'email');
        $password = $this->getProperty($data, 'password');
        $enabled = $this->getProperty($data, 'enabled');
        $locked = $this->getProperty($data, 'locked');
        $user = null;

        try {
            if ($id) {
                // update user
                $user = $this->userRepository->findUserById($id);
                if (!$user) {
                    throw new EntityNotFoundException($this->userRepository->getClassName(), $id);
                }
                $this->processEmail($user, $email);
            } else {
                // add user
                if (!$this->isValidPassword($password)) {
                    throw new MissingPasswordException();
                }
                /** @var UserInterface $user */
                $user = $this->userRepository->createNew();
                $this->processEmail($user, $email, $contact);
            }

            // check if username is already in database and the current user is not the user with this username
            if (!$patch || null !== $username) {
                if ($user->getUsername() != $username &&
                    !$this->isUsernameUnique($username)
                ) {
                    throw new UsernameNotUniqueException($username);
                }
                $user->setUsername($username);
            }

            // check if password is valid
            if (!$patch || null !== $password) {
                if ($this->isValidPassword($password)) {
                    $user->setSalt($this->generateSalt());
                    $user->setPassword(
                        $this->encodePassword($user, $password, $user->getSalt())
                    );
                }
            }

            if (!$patch || null !== $this->getProperty($data, 'userRoles')) {
                if (!$this->processUserRoles($user, $this->getProperty($data, 'userRoles', []))) {
                    throw new \Exception('Could not update dependencies!');
                }
            }

            if (!$patch || null !== $this->getProperty($data, 'userGroups')) {
                if (!$this->processUserGroups($user, $this->getProperty($data, 'userGroups', []))) {
                    throw new \Exception('Could not update dependencies!');
                }
            }

            if (!$patch || (null !== $contact || null !== $contactId)) {
                if ($contact && !$contactId) {
                    @trigger_error(
                        'Usage of the contact object to define the contact corresponding to the user is deprecated'
                        . ' since version 1.4 and will be removed in 2.0. Use the contactId query parameter instead.',
                        E_USER_DEPRECATED
                    );
                }
                $user->setContact($this->getContact($contactId ? $contactId : $contact['id']));
            }

            if (!$patch || null !== $locale) {
                $user->setLocale($locale);
            }

            if (null !== $enabled) {
                $user->setEnabled($enabled);
            }

            if (null !== $locked) {
                $user->setLocked($locked);
            }
        } catch (\Exception $re) {
            if (isset($user)) {
                $this->em->remove($user);
            }

            throw $re;
        }

        $this->em->persist($user);
        if ($flush) {
            $this->em->flush();
        }

        return $user;
    }
317115
public function save($media, $flush = true)
    {
        if ($media->getFile() !== null) {
            if ($this->saveFile($media) === false) {
                return false;
            }
        }

        if ($media->getFocusIsEdited() === true) {
            $this->reset($media, true);
            $media->setFocusIsEdited(false);
        }

        $media->setUpdatedAt(new \Datetime());

        parent::save($media, $flush);

        return true;
    }
668505
protected function flushTransaction($object = null)
    {
        $violations = new ConstraintViolationList();

        try {
            $this->om->flush();

            if (null !== $this->connection && null === $object) {
                $this->connection->commit();
            }
        } catch (\Exception $e) {
            $this->flushTransactionException($e, $violations, $object);
        }

        return $violations;
    }
254451
public function flush($entity)
    {
        /**
         * @var ObjectManager $objectManager
         */
        $objectManager = $this
            ->get('elcodi.provider.manager')
            ->getManagerByEntityNamespace(get_class($entity));

        $objectManager->persist($entity);
        $objectManager->flush($entity);

        return $this;
    }
1302992
public function importUser($id, $flush = true)
    {
        $this->consoleOutput->writeln("Reading user #" . $id . "... ", true);

        $sql = "SELECT * FROM users WHERE users.user_id = :id " . ImportHelper::spamUsersFilterSql();
        $statement = $this->dbalConnection->prepare($sql);
        $statement->bindValue('id', $id);
        $statement->execute();

        $faker = Factory::create();
        $pkpUser = $statement->fetch();
        $user = null;

        if ($pkpUser) {
            if (!empty($pkpUser['username'])) {
                $user = $this->em->getRepository('VipaUserBundle:User')->findOneBy(['username' => $pkpUser['username']]);

                if (!$user) {
                    $user = $this->em->getRepository('VipaUserBundle:User')->findOneBy(['email' => $pkpUser['email']]);
                }
            }

            if (is_null($user)) {
                $user = new User();
                !empty($pkpUser['username']) ?
                    $user->setUsername($pkpUser['username']) :
                    $user->setUsername($faker->userName);

                !empty($pkpUser['email']) ?
                    $user->setEmail($pkpUser['email']) :
                    $user->setEmail($faker->companyEmail);

                !empty($pkpUser['disabled']) ?
                    $user->setEnabled(!$pkpUser['disabled']) :
                    $user->setEnabled(1);

                // Set a random password
                $password = mb_substr($this->tokenGenerator->generateToken(), 0, 8);
                $user->setPlainPassword($password);

                // Fields which can't be blank
                !empty($pkpUser['first_name']) ? $user->setFirstName($pkpUser['first_name']) : $user->setFirstName('Anonymous');
                !empty($pkpUser['last_name']) ? $user->setLastName($pkpUser['last_name']) : $user->setLastName('Anonymous');

                // Optional fields
                !empty($pkpUser['billing_address']) && $user->setBillingAddress($pkpUser['billing_address']);
                !empty($pkpUser['mailing_address']) && $user->setAddress($pkpUser['mailing_address']);
                !empty($pkpUser['gender']) && $user->setGender($pkpUser['gender']);
                !empty($pkpUser['phone']) && $user->setPhone($pkpUser['phone']);
                !empty($pkpUser['fax']) && $user->setFax($pkpUser['fax']);
                !empty($pkpUser['url']) && $user->setUrl($pkpUser['url']);
                
                $this->em->persist($user);

                if ($flush) {
                    $this->em->flush();
                }
            }

            return $user;
        }

        return null;
    }
485066
public function move($object, $parentObject = null) {
		$this->em->flush();
		
		if ($parentObject !== null) {
			$this->valMove($object, $parentObject);
		}
		
		$newLft = 1;
		if ($parentObject === null) {
			if (null !== ($maxRgt = $this->lookupMaxRgt($object))) {
				$newLft = $maxRgt + 1;
			}
		} else {
			$newLft = $this->lookupLftRgt($parentObject)['rgt'];
		}
		
		$this->moveToLft($object, $newLft);
	}
1144632
public function updateUserData(Data $data, $flush = true)
    {
        $this->em->persist($data);
        if($flush){
            $this->em->flush();
        }

        //return array with sf validator errors
        return new \Symfony\Component\Validator\ConstraintViolationList();
    }
94902
protected function onAfterCreate(DataObject $object, $identifier, &$data, &$fixtures)
    {
        $this->enableValidation()->invokeCallbacks('afterCreate', [$object, $identifier, $data, $fixtures]);
    }
700046
public void savePersistentObject(PersistentObject object) {
        final String type = object.getClass().getSimpleName();
        LOG.trace("Trying to create a new " + type);
        dao.saveOrUpdate(object);
        LOG.info("Created the " + type + " with id " + object.getId());
    }
1107011
private function addBulkCreateRecord($record, $objectType)
    {
        if (isset($this->bulkCreateRecords[$objectType])
            && count($this->bulkCreateRecords[$objectType]) == $this->bulkSaveLimit) {
            $this->flushCreates($objectType);
        }

        $this->bulkCreateRecords[$objectType][] = $record;
    }
199911
public function save($entity, $flush = true)
    {
        $this->getEntityManager()->persist($entity);

        if ($flush) {
            $this->getEntityManager()->flush($entity);
        }
        return $this;
    }
998653
private function getEntityOnFlush($entity, $flushEntity)
    {
        if (ClassUtils::getClass($entity) == ClassUtils::getClass($flushEntity) && $entity->getId() === $flushEntity->getId()) {
            return $flushEntity;
        } else {
            return $entity;
        }
    }
626272
public function remove($object, $flushed = true)
    {
        $this->preRemove($object, $flushed);
        $em = $this->getEntityManager();
        $em->remove($object);
        if ($flushed) {
            $em->flush($object);
        }
        $this->postRemove($object, $flushed);
        return $object;
    }
1097412
public function save($object, $flush = true)
    {
        $this->isExpectedObject($object);
        $this->objectManager->persist($object);
        if ($flush) {
            $this->flush();
        }
    }
666908
function create($txn = true) {
		if ($txn && !($txn instanceof pq\Transaction)) {
			$txn = $this->table->getConnection()->startTransaction();
		}
		try {
			foreach ($this->rows as $row) {
				$row->create();
			}
		} catch (\Exception $e) {
			if ($txn) {
				$txn->rollback();
			}
			throw $e;
		}
		if ($txn) {
			$txn->commit();
		}
		return $this;
	}
84164
public function update($object)
    {
        if ($this->isNewObject($object)) {
            throw new UnknownObjectException('The object of type "' . get_class($object) . '" (identifier: "' . $this->getIdentifierByObject($object) . '") which was passed to EntityManager->update() is not a previously persisted object. Check the code which updates this entity and make sure that only objects are updated which were persisted before. Alternatively use add() for persisting new objects."', 1313663277);
        }
        try {
            $this->entityManager->persist($object);
        } catch (\Exception $exception) {
            throw new PersistenceException('Could not merge object of type "' . get_class($object) . '"', 1297778180, $exception);
        }
    }