humhub / humhub

HumHub is an Open Source Enterprise Social Network. Easy to install, intuitive to use and extendable with countless freely available modules.
https://www.humhub.com
Other
6.33k stars 1.66k forks source link

Error while trying to change some User Profile fields #1017

Closed g0dkar closed 9 years ago

g0dkar commented 9 years ago

Hi!

I just learned about HumHub, installed it and it is AMAZING! Truly wonderful! The only problem I've had so far is that I can't change any of the default User Profile fields. I get this error whenever I try to change some info on the default User Profile fields.

I'm trying to hide some of them, and change the name of a few.

[From the "Admin -> Logging" page, formatted by me]
Trying to get property of non-object (/home/ubuntu/humhub-master/protected/modules_core/admin/controllers/UserprofileController.php:169)
Stack trace:
#0 /home/ubuntu/humhub-master/protected/vendors/yii/web/filters/CFilterChain.php(133): UserProfileController->runAction()
#1 /home/ubuntu/humhub-master/protected/vendors/yii/web/filters/CFilter.php(40): CFilterChain->run()
#2 /home/ubuntu/humhub-master/protected/vendors/yii/web/CController.php(1145): CAccessControlFilter->filter()
#3 /home/ubuntu/humhub-master/protected/vendors/yii/web/filters/CInlineFilter.php(58): UserProfileController->filterAccessControl()
#4 /home/ubuntu/humhub-master/protected/vendors/yii/web/filters/CFilterChain.php(130): CInlineFilter->filter()
#5 /home/ubuntu/humhub-master/protected/vendors/yii/web/CController.php(291): CFilterChain->run()
#6 /home/ubuntu/humhub-master/protected/vendors/yii/web/CController.php(265): UserProfileController->runActionWithFilters()
#7 /home/ubuntu/humhub-master/protected/vendors/yii/web/CWebApplication.php(282): UserProfileController->run()
#8 /home/ubuntu/humhub-master/protected/vendors/yii/web/CWebApplication.php(141): WebApplication->runController()
#9 /home/ubuntu/humhub-master/protected/vendors/yii/base/CApplication.php(180): WebApplication->processRequest()
#10 /home/ubuntu/humhub-master/index.php(39): WebApplication->run()

REQUEST_URI=/admin/userprofile/editField/id/4 in /home/ubuntu/humhub-master/protected/modules_core/admin/controllers/UserprofileController.php (169) in /home/ubuntu/humhub-master/index.php (39)

I wish I could help more, but since I just started using it (and I'm really rusty on PHP) I'm afraid I can't =/

evanlihou commented 9 years ago

What's the current status of this bug being fixed?

WASasquatch commented 9 years ago

The pull request should be reverted by HumHub developers since it appears the pull author has abandoned it.

@luke- @andystrobel

esemve commented 9 years ago

Hotfix (but i'm not a HumHub developer). Change actionEditField and getTypeInstances functions to:

UserProfileController.php

  public function actionEditField() {

        // XSS Protection
        $_POST = Yii::app()->input->stripClean($_POST);

        $id = (int) Yii::app()->request->getQuery('id');

        // Get Base Field
        $field = ProfileField::model()->findByPk($id);
        if ($field == null)
            $field = new ProfileField;

        // Get all Available Field Class Instances, also bind current profilefield to the type
        $profileFieldTypes = new ProfileFieldType();
        $fieldTypes = $profileFieldTypes->getTypeInstances();
        // Build Form Definition
        $definition = array();

        #$definition['activeForm'] = array(
        #    'class' => 'CActiveForm',
        #    'enableAjaxValidation' => true,
        #    'id' => 'login-form',
        #);

        $definition['elements'] = array();

        // Add all sub forms
        $definition['elements'] = array_merge($definition['elements'], $field->getFormDefinition());
        foreach ($fieldTypes as $fieldType) {
            $definition['elements'] = array_merge($definition['elements'], $fieldType->getFormDefinition());
        }

        // Add Form Buttons
        $definition['buttons'] = array(
            'save' => array(
                'type' => 'submit',
                'label' => Yii::t('AdminModule.controllers_UserprofileController', 'Save'),
                'class' => 'btn btn-primary'
            ),
        );

        if (!$field->isNewRecord && !$field->is_system) {
            $definition['buttons']['delete'] = array(
                'type' => 'submit',
                'label' => Yii::t('AdminModule.controllers_UserprofileController', 'Delete'),
                'class' => 'btn btn-danger pull-right'
            );
        }

        // Create Form Instance
        $form = new HForm($definition);

        // Add used models to the CForm, so we can validate it
        $form['ProfileField']->model = $field;
        foreach ($fieldTypes as $fieldType) {
            $form[get_class($fieldType)]->model = $fieldType;
        }

        // Form Submitted?
        if ($form->submitted('save') && $form->validate()) {

            $this->forcePostRequest();

            // Use ProfileField Instance from Form with new Values
            $field = $form['ProfileField']->model;
            $fieldType = $form[$field->field_type_class]->model;
            $fieldType->setProfileField($field);

            $field->save();
            $fieldType->save();

            $this->redirect(Yii::app()->createUrl('//admin/userprofile'));
        }

        if ($form->submitted('delete')) {
            $this->forcePostRequest();
            $field->delete();
            $this->redirect(Yii::app()->createUrl('//admin/userprofile'));
        }

        $this->render('editField', array('form' => $form, 'field' => $field));
    }

ProfileFieldType.php

    /**
     * Returns an array of instances of all available field types.
     *
     * @return Array
     */
    public function getTypeInstances($profileField = null) {

        $types = array();
        foreach ($this->getFieldTypes() as $className => $title) {

            if (Helpers::CheckClassType($className, 'ProfileFieldType')) {
                $instance = new $className;
                if ($profileField != null) {
                    $instance->profileField = $profileField;

                    // Seems current type, so try load data
                    if ($profileField->field_type_class == $className) {
                        $instance->load();
                    }
                }
                $types[] = $instance;
            }
        }
        return $types;
    }
rbraband commented 9 years ago

Thank you esemve for the Fix!

acubaniti commented 9 years ago

Worked, great work!