bhaveshsoni / yii-user-management

Automatically exported from code.google.com/p/yii-user-management
0 stars 0 forks source link

YUM have a wrong usergroup module/model code #178

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a Yii WebApp and Install YUM using custom name tables.
2. After Install YUM, Installer generate a new module configuration to save in 
main.php
3. Go to http://localhost/webapp/index.php/user/user/index , log as demo and 
click in Social -> My groups.

What is the expected output? What do you see instead?
I see a error than says {{usergroup}} table dont exists. I check code and i see 
some errors in YumUsergroup, YumUsergroupMessage and UsergroupModule classes.
YumUsergroupModule class original code:

public function tableName()
    {
        return '{{usergroup}}';
    }

It would be:

public function tableName()
    {
        if (isset(Yum::module('usergroup')->usergroupTable))
            $this->_tableName = Yum::module('usergroup')->usergroupTable;
        else
            $this->_tableName = '{{usergroup}}'; // fallback if nothing is set

        return Yum::resolveTableName($this->_tableName,$this->getDbConnection());
    }

public function tableName()
    {
        return '{{usergroup_messages}}';
    }

YumUsergroupMessage class original code:

It would be:

public function tableName()
    {
        if (isset(Yum::module('usergroup')->usergroupMessagesTable))
            $this->_tableName = Yum::module('usergroup')->usergroupMessagesTable;
        else
            $this->_tableName = '{{usergroup_messages}}'; // fallback if nothing is set

        return Yum::resolveTableName($this->_tableName,$this->getDbConnection());
    }

YumUsergroupModule has not a $$usergroupTable and $usergroupMessagesTable 
public propertys. I added this code to resolve:

    public $usergroupTable = '{{usergroup}}';
    public $usergroupMessagesTable = '{{usergroup_messages}}';;

What version of the product are you using? On what operating system?
Yii 1.1.8, YUM r417. Windows XP SP 3 with XAMPP 1.7.1

Original issue reported on code.google.com by jacko87 on 3 Dec 2011 at 5:52

GoogleCodeExporter commented 8 years ago
jacko87,

thanks for posting this up!

when i go to:
/usergroup/groups/index
(after a group has been created) then the model tries to pull any related 
messages using usergroupMessages.

I was receiving the error that $_tableName wasn't defined in 
YumUsergroupMessage. After trial and error I found the following to work:
    /**
     * Returns resolved table name (incl. table prefix when it is set in db configuration)
     * Following algorith of searching valid table name is implemented:
     *  - try to find out table name stored in currently used module
     *  - if not found try to get table name from UserGroupModule configuration
     *  - if not found user default {{user_group}} table name
     * @return string
     */
    public function tableName()
    {

        if (isset(Yum::module()->usergroupMessagesTable))
            //$this->_tableName = Yum::module()->usergroupMessagesTable;
            $_tableName = Yum::module()->usergroupMessagesTable;
        elseif (isset(Yii::app()->modules['usergroup']['usergroupMessagesTable']))
            //$this->_tableName = Yii::app()->modules['usergroup']['usergroupMessagesTable'];
            $_tableName = Yii::app()->modules['usergroup']['usergroupMessagesTable'];
        else
            //$this->_tableName = '{{user_group_message}}'; // fallback if nothing is set
            $_tableName = '{{user_group_message}}';

        $_tableName = '{{user_group_message}}'; // fallback if nothing is set
        return Yum::resolveTableName($_tableName, $this->getDbConnection());
        //return '{{user_group_message}}';
    }

essentially, creating a variable in the function and removing the $this->

hope that helps someone else.

Original comment by allen.br...@gmail.com on 24 Feb 2012 at 2:44