/**
  * Creates a role.
  *
  * @param array $data
  * @return void
  */
 protected function process_role($data)
 {
     // We require the user to fill the role shortname.
     if (empty($data['shortname'])) {
         throw new Exception('\'role\' requires the field \'shortname\' to be specified');
     }
     $this->datagenerator->create_role($data);
 }
Exemple #2
0
 public function execute()
 {
     global $CFG, $DB;
     require_once $CFG->libdir . DIRECTORY_SEPARATOR . "testing" . DIRECTORY_SEPARATOR . "generator" . DIRECTORY_SEPARATOR . "data_generator.php";
     $generator = new \testing_data_generator();
     $options = $this->expandedOptions;
     $arguments = $this->arguments;
     //don't create if already exists
     $role = $DB->get_record('role', array('shortname' => $arguments[0]));
     if ($role) {
         echo "Role '" . $arguments[0] . "' already exists!\n";
         exit(0);
     }
     $options['shortname'] = $arguments[0];
     $newroleid = $generator->create_role($options);
     echo "{$newroleid}\n";
 }