rfe #640: Refactored autocommit and autocomment
Autocommit assets like CS posts or Calendar Events can now be added before the parent is committed. They will go into the same version tag as their parent.
This commit is contained in:
parent
71fc839c83
commit
99a9da626d
22 changed files with 218 additions and 259 deletions
|
|
@ -16,12 +16,12 @@ our $VERSION = "0.0.0";
|
|||
|
||||
use Tie::IxHash;
|
||||
use Carp qw(croak);
|
||||
use Storable qw(nfreeze thaw);
|
||||
|
||||
use WebGUI::International;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::Form;
|
||||
use WebGUI::Storage::Image;
|
||||
use Storable;
|
||||
|
||||
use base 'WebGUI::Asset';
|
||||
|
||||
|
|
@ -275,8 +275,7 @@ sub generateRecurringEvents {
|
|||
$properties->{startTime} = $startDate->toDatabaseTime;
|
||||
$properties->{endTime} = $endDate->toDatabaseTime;
|
||||
}
|
||||
my $newEvent = $parent->addChild($properties);
|
||||
$newEvent->requestAutoCommit;
|
||||
my $newEvent = $parent->addChild($properties, undef, undef, { skipAutoCommitWorkflows => 1 });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -298,8 +297,12 @@ By specifying this method, you activate this feature.
|
|||
|
||||
sub getAutoCommitWorkflowId {
|
||||
my $self = shift;
|
||||
return $self->getParent->get('workflowIdCommit')
|
||||
|| $self->session->setting->get('defaultVersionTagWorkflow');
|
||||
my $parent = $self->getParent;
|
||||
if ($parent->hasBeenCommitted) {
|
||||
return $parent->get('workflowIdCommit')
|
||||
|| $self->session->setting->get('defaultVersionTagWorkflow');
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1469,7 +1472,7 @@ sub processPropertiesFromFormPost {
|
|||
my $self = shift;
|
||||
$self->SUPER::processPropertiesFromFormPost; # Updates the event
|
||||
my $session = $self->session;
|
||||
my $form = $self->session->form;
|
||||
my $form = $session->form;
|
||||
|
||||
### Verify the form was filled out correctly...
|
||||
my @errors;
|
||||
|
|
@ -1489,6 +1492,17 @@ sub processPropertiesFromFormPost {
|
|||
return \@errors;
|
||||
}
|
||||
|
||||
# Since we may be adding more events, set out version tag to be active if needed
|
||||
# Leave the original version tag available, we will need to reactivate it before returning
|
||||
warn "trying to activate version tag\n";
|
||||
my $activeVersionTag = WebGUI::VersionTag->getWorking($session, 'nocreate');
|
||||
# if our version tag is active, we don't need a new one, and don't need to reactivate anything later
|
||||
if ($activeVersionTag && $activeVersionTag->getId eq $self->get('tagId')) {
|
||||
undef $activeVersionTag;
|
||||
}
|
||||
else {
|
||||
WebGUI::VersionTag->new($session, $self->get('tagId'))->setWorking;
|
||||
}
|
||||
|
||||
### Form is verified
|
||||
# Events are always hidden from navigation
|
||||
|
|
@ -1518,16 +1532,16 @@ sub processPropertiesFromFormPost {
|
|||
my $dtStart
|
||||
= WebGUI::DateTime->new($session,
|
||||
mysql => $self->get("startDate") . " " . $self->get("startTime"),
|
||||
time_zone => $tz,
|
||||
time_zone => $tz,
|
||||
);
|
||||
|
||||
my $dtEnd
|
||||
= WebGUI::DateTime->new($session,
|
||||
mysql => $self->get("endDate") . " " . $self->get("endTime"),
|
||||
time_zone => $tz,
|
||||
time_zone => $tz,
|
||||
);
|
||||
|
||||
$self->update({
|
||||
$self->update({
|
||||
startDate => $dtStart->toDatabaseDate,
|
||||
startTime => $dtStart->toDatabaseTime,
|
||||
endDate => $dtEnd->toDatabaseDate,
|
||||
|
|
@ -1603,7 +1617,6 @@ sub processPropertiesFromFormPost {
|
|||
|
||||
$self->setRelatedLinks(\@rel_link_saves);
|
||||
|
||||
|
||||
# Determine if the pattern has changed
|
||||
if ($form->param("recurType")) {
|
||||
# Create the new recurrence hash
|
||||
|
|
@ -1617,16 +1630,19 @@ sub processPropertiesFromFormPost {
|
|||
|
||||
|
||||
# Pattern keys
|
||||
if (nfreeze(\%recurrence_new) ne nfreeze(\%recurrence_old)) {
|
||||
if (Storable::freeze(\%recurrence_new) ne Storable::freeze(\%recurrence_old)) {
|
||||
# Delete all old events and create new ones
|
||||
my $old_id = $self->get("recurId");
|
||||
|
||||
# Set the new recurrence pattern
|
||||
if (%recurrence_new) {
|
||||
my $new_id = $self->setRecurrence(\%recurrence_new);
|
||||
return ["There is something wrong with your recurrence pattern."]
|
||||
unless $new_id;
|
||||
|
||||
if (! $new_id) {
|
||||
$activeVersionTag->setWorking
|
||||
if $activeVersionTag;
|
||||
return ["There is something wrong with your recurrence pattern."];
|
||||
}
|
||||
|
||||
# Generate the new recurring events
|
||||
$self->generateRecurringEvents();
|
||||
}
|
||||
|
|
@ -1649,7 +1665,7 @@ sub processPropertiesFromFormPost {
|
|||
# TODO: Give users a form property to decide what events to update
|
||||
# TODO: Make a workflow activity to do this, so that updating
|
||||
# 1 million events doesn't kill the server.
|
||||
# Just update related events
|
||||
# Just update related events
|
||||
my %properties = %{ $self->get };
|
||||
delete $properties{startDate};
|
||||
delete $properties{endDate};
|
||||
|
|
@ -1663,23 +1679,21 @@ sub processPropertiesFromFormPost {
|
|||
});
|
||||
|
||||
for my $eventId (@{$events}) {
|
||||
my $event = WebGUI::Asset->newByDynamicClass($session,$eventId);
|
||||
my $event = WebGUI::Asset->newByDynamicClass($session, $eventId);
|
||||
|
||||
# Add a revision
|
||||
$properties{ startDate } = $event->get("startDate");
|
||||
$properties{ endDate } = $event->get("endDate");
|
||||
|
||||
# addRevision returns the new revision
|
||||
$event = $event->addRevision(\%properties);
|
||||
$event->requestAutoCommit();
|
||||
$event = $event->addRevision(\%properties, undef, { skipAutoCommitWorkflows => 1 });
|
||||
}
|
||||
}
|
||||
}
|
||||
$activeVersionTag->setWorking
|
||||
if $activeVersionTag;
|
||||
|
||||
# Finally, commit this event
|
||||
delete $self->{_storageLocation};
|
||||
$self->requestAutoCommit;
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue