/// <summary> /// Publishes the document to the live site. /// </summary> private void HandlePublishNow() { // Have to do this prior to the publish due to workaround for "publish at" handling. Instance.Status = (int)WorkflowStatus.Approved; Instance.CompletedDate = DateTime.Now; // Perform the publish IContent node = _contentService.GetById(Instance.NodeId); // clear the release date if (node.ReleaseDate.HasValue) { node.ReleaseDate = null; } Attempt <PublishStatus> publishStatus = _contentService.PublishWithStatus(node, Instance.TaskInstances.Last().ActionedByUserId ?? _utility.GetCurrentUser().Id); if (!publishStatus.Success) { Instance.Status = (int)WorkflowStatus.Errored; Instance.AuthorComment += $" (Workflow error: {publishStatus.Exception.Message})"; Log.Error(publishStatus.Exception.Message); throw new WorkflowException(publishStatus.Exception.Message); } _instancesService.UpdateInstance(Instance); _emailer.Send(Instance, EmailType.ApprovedAndCompleted); Completed?.Invoke(this, new InstanceEventArgs(Instance, "PublishNow")); }
/// <summary> /// Publishes the document to the live site. /// </summary> private void HandlePublishNow() { // Have to do this prior to the publish due to workaround for "publish at" handling. Instance.Status = (int)WorkflowStatus.Approved; Instance.CompletedDate = DateTime.Now; // Perform the publish IContent node = _contentService.GetById(Instance.NodeId); // clear the release date if (node.ReleaseDate.HasValue) { node.ReleaseDate = null; } Attempt <PublishStatus> publishStatus = _contentService.PublishWithStatus(node, Instance.TaskInstances.Last().ActionedByUserId ?? _utility.GetCurrentUser().Id); EventMessages = GetEventMessages(publishStatus); if (!publishStatus.Success) { bool exceptionOccured = publishStatus.Exception != null; string errorDetail = exceptionOccured ? publishStatus.Exception.Message : publishStatus.Result.StatusType.ToString(); string errorMessage = exceptionOccured ? $" [Workflow error: {errorDetail}]" : $" [Workflow error: Publish failed - {errorDetail}]"; Instance.Status = (int)WorkflowStatus.Errored; Instance.AuthorComment += errorMessage; _instancesService.UpdateInstance(Instance); Log.Error(errorMessage); _emailer.Send(Instance, EmailType.WorkflowErrored, errorDetail); if (exceptionOccured) { throw new WorkflowException(publishStatus.Exception.Message); // need eventmessages support here? } throw new UmbracoOperationFailedException(publishStatus.Result.ToString()); } _instancesService.UpdateInstance(Instance); _emailer.Send(Instance, EmailType.ApprovedAndCompleted); Completed?.Invoke(this, new InstanceEventArgs(Instance, "PublishNow")); }
/// <summary> /// Removes the document from the live site. /// </summary> private void HandleUnpublishNow() { bool success; var errorText = ""; int workflowStatus = Instance.Status; try { // Have to do this prior to the publish due to workaround for "unpublish at" handling. Instance.Status = (int)WorkflowStatus.Approved; Instance.CompletedDate = DateTime.Now; _instancesService.UpdateInstance(Instance); // Perform the unpublish IContent node = _contentService.GetById(Instance.NodeId); success = _contentService.UnPublish(node, Instance.TaskInstances.Last().ActionedByUserId ?? _utility.GetCurrentUser().Id); } catch (Exception e) { try { // rollback the process completion. Instance.Status = workflowStatus; Instance.CompletedDate = null; _instancesService.UpdateInstance(Instance); } catch (Exception ex) { errorText = $"Unable to unpublish document {_nodeName}: {ex.Message}"; Log.Error(errorText); } success = false; errorText = $"Unable to unpublish document {_nodeName}: {e.Message}"; Log.Error(errorText); } if (success) { _emailer.Send(Instance, EmailType.ApprovedAndCompleted); Log.Info("Successfully unpublished page " + Instance.Node.Name); Completed?.Invoke(this, new InstanceEventArgs(Instance, "UnpublishNow")); } else { throw new WorkflowException(errorText); } }
public void Can_Get_For_Date_Range(int count, int daysAgo, int expected) { IEnumerable <WorkflowInstancePoco> instances = Scaffold.Instances(count); List <WorkflowInstanceViewModel> results = _service.GetAllInstancesForDateRange(DateTime.Now.AddDays(daysAgo)); // all instances are incomplete, so return regardless of daysAgo value Assert.Equal(expected, results.Count); foreach (WorkflowInstancePoco instance in instances) { instance.CompletedDate = DateTime.Now.AddDays(daysAgo - 10); _service.UpdateInstance(instance); } results = _service.GetAllInstancesForDateRange(DateTime.Now.AddDays(daysAgo)); // all instances are now completed prior to the oldest date so should return an empty set Assert.Empty(results); }