[Bio] / WebApplication / scripts / set_user_preference.pl Repository:
ViewVC logotype

View of /WebApplication/scripts/set_user_preference.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Mon Nov 26 21:47:15 2007 UTC (12 years, 4 months ago) by paczian
Branch: MAIN
CVS Tags: rast_rel_2008_06_18, rast_rel_2008_12_18, rast_rel_2008_07_21, rast_2008_0924, rast_rel_2008_04_23, rast_rel_2008_06_16, rast_rel_2008_09_30, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, rast_rel_2009_02_05, mgrast_rel_2008_0625, rast_rel_2008_10_09, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, mgrast_rel_2008_1110, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, rast_rel_2008_11_24, rast_rel_2008_08_07
initial version

#!/usr/bin/env perl

use strict;
use warnings;

use lib('..');
use lib('../../PPO');

use DBMaster;
use FIG;

use Getopt::Long;

sub usage {
  print "set_user_preference.pl >>> set a user preference\n";
  print "user_set_password.pl -login <login> -application <application> -preference <preference> -value <value>\n";
}

# read in parameters
my $login    = '';
my $app = '';
my $preference = '';
my $value = '';

GetOptions ( 'application=s' => \$app,
	     'login=s' => \$login,
	     'preference=s' => \$preference,
	     'value=s' => \$value,
	   );


unless ($app and $login and $preference and $value) {
  &usage();
  exit 0;
}

# initialize db-master
my $dbmaster = DBMaster->new( -database => 'WebAppBackend' );
my $application = $dbmaster->Backend->init( { name => $app } );
unless ( ref( $application ) ) {
  print STDERR "Application $app not found ! \n";
  exit(0);
}

# get user
my $user = $dbmaster->User->init( { 'login' => $login } );
unless (ref $user) {
  print "User $login not found in database, aborting.\n";
  exit 0;
}

my $preferences = $dbmaster->Preferences->get_objects( { user => $user,
							 name => $preference,
						         application => $application } );

unless ( scalar( @$preferences ) ) {
  my $preferenceobj = $dbmaster->Preferences->create( { user => $user,
							name => $preference,
							value => $value,
							application => $application } );
  print STDERR "Preference set.\n";
}
else {
  if ( $preferences->[0]->value eq $value ) {
    print STDERR "The user already has this preference.\n";
  }
  else {
    $preferences->[0]->value( $value );
    print STDERR "Preference set from ".$preferences->[0]->value." to $value\n";
  }
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3