The User object was not saving anything if its userID started off as undef (i.e., new user) and the code never changed any properties (which is normal for a new user). Changed the code to automatically assume it is dirty if it starts with an undefined userID. Changed writeProperties to use the return value from the data source to save any changes to userID, so that when it is defined (by inserting a new record, probably) then we can remember it. Finally, changed propertySet so that when userID is changed from an undefined value to a defined value, the change is propagated to the fields and the groups are marked dirty, which will force them to be written out too.

This commit is contained in:
ian%hixie.ch 2001-11-10 21:00:37 +00:00
Родитель 5139796ce4
Коммит b9400f341d
1 изменённых файлов: 17 добавлений и 4 удалений

Просмотреть файл

@ -128,7 +128,7 @@ sub objectInit {
$self->originalGroups({%$groups}); # a backup used to make a comparison when saving the groups
my %rights = map {$_ => 1} @$rights;
$self->rights(\%rights); # map a list of strings into a hash for easy access
$self->{'_DIRTY'}->{'properties'} = 0;
$self->{'_DIRTY'}->{'properties'} = not(defined($userID));
}
sub hasRight {
@ -301,7 +301,20 @@ sub invalidateRights {
sub propertySet {
my $self = shift;
my($name, $value) = @_;
# check that we're not doing silly things like changing the user's ID
my $hadUndefinedID = (($name eq 'userID') and
($self->propertyExists($name)) and
(not defined($self->propertyGet($name))));
my $result = $self->SUPER::propertySet(@_);
if (($name eq 'userID') and (defined($value)) and ($hadUndefinedID)) {
# we've just aquired an ID, so propagate the change to all fields
foreach my $field (values(%{$self->fieldsByID})) {
$field->userID($value);
}
# and mark the groups as dirty too
$self->{'_DIRTY'}->{'groups'} = 1;
}
$self->{'_DIRTY'}->{'properties'} = 1;
return $result;
}
@ -335,9 +348,9 @@ sub DESTROY {
sub writeProperties {
my $self = shift;
$self->app->getService('dataSource.user')->setUser($self->app, $self->userID, $self->mode,
$self->password, $self->adminMessage,
$self->newFieldID, $self->newFieldValue, $self->newFieldKey);
$self->userID($self->app->getService('dataSource.user')->setUser($self->app, $self->userID, $self->mode,
$self->password, $self->adminMessage,
$self->newFieldID, $self->newFieldValue, $self->newFieldKey));
}
sub writeGroups {