diff --git a/PivotSubscriptions/EventLog.cls b/PivotSubscriptions/EventLog.cls index 1135c45..bc3e769 100644 --- a/PivotSubscriptions/EventLog.cls +++ b/PivotSubscriptions/EventLog.cls @@ -3,7 +3,7 @@ Class PivotSubscriptions.EventLog Extends %Persistent { /// Event Type covers: create, update, delete, sendSubscription, and tableError -Property EventType As %String(VALUELIST = ",create,update,delete,sendSubscription,tableError,unsubscribe"); +Property EventType As %String(VALUELIST = ",create,update,delete,sendSubscription,sendNow,tableError,unsubscribe"); Property StartTime As %TimeStamp [ InitialExpression = {$zdt($h, 3, 1)} ]; @@ -31,8 +31,10 @@ Property Subscription As PivotSubscriptions.Subscription; Property GUID As %String [ InitialExpression = {$System.Util.CreateGUID()} ]; +Property RunOnce As %Boolean; + /// Takes in info about an Alert Task and logs the information to the TaskLog -ClassMethod CreateEvent(pType, pSubscriptionId, pUser, pPivot, pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName, ByRef pEvent) As %Status +ClassMethod CreateEvent(pType, pSubscriptionId, pUser, pPivot, pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName, pRunOnce, ByRef pEvent) As %Status { Set tSC=$$$OK @@ -42,6 +44,7 @@ ClassMethod CreateEvent(pType, pSubscriptionId, pUser, pPivot, pDayOfWeek, pHour Set tEventLog.UserName=pUser Set tEventLog.Pivot=pPivot Set tEventLog.Name=pName + Set tEventLog.RunOnce=pRunOnce Set tEventLog.DayOfWeek=pDayOfWeek Set tEventLog.Hour=pHour @@ -67,7 +70,7 @@ Method UpdateStatus(pStatus) As %Status Quit tSC } -Method UpdateEvent(pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName) As %Status +Method UpdateEvent(pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName, pRunOnce) As %Status { Set tSC=$$$OK @@ -77,6 +80,7 @@ Method UpdateEvent(pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName) As %Stat Set ..Format=pFormat Set ..Emails=pEmails Set ..Name=pName + Set ..RunOnce=pRunOnce Set tSC=..%Save() @@ -153,6 +157,9 @@ Storage Default GUID + +RunOnce + ^PivotSubscriptions.EventLogD EventLogDefaultData diff --git a/PivotSubscriptions/Installer.cls b/PivotSubscriptions/Installer.cls index 6a5f55e..651e336 100644 --- a/PivotSubscriptions/Installer.cls +++ b/PivotSubscriptions/Installer.cls @@ -1,7 +1,7 @@ Class PivotSubscriptions.Installer { -ClassMethod RunInstaller(pRootDir) +ClassMethod RunInstaller(pRootDir = "") { Set tSC=$$$OK @@ -16,7 +16,7 @@ ClassMethod RunInstaller(pRootDir) Set tPage="PivotSubscriptions.UI.SubscriptionManager.zen" Set tItem.href=$system.CSP.GetPortalApp($namespace,tPage)_tPage Set tItem.title="Pivot Subscriptions" - Set tItem.bookCover="{background: {style:'background:white;',src:'covers/PivotSubscriptions_Cover.png'},header: {text:'$type',style:'display: none;'},title: {text:'$title',style:'display: none;'},image: {style:'display: none;',src:'deepsee/ds2_globe_44.png',imageStyle:'width:64px;height:64px;'},subtitle: {style:'display: none;'},footer: {text:'$owner',style:'display: none;'}}" + Set tItem.bookCover="{background: {style:'background:white;',src:'covers/PivotSubscriptions_Cover.png'},header: {text:'$type',style:'display: none;'},title: {text:'$title',style:'display: none;'},image: {style:'display: none;',src:'deepsee/ds2_globe_44.png',imageStyle:'width:64px;height:64px;'},subtitle: {text:'"_##class(PivotSubscriptions.Utils).GetVersion()_"',style:'font-size:9px;top:179px;'},footer: {text:'$owner',style:'display: none;'}}" Set tSC=tItem.%Save() If $$$ISERR(tSC) Quit tSC diff --git a/PivotSubscriptions/Subscription.cls b/PivotSubscriptions/Subscription.cls index e294178..e7fb164 100644 --- a/PivotSubscriptions/Subscription.cls +++ b/PivotSubscriptions/Subscription.cls @@ -25,18 +25,20 @@ Property CustomFilters As array Of %String(MAXLEN = ""); Property CustomEmailText As %String(MAXLEN = ""); +Property RunOnce As %Boolean [ InitialExpression = 0 ]; + Method Unsubscribe(pEmail) As %Status { Set tSC=$$$OK - Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("unsubscribe",..%Id(),$username,..Pivot,..DayOfWeek,..Hour,..Minute,..Format,pEmail,..Name,.tEvent) + Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("unsubscribe",..%Id(),$username,..Pivot,..DayOfWeek,..Hour,..Minute,..Format,pEmail,..Name,..RunOnce,.tEvent) Set tEmailList=$LFS(..Emails,",") If $LL(tEmailList)=1 { If ..Emails=pEmail { // This is the only Email for the subscription, delete subscription - Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("delete",..%Id(),$username,..Pivot,..DayOfWeek,..Hour,..Minute,..Format,..Emails,..Name,.tDeleteEvent) + Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("delete",..%Id(),$username,..Pivot,..DayOfWeek,..Hour,..Minute,..Format,..Emails,..Name,..RunOnce,.tDeleteEvent) Set tSC=##class(PivotSubscriptions.Subscription).%DeleteId(..%Id()) Do tDeleteEvent.UpdateStatus(tSC) Do tEvent.UpdateStatus(tSC) @@ -106,6 +108,9 @@ Storage Default CustomEmailText + +RunOnce + ^PivotSubscriptions.SubD SubscriptionDefaultData diff --git a/PivotSubscriptions/Task.cls b/PivotSubscriptions/Task.cls index e3e149a..1c11bb9 100644 --- a/PivotSubscriptions/Task.cls +++ b/PivotSubscriptions/Task.cls @@ -16,9 +16,9 @@ Method OnTask() As %Status // Ignore minute for testing purposes // This will allow the task to be run on demand and send emails immediately // Leaving DayOfWeek and Hour so the scheduled task does not spam emails - Set tRS=##class(%SQL.Statement).%ExecDirect(,"SELECT ID,Emails,Name,Pivot,Format,DayOfWeek,""Hour"",""Minute"" FROM PivotSubscriptions.Subscription WHERE DayOfWeek[? AND ""Hour""=?",tDayOfWeek,tHour) + Set tRS=##class(%SQL.Statement).%ExecDirect(,"SELECT ID,Emails,Name,Pivot,Format,DayOfWeek,""Hour"",""Minute"",RunOnce FROM PivotSubscriptions.Subscription WHERE DayOfWeek[? AND ""Hour""=?",tDayOfWeek,tHour) } Else { - Set tRS=##class(%SQL.Statement).%ExecDirect(,"SELECT ID,Emails,Name,Pivot,Format,DayOfWeek,""Hour"",""Minute"" FROM PivotSubscriptions.Subscription WHERE DayOfWeek[? AND ""Hour""=? AND ""Minute""=?",tDayOfWeek,tHour,tMinute) + Set tRS=##class(%SQL.Statement).%ExecDirect(,"SELECT ID,Emails,Name,Pivot,Format,DayOfWeek,""Hour"",""Minute"",RunOnce FROM PivotSubscriptions.Subscription WHERE DayOfWeek[? AND ""Hour""=? AND ""Minute""=?",tDayOfWeek,tHour,tMinute) } // Loop through Subscription results and send emails. @@ -31,14 +31,21 @@ Method OnTask() As %Status Set tHour=tRS.%Get("Hour") Set tMinute=tRS.%Get("Minute") Set tName=tRS.%Get("Name") + Set tRunOnce=tRS.%Get("RunOnce") - Set tSC = ##class(PivotSubscriptions.Task).SendSubscription(tID,tPivot,tEmails,tFormat,tDayOfWeek,tHour,tMinute,tName) + Set tSC = ##class(PivotSubscriptions.Task).SendSubscription(tID,0,tPivot,tEmails,tFormat,tDayOfWeek,tHour,tMinute,tName) + + If tRunOnce { + Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("delete",tID,$username,tPivot,tDayOfWeek,tHour,tMinute,tFormat,tEmails,tName,tRunOnce,.tDeleteEvent) + Set tSC=##class(PivotSubscriptions.Subscription).%DeleteId(tID) + Do tDeleteEvent.UpdateStatus(tSC) + } } Quit tSC } -ClassMethod SendSubscription(pID, pPivot As %String, pEmails As %String, pFormat As %String, pDayOfWeek, pHour, pMinute, pName) As %Status +ClassMethod SendSubscription(pID, pSendNow As %Boolean = 0, pPivot As %String, pEmails As %String, pFormat As %String, pDayOfWeek, pHour, pMinute, pName) As %Status { Set tSC=$$$OK @@ -47,7 +54,7 @@ ClassMethod SendSubscription(pID, pPivot As %String, pEmails As %String, pFormat } Try { - Set tSC=##class(PivotSubscriptions.Task).SendEmail(pID,pPivot,pEmails,pFormat,pName) + Set tSC=##class(PivotSubscriptions.Task).SendEmail(pID,pSendNow,pPivot,pEmails,pFormat,pName) } Catch ex { Set tSC=ex.AsStatus() } @@ -55,10 +62,12 @@ ClassMethod SendSubscription(pID, pPivot As %String, pEmails As %String, pFormat Quit tSC } -ClassMethod SendEmail(pID, pPivot As %String, pEmails As %String, pFormat As %String, pName As %String) As %Status +ClassMethod SendEmail(pID, pSendNow As %Boolean = 0, pPivot As %String, pEmails As %String, pFormat As %String, pName As %String) As %Status { Set tSC=$$$OK Set tFilename="" + + Set tEventType=$Select(pSendNow:"sendNow",1:"sendSubscription") Set mdx=##class(%DeepSee.Utils).%GetMDXFromPivot(pPivot,.tSC,0) Set tSubscription=##class(PivotSubscriptions.Subscription).%OpenId(pID) @@ -67,7 +76,7 @@ ClassMethod SendEmail(pID, pPivot As %String, pEmails As %String, pFormat As %St For tCount=1:1:$l(pEmails,",") { Set tEmail=$p(pEmails,",",tCount) - Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("sendSubscription",pID,$username,pPivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tEmail,pName,.pEvent) + Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent(tEventType,pID,$username,pPivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tEmail,pName,tSubscription.RunOnce,.pEvent) If $$$ISERR(tSC) Quit tSC Try { diff --git a/PivotSubscriptions/UI/Dialog/EditSubscription.cls b/PivotSubscriptions/UI/Dialog/EditSubscription.cls index e2b024d..015a81e 100644 --- a/PivotSubscriptions/UI/Dialog/EditSubscription.cls +++ b/PivotSubscriptions/UI/Dialog/EditSubscription.cls @@ -34,6 +34,8 @@ XData dialogBody [ XMLNamespace = "http://www.intersystems.com/zen" ]