Added exists() method to ProfileField + tests
This commit is contained in:
parent
18993c5924
commit
774c499d2d
2 changed files with 30 additions and 13 deletions
|
|
@ -104,12 +104,7 @@ sub create {
|
|||
|
||||
### Check data
|
||||
# Check if the field already exists
|
||||
my $fieldNameExists
|
||||
= $session->db->quickScalar(
|
||||
"select count(*) from userProfileField where fieldName=?",
|
||||
[$fieldName]
|
||||
);
|
||||
return undef if $fieldNameExists;
|
||||
return undef if $class->exists($session,$fieldName);
|
||||
return undef if $class->isReservedFieldName($fieldName);
|
||||
|
||||
### Data okay, create the field
|
||||
|
|
@ -155,6 +150,24 @@ sub delete {
|
|||
$db->deleteRow("userProfileField","fieldName",$self->getId);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 exists ( session, fieldName )
|
||||
|
||||
Class method that returns true if a field with the given name already
|
||||
exists. The first argument is a WebGUI::Session object. C<fieldName> is
|
||||
the field name to check
|
||||
|
||||
=cut
|
||||
|
||||
sub exists {
|
||||
my ( $class, $session, $fieldName ) = @_;
|
||||
|
||||
return 1 if $session->db->quickScalar(
|
||||
"SELECT COUNT(*) FROM userProfileField WHERE fieldName=?",
|
||||
[$fieldName]
|
||||
);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -717,12 +730,7 @@ sub rename {
|
|||
|
||||
### Check data
|
||||
# Make sure the field doesn't exist
|
||||
my $fieldNameExists
|
||||
= $self->session->db->quickScalar(
|
||||
"SELECT COUNT(*) FROM userProfileField WHERE fieldName=?",
|
||||
[$newName]
|
||||
);
|
||||
return 0 if ($fieldNameExists);
|
||||
return 0 if $self->exists($session, $newName);
|
||||
|
||||
# Rename the userProfileData column
|
||||
my $fieldClass = $self->getFormControlClass;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue