public function create(UserAccountModel $user, UserAccountEditMetaDataModel $userAccountEditMetaDataModel = null) { global $DB, $CONFIG, $EXTENSIONHOOKRUNNER; // TODO should check email and username not already exist and nice error $stat = $DB->prepare("INSERT INTO user_account_information (username, username_canonical, email, email_canonical, password_hash, created_at, is_editor, created_from_ip) " . "VALUES (:username, :username_canonical, :email, :email_canonical, :password_hash, :created_at, :is_editor, :created_from_ip) RETURNING id"); $stat->execute(array('username' => substr($user->getUsername(), 0, VARCHAR_COLUMN_LENGTH_USED), 'username_canonical' => substr(UserAccountModel::makeCanonicalUserName($user->getUsername()), 0, VARCHAR_COLUMN_LENGTH_USED), 'email' => substr($user->getEmail(), 0, VARCHAR_COLUMN_LENGTH_USED), 'email_canonical' => substr(UserAccountModel::makeCanonicalEmail($user->getEmail()), 0, VARCHAR_COLUMN_LENGTH_USED), 'password_hash' => $user->getPasswordHash(), 'created_at' => \TimeSource::getFormattedForDataBase(), 'is_editor' => $CONFIG->newUsersAreEditors ? 1 : 0, 'created_from_ip' => $userAccountEditMetaDataModel ? $userAccountEditMetaDataModel->getIp() : null)); $data = $stat->fetch(); $user->setId($data['id']); $EXTENSIONHOOKRUNNER->afterUserAccountCreate($user); }