[Rt-commit] r8740 - rtir/branches/2.3-EXPERIMENTAL/etc
ruz at bestpractical.com
ruz at bestpractical.com
Mon Aug 27 07:04:29 EDT 2007
Author: ruz
Date: Mon Aug 27 07:04:28 2007
New Revision: 8740
Modified:
rtir/branches/2.3-EXPERIMENTAL/etc/add_constituency
Log:
* check that constituency already exist and ask if user want proceed
Modified: rtir/branches/2.3-EXPERIMENTAL/etc/add_constituency
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/etc/add_constituency (original)
+++ rtir/branches/2.3-EXPERIMENTAL/etc/add_constituency Mon Aug 27 07:04:28 2007
@@ -91,6 +91,20 @@
$RT::Handle->BeginTransaction;
+if ( cf_value_exists( $constituency ) ) {
+ print <<END;
+Constituency '$constituency' already exists.
+
+If you continue then we'll...
+* create queues if they don't exist
+* create groups if they don't exist
+* grant basic set of rights
+
+END
+
+ exit 0 unless prompt_yN( "Do you want to proceed?" );
+}
+
debug "Adding constituency $constituency";
add_cf_value( $constituency );
@@ -165,6 +179,13 @@
debug "Done. Enjoy your new constituency.\n";
+sub prompt_yN {
+ my $text = shift;
+ print "$text [y/N] ";
+ return 0 unless <STDIN> =~ /^(?:y|yes)$/i;
+ return 1;
+}
+
sub get_cf {
my $cf = RT::CustomField->new( $RT::SystemUser );
$cf->Load( "_RTIR_Constituency" );
@@ -174,16 +195,25 @@
return $cf;
}
-sub add_cf_value {
+sub cf_value_exists {
my $value = shift;
- debug "Adding the value to the constituency CF";
+ debug "Check that the constituency exists";
my $cf = get_cf();
my $values = $cf->Values;
$values->Limit( FIELD => 'Name', VALUE => $value );
my $value_obj = $values->First;
- if ( $value_obj && $value_obj->id ) {
+ return $value_obj && $value_obj->id? 1 : 0;
+}
+
+sub add_cf_value {
+ my $value = shift;
+
+ debug "Adding the value to the constituency CF";
+
+ my $cf = get_cf();
+ if ( cf_value_exists( $value ) ) {
debug "Value '$value' already exists";
} else {
my ($val,$msg) = $cf->AddValue( Name => $value );
More information about the Rt-commit
mailing list