Add a method to update userProfileData column types.
Fix a bug with making a profileField called userId. Update POD Added several profileField tests.
This commit is contained in:
parent
23f7af1d71
commit
0d06c15275
4 changed files with 95 additions and 8 deletions
|
|
@ -26,6 +26,7 @@
|
|||
- fixed #10650: Unflatten WebGUI storage locations
|
||||
- fixed #10664: ThiingyRecord disappeared... sort of
|
||||
- fixed #10687: i18n Asset_Product::buy_form_options
|
||||
- fixed #10651: Dashboard Content positions
|
||||
|
||||
7.7.15
|
||||
- fixed #10629: WebGUI::ProfileField create new field bug
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ use Getopt::Long;
|
|||
use WebGUI::Session;
|
||||
use WebGUI::Storage;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::ProfileField;
|
||||
use List::MoreUtils qw/uniq/;
|
||||
|
||||
my $toVersion = '7.7.16';
|
||||
|
|
@ -32,6 +33,7 @@ my $session = start(); # this line required
|
|||
replaceUsageOfOldTemplatesAgain($session);
|
||||
updatePayPalDriversAgain($session);
|
||||
addThingyRecordFieldPriceDefaults($session);
|
||||
correctProfileFieldColumnTypes($session);
|
||||
|
||||
# upgrade functions go here
|
||||
|
||||
|
|
@ -47,6 +49,15 @@ finish($session); # this line required
|
|||
# print "DONE!\n" unless $quiet;
|
||||
#}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
sub correctProfileFieldColumnTypes {
|
||||
my $session = shift;
|
||||
my $config = $session->config;
|
||||
print "\tCheck database profile field types against form settings..." unless $quiet;
|
||||
WebGUI::ProfileField->fixDataColumnTypes($session);
|
||||
print "DONE!\n" unless $quiet;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
sub updatePayPalDriversAgain {
|
||||
my $session = shift;
|
||||
|
|
|
|||
|
|
@ -67,7 +67,50 @@ Return true iff fieldName is reserved and therefore not usable as a profile fiel
|
|||
sub isReservedFieldName {
|
||||
my $class = shift;
|
||||
my $fieldName = shift;
|
||||
return isIn($fieldName, ('func', 'op', 'wg_privacySettings'));
|
||||
return isIn($fieldName, qw/userId func op wg_privacySettings/);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 fixDataColumnTypes ( session )
|
||||
|
||||
Checks the column types of userProfileData against the form fields that they use. If they
|
||||
differ then they are updated to match for the form field. This is to account for bugs in
|
||||
this module, and changes in Form types.
|
||||
|
||||
This is a class method.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub fixDataColumnTypes {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
|
||||
my $dbh = $session->db->dbh;
|
||||
|
||||
my $fields = WebGUI::ProfileField->getFields($session);
|
||||
foreach my $field ( @{ $fields } ) {
|
||||
my $columnInfo = $dbh->column_info(undef, undef, 'userProfileData', $field->getId)->fetchrow_hashref();
|
||||
my $formField = $field->formField(undef, undef, undef, undef, undef, 'returnObject');
|
||||
my $columnType = $formField->getDatabaseFieldType();
|
||||
$columnType =~ s/\s+\w+$//;
|
||||
if ($columnType eq 'BOOLEAN') {
|
||||
$columnType = 'TINYINT'; ##Alias for INT(1)
|
||||
}
|
||||
my $actualType = $columnInfo->{TYPE_NAME};
|
||||
if ($columnType =~ m/\(\d+\)/) {
|
||||
$actualType = sprintf('%s(%s)', $actualType, $columnInfo->{COLUMN_SIZE});
|
||||
}
|
||||
if ($actualType ne $columnType) {
|
||||
$session->log->warn("Updating ".$field->getId." from $actualType to $columnType");
|
||||
$session->db->write('ALTER TABLE userProfileData MODIFY COLUMN '.$dbh->quote_identifier($field->getId).' '.$columnType);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -220,7 +263,7 @@ sub _formProperties { my $self = shift; return $self->formProperties(@_); }
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 formField ( [ formProperties, withWrapper, userObject ] )
|
||||
=head2 formField ( [ formProperties, withWrapper, userObject, skipDefault, assignedValue ] )
|
||||
|
||||
Returns an HTMLified form field element.
|
||||
|
||||
|
|
@ -245,6 +288,10 @@ If true, this causes the default value set up for the form field to be ignored.
|
|||
If assignedValue is defined, it will be used to override the default value set up for the
|
||||
form.
|
||||
|
||||
=head3 returnObject
|
||||
|
||||
If true, it returns a WebGUI::Form object, instead of returning HTML.
|
||||
|
||||
=cut
|
||||
|
||||
# FIXME This would be better if it returned an OBJECT not the HTML
|
||||
|
|
@ -259,6 +306,7 @@ sub formField {
|
|||
my $u = shift || $session->user;
|
||||
my $skipDefault = shift;
|
||||
my $assignedValue = shift;
|
||||
my $returnObject = shift;
|
||||
|
||||
if ($skipDefault) {
|
||||
$properties->{value} = undef;
|
||||
|
|
@ -278,12 +326,14 @@ sub formField {
|
|||
$properties->{value} = WebGUI::Operation::Shared::secureEval($session,$properties->{dataDefault});
|
||||
}
|
||||
}
|
||||
my $form = WebGUI::Form::DynamicField->new($session,%{$properties});
|
||||
return $form if $returnObject;
|
||||
if ($withWrapper == 1) {
|
||||
return WebGUI::Form::DynamicField->new($session,%{$properties})->toHtmlWithWrapper;
|
||||
return $form->toHtmlWithWrapper;
|
||||
} elsif ($withWrapper == 2) {
|
||||
return WebGUI::Form::DynamicField->new($session,%{$properties})->getValueAsHtml;
|
||||
return $form->getValueAsHtml;
|
||||
} else {
|
||||
return WebGUI::Form::DynamicField->new($session,%{$properties})->toHtml;
|
||||
return $form->toHtml;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -437,7 +487,7 @@ sub getEditableFields {
|
|||
|
||||
=head2 getFields ( session )
|
||||
|
||||
Returns an array reference of WebGUI::ProfileField objects. This is a class method.
|
||||
Returns an array reference of all WebGUI::ProfileField objects. This is a class method.
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -509,6 +559,8 @@ sub getRegistrationFields {
|
|||
return $class->_listFieldsWhere($session, "f.showAtRegistration = 1");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getPasswordRecoveryFields ( session )
|
||||
|
||||
Returns an array reference of profile field objects that are required
|
||||
|
|
@ -892,7 +944,7 @@ sub setCategory {
|
|||
|
||||
return undef if ($categoryId eq $currentCategoryId);
|
||||
|
||||
my ($sequenceNumber) = $self->session->db->quickArray("select max(sequenceNumber) from userProfileField where profileCategoryId=".$self->session->db->quote($categoryId));
|
||||
my ($sequenceNumber) = $self->session->db->quickArray("select max(sequenceNumber) from userProfileField where profileCategoryId=?", [$categoryId]);
|
||||
$self->session->db->setRow("userProfileField","fieldName",{fieldName=>$self->getId, profileCategoryId=>$categoryId, sequenceNumber=>$sequenceNumber+1});
|
||||
$self->{_property}{profileCategoryId} = $categoryId;
|
||||
$self->{_property}{sequenceNumber} = $sequenceNumber+1;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ WebGUI::Test->usersToDelete($newUser);
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 28; # Increment this number for each test you create
|
||||
plan tests => 37; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test the creation of ProfileField
|
||||
|
|
@ -124,6 +124,29 @@ is($newProfileField2->getLabel, 'WebGUI', 'getLabel will process safeEval calls
|
|||
ok( WebGUI::ProfileField->exists($session,"firstName"), "firstName field exists" );
|
||||
ok( !WebGUI::ProfileField->exists($session, time), "random field does not exist" );
|
||||
|
||||
###########################################################
|
||||
#
|
||||
# isReservedFieldName
|
||||
#
|
||||
###########################################################
|
||||
|
||||
ok( WebGUI::ProfileField->isReservedFieldName('func'), 'isReservedFieldName: func');
|
||||
ok( WebGUI::ProfileField->isReservedFieldName('op'), '... op');
|
||||
ok( WebGUI::ProfileField->isReservedFieldName('userId'), '... userId');
|
||||
ok( WebGUI::ProfileField->isReservedFieldName('wg_privacySettings'), '... wg_privacySettings');
|
||||
ok( !WebGUI::ProfileField->isReservedFieldName('function'), '... function is not');
|
||||
ok( !WebGUI::ProfileField->isReservedFieldName('operation'), '... operation is no');
|
||||
ok( !WebGUI::ProfileField->isReservedFieldName('shop'), '... shop is not');
|
||||
|
||||
###########################################################
|
||||
#
|
||||
# exists
|
||||
#
|
||||
###########################################################
|
||||
|
||||
ok( WebGUI::ProfileField->exists($session, 'email'), 'exists: email');
|
||||
ok( !WebGUI::ProfileField->exists($session, 'userId'), '... userId (not)');
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue