<commit_before><?php
class ContentController extends CController
{
    /**
     * @return array
     */
    public function actions()
    {
        return array(
            'wsdl' => array(
                'class' => 'CWebServiceAction',
                'classMap' => array(
                    'Status' => 'Status',
                    'StatusCode' => 'StatusCode',
                    'RegisterResult' => 'RegisterResult',
                    'LicenceDTO' => 'LicenceDTO',
                    'CollectionDTO' => 'CollectionDTO',
                    'MediaDTO' => 'MediaDTO',
                    'AssignMediaDTO' => 'AssignMediaDTO'
                ),
            ),
        );
    }


    /**
     * @param InstitutionDTO $institutionDto
     * @return RegisterResult
     * @soap
     */
    public function register($institutionDto)
    {
        $user = new InstallConfigurationForm();
        $transaction = $user->dbConnection->beginTransaction();
        $message = "";
        try {
            $user->username = $institutionDto->username;
            $user->email = $institutionDto->email;
            $user->password = $<PASSWORD>;
            $user->activekey = UserModule::encrypting(microtime() . $user->password);
            $user->verifyPassword = $user->password = UserModule::encrypting($user->password);
            $user->created = date('Y-m-d H:i:s');
            $user->modified = date('Y-m-d H:i:s');
            $user->lastvisit = NULL;
            $user->role = 'institution';
            $user->status = User::STATUS_NOACTIVE;

            if ($user->save()) {
                $institution = new Institution();
                $institution->name = $institutionDto->name;
                $institution->url = $institutionDto->url;
                $institution->logo_url = $institutionDto->logoUrl;
                $institution->description = $institutionDto->description;
                $institution->status = Institution::STATUS_NOACTIVE;
                $institution->user_id = $user->id;
                $institution->token = md5($institution->name . "_" . $institution->url);
                $institution->created = date('Y-m-d H:i:s');

                if ($institution->save()) {
                    $transaction->commit();
                    $res = new RegisterResult();
                    $res->token = $institution->token;
                    $res->status = Status::getStatus(StatusCode::SUCCESS(), "");
                    return $res;
                }

                $errors = $institution->getErrors();
                foreach ($errors as $field => $error) {
                    $message .= $error[0] . ";";
                }
            } else {
                $errors = $user->getErrors();
                foreach ($errors as $field => $error) {
                    $message .= $error[0] . ";";
                }
            }

            $transaction->rollback();
            $rr = new RegisterResult();
            $rr->status = Status::getStatus(StatusCode::ILLEGAL_ARGUMENT(), $message);
            return $rr;
        } catch (Exception $ex) {
            $transaction->rollback();
            $res = new RegisterResult();
            $res->status = Status::getStatus(StatusCode::FATAL_ERROR(), $ex->getMessage());
            return $res;
        }
    }

    /**
     * @param InstitutionDTO $institutionDto
     * @return RegisterResult
     * @soap
     */
    public function updateProfile($institutionDto)
    {
        $message = "";
        try {
            $institution = Institution::model()->find('token=:token',array(':token'=>$institutionDto->token));
            if($institution){
                $institution->name = $institutionDto->name;
                $institution->url = $institutionDto->url;
                $institution->logo_url = $institutionDto->logoUrl;
                $institution->description = $institutionDto->description;
                $institution->token = md5($institution->name . "_" . $institution->url);
                if ($institution->save()) {
                    $res = new RegisterResult();
                    $res->token = $institution->token;
                    $res->status = Status::getStatus(StatusCode::SUCCESS(), "");
                    return $res;
                }

                $errors = $institution->getErrors();
                foreach ($errors as $field => $error) {
                    $message .= $error[0] . ";";
                }

                $rr = new RegisterResult();
                $rr->status = Status::getStatus(StatusCode::ILLEGAL_ARGUMENT(), $message);
                return $rr;
            }else{
                $res = new RegisterResult();
                $res->status = Status::getStatus(StatusCode::FATAL_ERROR(), "Invalid token!");
                return $res;
            }
        } catch (Exception $ex) {
            $res = new RegisterResult();
            $res->status = Status::getStatus(StatusCode::FATAL_ERROR(), $ex->getMessage());
            return $res;
        }
    }


    /**
     * @param string $token
     * @param CollectionDTO $collection
     * @return Status
     * @soap
     */
    public function createCollection($token, $collection)
    {
        try {
            $institution = $this->getInstitution($token);<commit_msg>MDG-102 mgg: edit profile of Institution user results in PHP error it was missed to create record in profile model<commit_after><?php
class ContentController extends CController
{
    /**
     * @return array
     */
    public function actions()
    {
        return array(
            'wsdl' => array(
                'class' => 'CWebServiceAction',
                'classMap' => array(
                    'Status' => 'Status',
                    'StatusCode' => 'StatusCode',
                    'RegisterResult' => 'RegisterResult',
                    'LicenceDTO' => 'LicenceDTO',
                    'CollectionDTO' => 'CollectionDTO',
                    'MediaDTO' => 'MediaDTO',
                    'AssignMediaDTO' => 'AssignMediaDTO'
                ),
            ),
        );
    }


    /**
     * @param InstitutionDTO $institutionDto
     * @return RegisterResult
     * @soap
     */
    public function register($institutionDto)
    {
        $user = new InstallConfigurationForm();
        $transaction = $user->dbConnection->beginTransaction();
        $message = "";
        try {
            $user->username = $institutionDto->username;
            $user->email = $institutionDto->email;
            $user->password = $institutionDto->password;
            $user->activekey = UserModule::encrypting(microtime() . $user->password);
            $user->verifyPassword = $user->password = UserModule::encrypting($user->password);
            $user->created = date('Y-m-d H:i:s');
            $user->modified = date('Y-m-d H:i:s');
            $user->lastvisit = NULL;
            $user->role = 'institution';
            $user->status = User::STATUS_NOACTIVE;

            if ($user->save()) {
                $profile = new Profile;
                $profile->user_id = $user->id;
                $profile->save();

                $institution = new Institution();
                $institution->name = $institutionDto->name;
                $institution->url = $institutionDto->url;
                $institution->logo_url = $institutionDto->logoUrl;
                $institution->description = $institutionDto->description;
                $institution->status = Institution::STATUS_NOACTIVE;
                $institution->user_id = $user->id;
                $institution->token = md5($institution->name . "_" . $institution->url);
                $institution->created = date('Y-m-d H:i:s');

                if ($institution->save()) {
                    $transaction->commit();
                    $res = new RegisterResult();
                    $res->token = $institution->token;
                    $res->status = Status::getStatus(StatusCode::SUCCESS(), "");
                    return $res;
                }

                $errors = $institution->getErrors();
                foreach ($errors as $field => $error) {
                    $message .= $error[0] . ";";
                }
            } else {
                $errors = $user->getErrors();
                foreach ($errors as $field => $error) {
                    $message .= $error[0] . ";";
                }
            }

            $transaction->rollback();
            $rr = new RegisterResult();
            $rr->status = Status::getStatus(StatusCode::ILLEGAL_ARGUMENT(), $message);
            return $rr;
        } catch (Exception $ex) {
            $transaction->rollback();
            $res = new RegisterResult();
            $res->status = Status::getStatus(StatusCode::FATAL_ERROR(), $ex->getMessage());
            return $res;
        }
    }

    /**
     * @param InstitutionDTO $institutionDto
     * @return RegisterResult
     * @soap
     */
    public function updateProfile($institutionDto)
    {
        $message = "";
        try {
            $institution = Institution::model()->find('token=:token', array(':token' => $institutionDto->token));
            if ($institution) {
                $institution->name = $institutionDto->name;
                $institution->url = $institutionDto->url;
                $institution->logo_url = $institutionDto->logoUrl;
                $institution->description = $institutionDto->description;
                $institution->token = md5($institution->name . "_" . $institution->url);
                if ($institution->save()) {
                    $res = new RegisterResult();
                    $res->token = $institution->token;
                    $res->status = Status::getStatus(StatusCode::SUCCESS(), "");
                    return $res;
                }

                $errors = $institution->getErrors();
                foreach ($errors as $field => $error) {
                    $message .= $error[0] . ";";
                }

                $rr = new RegisterResult();
                $rr->status = Status::getStatus(StatusCode::ILLEGAL_ARGUMENT(), $message);
                return $rr;
            } else {
                $res = new RegisterResult();
                $res->status = Status::getStatus(StatusCode::FATAL_ERROR(), "Invalid token!");
                return $res;
            }
        } catch (Exception $ex) {
            $res = new RegisterResult();
            $res->status = Status::getStatus(StatusCode::FATAL_ERROR(), $ex->getMessage());
            return $res;
        }
    }


    /**
     * @param string $token
     * @param CollectionDTO $collection
     * @return Status
     * @soap
     */
    public function createCollection($token, $collection)
    {
        try {
            $institution = $this->getInstitution($token);
{'fraction_non_alphanumeric': 0.14384572799409484, 'fraction_numerical': 0.0011994832995017531, 'mean_word_length': 1.59492458702418, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 172, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4041612', 'n_tokens_mistral': 2839, 'n_tokens_neox': 2761, 'n_words': 501}