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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -281,7 +281,12 @@ Returns the workflowId of the Gallery's approval workflow.
|
|||
|
||||
sub getAutoCommitWorkflowId {
|
||||
my $self = shift;
|
||||
return $self->getGallery->get("workflowIdCommit");
|
||||
my $gallery = $self->getGallery;
|
||||
if ($gallery->hasBeenCommitted) {
|
||||
return $gallery->get("workflowIdCommit")
|
||||
|| $self->session->setting->get('defaultVersionTagWorkflow');
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -683,8 +688,6 @@ sub processPropertiesFromFormPost {
|
|||
} );
|
||||
}
|
||||
|
||||
$self->requestAutoCommit;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -195,25 +195,13 @@ sub editSave {
|
|||
}
|
||||
$tempStorage->delete;
|
||||
|
||||
# deal with special commit rules
|
||||
if ($self->session->form->process("saveAndCommit") ne "") {
|
||||
if ($self->session->setting->get("skipCommitComments")) {
|
||||
$self->session->http->setRedirect($self->getUrl("op=commitVersionTagConfirm;tagId=".WebGUI::VersionTag->getWorking($self->session)->getId));
|
||||
}
|
||||
else {
|
||||
$self->session->http->setRedirect($self->getUrl("op=commitVersionTag;tagId=".WebGUI::VersionTag->getWorking($self->session)->getId));
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
if ($self->session->setting->get("autoRequestCommit")) {
|
||||
if ($self->session->setting->get("skipCommitComments")) {
|
||||
WebGUI::VersionTag->getWorking($self->session)->requestCommit;
|
||||
}
|
||||
else {
|
||||
$self->session->http->setRedirect($self->getUrl("op=commitVersionTag;tagId=".WebGUI::VersionTag->getWorking($self->session)->getId));
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
if (WebGUI::VersionTag->autoCommitWorkingIfEnabled($self->session, {
|
||||
override => scalar $self->session->form->process("saveAndCommit"),
|
||||
allowComments => 1,
|
||||
returnUrl => $self->getUrl,
|
||||
})) {
|
||||
return undef;
|
||||
};
|
||||
|
||||
return $self->getParent->www_manageAssets if ($self->session->form->process("proceed") eq "manageAssets");
|
||||
return $self->getParent->www_view;
|
||||
|
|
|
|||
|
|
@ -332,8 +332,13 @@ sub getContentLastModified {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub getAutoCommitWorkflowId {
|
||||
my $self = shift;
|
||||
return $self->getThread->getParent->get("approvalWorkflow");
|
||||
my $self = shift;
|
||||
my $cs = $self->getThread->getParent;
|
||||
if ($cs->hasBeenCommitted) {
|
||||
return $cs->get('approvalWorkflow')
|
||||
|| $self->session->setting->get('defaultVersionTagWorkflow');
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -879,7 +884,6 @@ sub postProcess {
|
|||
$size += $storage->getFileSize($file);
|
||||
}
|
||||
$self->setSize($size);
|
||||
$self->requestAutoCommit;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -582,6 +582,14 @@ sub postProcess {
|
|||
$self->SUPER::postProcess;
|
||||
}
|
||||
|
||||
sub processPropertiesFromFormPost {
|
||||
my $self = shift;
|
||||
if ($self->isNew && $self->getParent->getValue('useCaptcha')) {
|
||||
my $captcha = $self->session->form->process("captcha","Captcha");
|
||||
return [ 'invalid captcha' ];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub purge {
|
||||
|
|
|
|||
|
|
@ -467,10 +467,7 @@ sub www_editDuplicate {
|
|||
|
||||
# Auto-commit our revision if necessary
|
||||
# TODO: This needs to be handled automatically somehow...
|
||||
if ($session->setting->get("autoRequestCommit")) {
|
||||
my $tag = WebGUI::VersionTag->getWorking($session)->requestCommit;
|
||||
}
|
||||
|
||||
WebGUI::VersionTag->autoCommitWorkingIfEnabled($self->session);
|
||||
last DEF;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,7 +117,12 @@ sub definition {
|
|||
#-------------------------------------------------------------------
|
||||
sub getAutoCommitWorkflowId {
|
||||
my $self = shift;
|
||||
return $self->getWiki->get("approvalWorkflow");
|
||||
my $wiki = $self->getWiki;
|
||||
if ($wiki->hasBeenCommitted) {
|
||||
return $wiki->get('approvalWorkflow')
|
||||
|| $self->session->setting->get('defaultVersionTagWorkflow');
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -266,9 +271,7 @@ sub processPropertiesFromFormPost {
|
|||
}
|
||||
}
|
||||
|
||||
# wiki pages are auto committed
|
||||
$self->requestAutoCommit;
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -425,7 +425,7 @@ sub canAddEvent {
|
|||
: $self->session->user
|
||||
;
|
||||
|
||||
return 1 if (
|
||||
return 1 if (
|
||||
$user->isInGroup( $self->get("groupIdEventEdit") )
|
||||
);
|
||||
}
|
||||
|
|
@ -1755,26 +1755,6 @@ sub wrapIcal {
|
|||
return join "\r\n ",@text;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_add ( )
|
||||
|
||||
Returns an error message if the collaboration system has not yet been posted.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_add {
|
||||
my $self = shift;
|
||||
|
||||
#Check to see if the asset has been committed
|
||||
unless ($self->hasBeenCommitted ) {
|
||||
my $i18n = WebGUI::International->new($self->session,"Asset_Calendar");
|
||||
return $self->processStyle($i18n->get("asset not committed"));
|
||||
}
|
||||
return $self->SUPER::www_add( @_ );
|
||||
}
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_edit ( )
|
||||
|
|
|
|||
|
|
@ -1388,55 +1388,6 @@ sub view {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_add ( )
|
||||
|
||||
Returns an error message if the collaboration system has not yet been posted.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_add {
|
||||
my $self = shift;
|
||||
|
||||
#Check to see if the asset has been committed
|
||||
unless ( $self->hasBeenCommitted ) {
|
||||
my $i18n = WebGUI::International->new($self->session,"Asset_Collaboration");
|
||||
return $self->processStyle($i18n->get("asset not committed"));
|
||||
}
|
||||
return $self->SUPER::www_add( @_ );
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_editSave ( )
|
||||
|
||||
We're extending www_editSave() here to deal with editing a post that has been denied by the approval process. Our change will reassign the old working tag of this post to the user so that they can edit it.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_editSave {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
my $className = $session->form->param("class");
|
||||
|
||||
#my $assetId = $self->session->form->param("assetId");
|
||||
if($className eq "WebGUI::Asset::Post::Thread") {
|
||||
my $assetId = $session->form->param("assetId");
|
||||
|
||||
if($assetId eq "new" && $self->getValue("useCaptcha")) {
|
||||
my $captcha = $self->session->form->process("captcha","Captcha");
|
||||
unless ($captcha) {
|
||||
return $self->www_add;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $self->SUPER::www_editSave();
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_search ( )
|
||||
|
||||
The web method to display and use the forum search interface.
|
||||
|
|
|
|||
|
|
@ -361,7 +361,12 @@ Returns the workflowId of the Gallery's approval workflow.
|
|||
|
||||
sub getAutoCommitWorkflowId {
|
||||
my $self = shift;
|
||||
return $self->getParent->get("workflowIdCommit");
|
||||
my $gallery = $self->getParent;
|
||||
if ($gallery->hasBeenCommitted) {
|
||||
return $gallery->get("workflowIdCommit")
|
||||
|| $self->session->setting->get('defaultVersionTagWorkflow');
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -708,8 +713,6 @@ sub processPropertiesFromFormPost {
|
|||
return $errors if @$errors;
|
||||
|
||||
### Passes all checks
|
||||
|
||||
$self->requestAutoCommit;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -303,9 +303,7 @@ sub www_setContentPositions {
|
|||
$self->addRevision({
|
||||
contentPositions=>$self->session->form->process("map")
|
||||
});
|
||||
if ($self->session->setting->get("autoRequestCommit")) {
|
||||
WebGUI::VersionTag->getWorking($self->session)->requestCommit;
|
||||
}
|
||||
WebGUI::VersionTag->autoCommitWorkingIfEnabled($self->session);
|
||||
return "Map set: ".$self->session->form->process("map");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -385,21 +385,12 @@ sub www_importProducts {
|
|||
}
|
||||
else {
|
||||
$status_message = $i18n->get('import successful');
|
||||
##Copy and paste from WebGUI::Asset, www_editSave
|
||||
if ($self->session->setting->get("autoRequestCommit")) {
|
||||
# Make sure version tag hasn't already been committed by another process
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($self->session, "nocreate");
|
||||
|
||||
if ($versionTag && $self->session->setting->get("skipCommitComments")) {
|
||||
$versionTag->requestCommit;
|
||||
}
|
||||
elsif ($versionTag) {
|
||||
$self->session->http->setRedirect(
|
||||
$self->getUrl("op=commitVersionTag;tagId=".WebGUI::VersionTag->getWorking($self->session)->getId)
|
||||
);
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
if (WebGUI::VersionTag->autoCommitWorkingIfEnabled($self->session, {
|
||||
allowComments => 1,
|
||||
returnUrl => $self->getUrl,
|
||||
})) {
|
||||
return undef;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -392,26 +392,6 @@ sub view {
|
|||
return $self->processTemplate($var, undef, $template);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_add ( )
|
||||
|
||||
Returns an error message if the collaboration system has not yet been posted.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_add {
|
||||
my $self = shift;
|
||||
|
||||
#Check to see if the asset has been committed
|
||||
unless ($self->hasBeenCommitted ) {
|
||||
my $i18n = WebGUI::International->new($self->session,"Asset_WikiMaster");
|
||||
return $self->processStyle($i18n->get("asset not committed"));
|
||||
}
|
||||
return $self->SUPER::www_add( @_ );
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_byKeyword {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue