Upgrading user information

The following examples use the UpgradeInfo method (of the User object) to optimize peformance when setting User properties and updating the databases to which a user is subscribed.

These examples update a user profile and upgrade all the databases that the User is subscribed to. They also verify the update by attempting to log into each accessible database.

For more information, see UpgradeInfo.

Perl


use CQPerlExt;   
use Time::Local; 
$dbset = "2003.06.00";
$adminUser = "admin";
$adminPasswd = "";

# Create a DevOps Plan
 admin session
my $adminSession= CQAdminSession::Build();

if ($adminSession->Logon( $adminUser, $adminPasswd, $dbset )) {
    print "Could not get Admin session login\n";
    exit 1;
   }
# the user who you want to change user profile for 
my ($userName, $passwd) = ("testuser", "password");

# Get the user object for the user we want to upgrade.
my $userObj = $adminSession->GetUser($userName);
unless ($userObj) { 
    print "$0: Error: Failed lookup for user \"$userName\"\n"; 
    exit 1;
   }

$email="qe\@example.com";
$phone="123456789";
$fullname="Best Engineer";
$userObj->SetPassword($passwd);
$userObj->SetEmail($email);
$userObj->SetPhone($phone);
$userObj->SetFullName($fullname);

# Upgrade all the databases that the user is subscribed to
print "Upgrade user profile for $userName\n";
$failed_dbs = $userObj->UpgradeInfo();
@temp = @$failed_dbs;
if ($#temp > -1)
   {
        printf "fail dbs: %s.\n", join(',', @temp);
   }

# verify the new password by logging into databases
$session = CQSession::Build();
$dbdescs = $session->GetAccessibleDatabases("MASTR", $userName, $dbset);
foreach $i (0 .. $dbdescs->Count()-1)
{
    $dbname = $dbdescs->Item($i)->GetDatabaseName();
    $session->UserLogon($userName, $passwd, $dbname, $dbset);
    unless (defined $session)
    {
      print LOG "Could not get session login to db $dbname\n";
      exit 1;  
    }
    print "Checking user info in db $dbname:\n";
    # verify the new phone, fullname, and email
    if ($email ne $session->GetUserEmail()) {
      print "Email is not upgraded in $dbname\n";
          }
    if ($fullname ne $session->GetUserFullName()) {
      print "Full name is not upgraded in $dbname\n";
          }
    if ($phone ne $session->GetUserPhone()) {
      print "Phone is not upgraded in $dbname\n";
          }
    else {
          print "User information verified.\n";
          }
}