Just a simple command that helps to set up initial RBAC rules. You can put it into protected/commands/shell and add some operations, tasks, roles and user assignments. Use yiic shell and enter setuprbac to use.
It would have been great if you mentioned that your script executes the schema.sql for creating the tables which includes a prior DROP TABLE IF EXISTS!
I know that your script is for initial setup, but i didn’t expected that it would drop my existing tables without checking or asking
I've already added some items and was now searching for an easier way to do the heavy work…
Maybe at least something like:
$createTables = false;
// Check whether tables already exist
if($this->_db->schema->getTable('AuthItem') || $this->_db->schema->getTable('AuthItemChild') || $this->_db->schema->getTable('AuthAssignment')){
echo "At least one Auth* table already exists in database!n Overwrite existing Auth* tables? [Yes|No] ";
if(!strncasecmp(trim(fgets(STDIN)),'y',1))
$createTables = true;
}
// Read schema file and create db tables
if($createTables===true)
{
$schemafile=Yii::getPathOfAlias('system.web.auth').DIRECTORY_SEPARATOR.'schema.sql';
if (($schema=file_get_contents($schemafile))===false)
die("Could not read schema file in $schemafile.n");
$this->_db->createCommand($schema)->execute();
}
The script was just a quick mashup to help me install RBAC rules for fresh installations. It uses the sql schema file that comes with Yii to create all required tables. Sorry, if that was unclear.