/**
  * Assigns a role to a user at the specified context
  *
  * @throws Exception
  * @param array $data
  * @return void
  */
 protected function process_role_assign($data)
 {
     if (empty($data['roleid'])) {
         throw new Exception('\'role assigns\' requires the field \'role\' to be specified');
     }
     if (!isset($data['userid'])) {
         throw new Exception('\'role assigns\' requires the field \'user\' to be specified');
     }
     if (empty($data['contextlevel'])) {
         throw new Exception('\'role assigns\' requires the field \'contextlevel\' to be specified');
     }
     if (!isset($data['reference'])) {
         throw new Exception('\'role assigns\' requires the field \'reference\' to be specified');
     }
     // Getting the context id.
     $context = $this->get_context($data['contextlevel'], $data['reference']);
     $this->datagenerator->role_assign($data['roleid'], $data['userid'], $context->id);
 }