Insert developer user

@return  int|null
483842
protected function insertDeveloper()
    {
        $data   = $this->getPatchData();
        $create = $data->get(
            'gridguyz-core',
            'developer',
            'Do you want to create a developer user? (y/n)',
            'n',
            array( 'y', 'n', 'yes', 'no', 't', 'f', 'true', 'false', '1', '0' )
        );

        if ( in_array( strtolower( $create ),
             array( 'n', 'no', 'f', 'false', '0', '' ) ) )
        {
            return null;
        }

        $email = $data->get(
            'gridguyz-core',
            'developer-email',
            'Type the developer\'s email (must be valid email)',
            null,
            '/^[A-Z0-9\._%\+-]+@[A-Z0-9\.-]+\.[A-Z]{2,4}$/i',
            3
        );

        $displayName = $data->get(
            'gridguyz-core',
            'developer-displayName',
            'Type the developer\'s display name',
            strstr( $email, '@', true )
        );

        $password = $data->get(
            'gridguyz-core',
            'developer-password',
            'Type the developer\'s password',
            $this->createPasswordSalt( 6 ),
            true
        );

        return $this->insertIntoTable(
            'user',
            array(
                'email'         => $email,
                'displayName'   => $displayName,
                'passwordHash'  => $this->createPasswordHash( $password ),
                'groupId'       => static::DEVELOPER_GROUP,
                'state'         => 'active',
                'confirmed'     => 't',
                'locale'        => 'en',
            ),
            true
        );
    }
1366239
public function insert($userRoleLinker, $tableName = null, HydratorInterface $hydrator = null)
    {
        $this->checkEntity($userRoleLinker);

        return parent::insert($userRoleLinker);
    }
503698
protected function insert_id()
    {
        $query = $this->database->getQueryCollection()->findQuery($this->strQuery);

        if ($query) {
            return $query->result()->getRow($query->result()->count());
        }

        return null;
    }
1130589
protected function doInsert()
    {
        /**
         * Run pre-INSERT logic
         */
        $this->beforeInsert();

        $data = $this->toArray();
        /**
         * Execute validator logic
         * Can throw ValidatorException
         */
        $this->assert($data);

        $table = $this->getTable();

        /**
         * Execute the INSERT (this may throw an exception)
         */
        $primaryKey = $table::insert($data);

        /**
         * Normalize the result to an array indexed by primary key column(s)
         */
        $tempPrimaryKey = $table->getPrimaryKey();
        $newPrimaryKey = [current($tempPrimaryKey) => $primaryKey];

        /**
         * Save the new primary key value in object. The primary key may have
         * been generated by a sequence or auto-increment mechanism, and this
         * merge should be done before the afterInsert() method is run, so the
         * new values are available for logging, etc.
         */
        $this->setFromArray($newPrimaryKey);

        /**
         * Run post-INSERT logic
         */
        $this->afterInsert();

        /**
         * Update the "clean" to reflect that the data has been inserted.
         */
        $this->clean = $this->toArray();

        return $newPrimaryKey;
    }
493323
protected function insertService()
    {
        $data = $this->package->getResourceFromZip('system/service.json');
        $services = $this->cleanDuplicates($data, 'system', 'service');

        if (!empty($services)) {
            try {
                foreach ($services as $i => $service) {
                    unset($service['id']);
                    unset($service['last_modified_by_id']);
                    $service['created_by_id'] = Session::getCurrentUserId();
                    if (!empty($oldRoleId = array_get($service, 'config.default_role'))) {
                        $newRoleId = $this->getNewRoleId($oldRoleId);
                        if (!empty($newRoleId)) {
                            array_set($service, 'config.default_role', $newRoleId);
                        } else {
                            // If no new role found then do not store config. default_role field is not nullable.
                            $this->log(
                                'warning',
                                'Skipping config for service ' .
                                $service['name'] .
                                '. Default role not found by role id ' .
                                $oldRoleId
                            );
                            \Log::debug('Skipped service.', $service);
                            unset($service['config']);
                        }
                    }
                    if (!empty($oldDoc = array_get($service, 'doc'))) {
                        $service['service_doc_by_service_id'] = $oldDoc;
                        unset($service['doc']);
                    }
                    $services[$i] = $service;
                }

                $payload = ResourcesWrapper::wrapResources($services);
                $result = ServiceManager::handleRequest(
                    'system', Verbs::POST, 'service', [], [], $payload, null, true, true
                );
                if ($result->getStatusCode() >= 300) {
                    throw ResponseFactory::createExceptionFromResponse($result);
                }

                return true;
            } catch (\Exception $e) {
//                if ($e->getCode() === HttpStatusCodes::HTTP_FORBIDDEN) {
//                    $this->log('error', "Failed to insert services. " . $this->getErrorDetails($e));
//                } else {
//                    throw new InternalServerErrorException("Failed to insert services. " . $this->getErrorDetails($e));
//                }
                $this->throwExceptions($e, 'Failed to insert services');
            }
        }

        return false;
    }
786101
public function create()
    {
        $transaction = $this->getDb()->beginTransaction();

        try {
            $event = $this->getCreateUserEvent($this);
            $this->trigger(self::BEFORE_CREATE, $event);

            $this->setPassword($this->plainPassword);
            $this->generateAuthKey();

            if (!$this->save()) {
                $transaction->rollBack();

                return null;
            }

            $this->trigger(self::AFTER_CREATE, $event);

            $transaction->commit();

            return $this;
        } catch (\Exception $e) {
            $transaction->rollBack();
            Yii::warning($e->getMessage());
            throw $e;
        }
    }
1091931
function insert() {
		if (isset($this->document['_id']))
			return $this->update();
		if (isset($this->trigger['beforeinsert']) &&
			\Base::instance()->call($this->trigger['beforeinsert'],
				[$this,['_id'=>$this->document['_id']]])===FALSE)
			return $this->document;
		if ($this->legacy) {
			$this->collection->insert($this->document);
			$pkey=['_id'=>$this->document['_id']];
		}
		else {
			$result=$this->collection->insertone($this->document);
			$pkey=['_id'=>$result->getinsertedid()];
		}
		if (isset($this->trigger['afterinsert']))
			\Base::instance()->call($this->trigger['afterinsert'],
				[$this,$pkey]);
		$this->load($pkey);
		return $this->document;
	}
603208
protected function insert()
    {
        foreach ($this->scheduledForInsertion as $objectHashId => $entity) {
            // If this entity was a child of aggregate roots, then call its methods to set the aggregate root Id
            $this->entityRegistry->runAggregateRootCallbacks($entity);
            $className  = $this->entityRegistry->getClassName($entity);
            $dataMapper = $this->getDataMapper($className);

            $dataMapper->insert($entity);

            $this->entityRegistry->registerEntity($entity);
        }
    }
647056
private function create()
    {
        restoreRequest();
        $form = array(
            'name'=>'UserForm',
            'caption' => admUsersCreate,
            'width' => '400px',
            'fields' => array (
                array('type'=>'hidden','name'=>'action','value'=>'insert'),
                array('type'=>'edit','name'=>'name','label'=>admUsersName,'maxlength'=>32,'width'=>'100%',
                    'pattern'=>'/.+/', 'errormsg'=>admUsersNameInvalid),
                array('type'=>'edit','name'=>'login','label'=>admUsersLogin,'maxlength'=>16,'width'=>'100%',
                    'pattern'=>'/^[a-z0-9_]+$/i', 'errormsg'=>admUsersLoginInvalid),
                array('type'=>'select','name'=>'access','label'=>admAccessLevel, 'width'=>'100%',
                    'values'=>array('2','3','4'),'items'=>array(ACCESSLEVEL2,ACCESSLEVEL3,ACCESSLEVEL4),
                    'default' => USER),
                array('type'=>'checkbox','name'=>'active','label'=>admUsersAccountState, 'default' => true),
                array('type'=>'divider'),
                array('type'=>'password','name'=>'pswd1','label'=>admUsersPassword,'maxlength'=>32,
                    'width'=>'100%'),
                array('type'=>'password','name'=>'pswd2','label'=>admUsersConfirmation,'maxlength'=>32,
                    'width'=>'100%', 'equal'=>'pswd1', 'errormsg'=>admUsersConfirmInvalid),
                array('type'=>'divider'),
                array('type' => 'edit', 'name' => 'mail' , 'label' => admUsersMail,
                    'maxlength' => 32, 'width' => '100%'),
            ),
            'buttons'=>array('ok', 'cancel')
        );

        /** @var TAdminUI $page */
        $page = Eresus_Kernel::app()->getPage();
        $result = $page->renderForm($form, Eresus_CMS::getLegacyKernel()->request['arg']);
        return $result;
    }
1289173
protected function insert()
    {
        if ($this->isDirty()) {
            $sql = 'INSERT INTO '.$this->getTableName().'  SET ';
            $data = [];
            $params = [];

            $pk_name = $this->getPkName();

            foreach ((new \ReflectionObject($this))->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
                if ($this->{$property->getName()}) {
                    if ($this->{$property->getName()} instanceof Expression) {
                        $data[] = "`{$property->getName()}` = ".$this->{$property->getName()}->toSql();
                    } else {
                        $data[] = "`{$property->getName()}` = :{$property->getName()}";
                        $params[":{$property->getName()}"] = $this->{$property->getName()};
                    }
                }
            }

            $sql .= implode(',', $data);

            $stmt = $this->getDB()->prepare($sql);
            $stmt->execute($params);
            $last_insert_id = $this->getDB()->lastInsertId();

            if (is_array($pk_name)) {
                /*
                 * @TODO: Composite PK
                 */
            } else {
                $this->{$pk_name} = $last_insert_id;
            }

            $this->setDirty(false);
            $stmt->closeCursor();
            $this->_is_new = false;
        }

        return true;
    }
780301
public function _add() {
		$model = $this->model;
		$instance = new $model ();
		$this->operate_ ( $instance, function ($instance) {
			$datas = $this->getDatas ();
			$this->_setValuesToObject ( $instance, $datas );
			if ($this->_validateInstance ( $instance, $datas )) {
				return $this->AddOperation ( $instance, $datas, true );
			}
			return null;
		}, "inserted", "Unable to insert the instance", [ ] );
	}
1300716
protected function _insert()
    {
        $this->lang = \Mmi\App\FrontController::getInstance()->getRequest()->lang;
        return parent::_insert();
    }
670880
protected function _insert()
    {
        // set subscription date
        $this->oxnewssubscribed__oxsubscribed = new \OxidEsales\Eshop\Core\Field(date('Y-m-d H:i:s'), \OxidEsales\Eshop\Core\Field::T_RAW);

        return parent::_insert();
    }
273981
private function getInsertQuery()
    {
        return 'INSERT INTO '.$this->parts['from'][0]['table'].
               ' ('.implode(', ', array_keys($this->parts['set'])).')'.
               ' VALUES'.
               ' ('.implode(', ', $this->parts['set']).')';
    }
164080
protected function submitAddUser()
    {
        $this->setSubmitted(null, $this->getParam());
        $this->setSubmittedJson('data');

        $this->validateComponent('user');
        $this->addUser();
    }
462956
protected function performInsert()
    {
        if ($this->fireModelEvent('creating') === false) {
            return false;
        }

        // First we'll need to create a fresh query instance and touch the creation and
        // update timestamps on this model, which are maintained by us for developer
        // convenience. After, we will just continue saving these model instances.
        if ($this->usesTimestamps()) {
            $this->updateTimestamps();
        }

        $attributes = $this->attributes;

        if (empty($attributes)) {
            return true;
        }

        $updated = static::$client::create($attributes);

        if (array_has($updated, $keyName = $this->getKeyName())) {
            $this->setAttribute($keyName, array_get($updated, $keyName));
        }

        // We will go ahead and set the exists property to true, so that it is set when
        // the created event is fired, just in case the developer tries to update it
        // during the event. This will allow them to do so and run an update here.
        $this->exists = true;

        $this->wasRecentlyCreated = true;

        $this->fireModelEvent('created', false);

        return true;
    }
790480
private function insert(User $aUser)
    {
        $sql = 'INSERT INTO user (
            id,
            confirmation_token_token,
            confirmation_token_created_on,
            created_on,
            email,
            invitation_token_token,
            invitation_token_created_on,
            last_login,
            password,
            salt,
            remember_password_token_token,
            remember_password_token_created_on,
            roles,
            updated_on
        ) VALUES (
            :id,
            :confirmationTokenToken,
            :confirmationTokenCreatedOn,
            :createdOn,
            :email,
            :invitationTokenToken,
            :invitationTokenCreatedOn,
            :lastLogin,
            :password,
            :salt,
            :rememberPasswordTokenToken,
            :rememberPasswordTokenCreatedOn,
            :roles,
            :updatedOn
        )';
        $this->execute($sql, [
            'id'                             => $aUser->id()->id(),
            'confirmationTokenToken'         => $aUser->confirmationToken() ? $aUser->confirmationToken()->token() : null,
            'confirmationTokenCreatedOn'     => $aUser->confirmationToken() ? $aUser->confirmationToken()->createdOn() : null,
            'createdOn'                      => $aUser->createdOn()->format(self::DATE_FORMAT),
            'email'                          => $aUser->email()->email(),
            'invitationTokenToken'           => $aUser->invitationToken() ? $aUser->invitationToken()->token() : null,
            'invitationTokenCreatedOn'       => $aUser->invitationToken() ? $aUser->invitationToken()->createdOn() : null,
            'lastLogin'                      => $aUser->lastLogin() ? $aUser->lastLogin()->format(self::DATE_FORMAT) : null,
            'password'                       => $aUser->password()->encodedPassword(),
            'salt'                           => $aUser->password()->salt(),
            'rememberPasswordTokenToken'     => $aUser->rememberPasswordToken() ? $aUser->rememberPasswordToken()->token() : null,
            'rememberPasswordTokenCreatedOn' => $aUser->rememberPasswordToken() ? $aUser->rememberPasswordToken()->createdOn() : null,
            'roles'                          => $this->rolesToString($aUser->roles()),
            'updatedOn'                      => $aUser->updatedOn()->format(self::DATE_FORMAT),
        ]);
    }