I’m following an RBAC tutorial for adding roles/operations/etc… to a Yii project using the console and all seems fine but nothing is being saved to the database as expected. I have copied the schema for the three required tables from framework/web/auth/schema-mysql.sql
Sample code I’m trying:
$auth=Yii::app()->authManager;
$role=$auth->createRole('owner');
$auth->createOperation('createProject', 'Create a new project');
$role->addChild('createProject');
I have exited and re-entered the console to ensure it has any changes made. I have also ensured that protected/config/console.php contains the correct db info.
Is there a final method that should be called to save to the database that I’m missing?
Edit: Also I’m confused at why in the AuthAssignment table in the example database schema that the userid field is set to a string. Is it significant that I changed this to an integer?
The shell command is being run from the webroot and I know it is processing run() as it prints my successful message at the end. I am not getting any error messages in the console. I don’t believe any logs are being written to in this case.
A trial piece of code I’m trying is:
public function run($args)
{
if(($this->_authManager=Yii::app()->authManager)!==null)
{
echo "This command will create new roles\n";
echo 'Would you like to continue? [y|n]: ';
if(!strcasecmp(trim(fgets(STDIN)), 'y'))
{
$this->_authManager->clearAll();
$auth=Yii::app()->authManager;
$role=$auth->createRole('owner');
$auth->createOperation('createProject', 'Create a new project');
$role->addChild('createProject');
echo 'Authorisation hierarchy successfully generated.';
}
}
}
Did you set-up separate dbs within main, test & console? Or are you using the same db name?
On a trivial side note, you want to use the same auth rather than call yii::app() twice.
If you are not getting any error messages and your console is reporting success. Based on what you are telling me, I really cannot think of how to help. If I can think of anything else I will post back.
I discovered that I left out the CDbAuthManager from the components section in the main config file. I could have sworn I put it in there. Unsure why the if statement didn’t catch this.