/// <summary>
    /// Creates new or updates existing newsletter issue.
    /// </summary>
    public bool Save()
    {
        if (validated || IsValid())
        {
            IssueInfo issue = null;

            if (IssueID == 0)
            {
                // Initialize new issue
                issue = new IssueInfo();
                issue.IssueUnsubscribed = 0;
                issue.IssueSentEmails   = 0;
                issue.IssueNewsletterID = NewsletterID;
                issue.IssueSiteID       = CMSContext.CurrentSiteID;
            }
            else
            {
                issue = IssueInfoProvider.GetIssueInfo(IssueID);
            }

            if (issue != null)
            {
                issue.IssueTemplateID = TemplateID;
                issue.IssueShowInNewsletterArchive = chkShowInArchive.Checked;
                issue.IssueSenderName  = txtSenderName.Text.Trim();
                issue.IssueSenderEmail = txtSenderEmail.Text.Trim();

                // Saves content of editable region(s)
                // Get content from hidden field
                string   content = hdnIssueContent.Value;
                string[] regions = null;
                if (!string.IsNullOrEmpty(content))
                {
                    // Split content for each region, separator is '#|#'
                    regions = content.Split(new string[] { "#|#" }, StringSplitOptions.RemoveEmptyEntries);
                }
                issue.IssueText = IssueHelper.GetContentXML(regions);

                // Remove '#' from macros if included
                txtSubject.Text = txtSubject.Text.Trim().Replace("#%}", "%}");

                // Sign macros if included in the subject
                issue.IssueSubject = MacroResolver.AddSecurityParameters(txtSubject.Text, CMSContext.CurrentUser.UserName, null);

                // Save issue
                IssueInfoProvider.SetIssueInfo(issue);

                // Update IssueID
                IssueID = issue.IssueID;

                return(true);
            }
        }

        return(false);
    }
Example #2
0
    /// <summary>
    /// Creates new variant and raises "Add" event if specified.
    /// </summary>
    /// <param name="name">Name of new variant</param>
    /// <param name="issueId">ID of source issue on which the new variant will be based</param>
    private void RaiseOnAddEvent(string name, int issueId)
    {
        // Get main issue (original)
        int       currentIssuedId = IssueID;
        IssueInfo parentIssue     = IssueInfoProvider.GetOriginalIssue(currentIssuedId);

        // Allow modifying issues in idle state only
        if ((parentIssue == null) || (parentIssue.IssueStatus != IssueStatusEnum.Idle))
        {
            return;
        }

        // Get issue content specified by ID (if not found use original)
        IssueInfo contentIssue = null;

        if (issueId > 0)
        {
            if (issueId == parentIssue.IssueID)
            {
                contentIssue = parentIssue;
            }
            else
            {
                contentIssue = IssueInfoProvider.GetIssueInfo(issueId);
            }
        }

        NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo(parentIssue.IssueNewsletterID);

        // ID of the first child (if new A/B test is being created (i.e. parent and 2 children)
        int origVariantId = 0;

        // Check if current issue is variant issue
        if (!parentIssue.IssueIsABTest)
        {
            // Variant issue has not been created yet => create original and 2 child variants
            parentIssue.IssueIsABTest = true;

            // Create 1st variant based on parent issue, the 2nd variant will be created as ordinary variant below
            IssueInfo issueOrigVariant = parentIssue.Clone(true);
            issueOrigVariant.IssueVariantOfIssueID = parentIssue.IssueID;
            issueOrigVariant.IssueVariantName      = GetString("newsletter.abvariantoriginal");
            issueOrigVariant.IssueScheduledTaskID  = 0;
            IssueInfoProvider.SetIssueInfo(issueOrigVariant);
            // Create scheduled task for variant mail-out and update issue variant
            issueOrigVariant.IssueScheduledTaskID = CreateScheduledTask(issueOrigVariant);
            IssueInfoProvider.SetIssueInfo(issueOrigVariant);
            // Update parent issue
            IssueInfoProvider.SetIssueInfo(parentIssue);
            try
            {
                ObjectVersionManager.DestroyObjectHistory(parentIssue.ObjectType, parentIssue.IssueID);
            }
            catch (Exception ex)
            {
                EventLogProvider.LogException("Newsletter-AddVariant", "EXCEPTION", ex);
            }

            origVariantId = issueOrigVariant.IssueID;
        }

        // Variant issue has been created => create new variant only
        IssueInfo issueVariant = (contentIssue != null ? contentIssue.Clone(true) : parentIssue.Clone(true));

        issueVariant.IssueVariantName      = name;
        issueVariant.IssueVariantOfIssueID = parentIssue.IssueID;

        // Prepare content with empty regions if empty content will be used
        string[] regions = null;
        if ((contentIssue == null) && (newsletter != null))
        {
            EmailTemplateInfo template = EmailTemplateInfoProvider.GetEmailTemplateInfo(newsletter.NewsletterTemplateID);
            if (template != null)
            {
                bool          isValidRegionName;
                List <string> regionNames = new List <string>();
                EmailTemplateHelper.ValidateEditableRegions(template.TemplateBody, out isValidRegionName, out isValidRegionName, regionNames);
                for (int i = regionNames.Count - 1; i >= 0; i--)
                {
                    regionNames[i] = regionNames[i] + "::";
                }
                regions = regionNames.ToArray();
                // Set template ID (i.e. this template with these regions is used for current issue)
                issueVariant.IssueTemplateID = template.TemplateID;
            }
        }

        issueVariant.IssueText            = (contentIssue != null ? contentIssue.IssueText : IssueHelper.GetContentXML(regions));
        issueVariant.IssueScheduledTaskID = 0;
        IssueInfoProvider.SetIssueInfo(issueVariant);

        // Duplicate attachments and replace old guids with new guids in issue text if current variant issue is based on content of another
        if (contentIssue != null)
        {
            List <Guid> guids = new List <Guid>();
            MetaFileInfoProvider.CopyMetaFiles(contentIssue.IssueID, issueVariant.IssueID,
                                               (contentIssue.IssueIsVariant ? IssueInfo.OBJECT_TYPE_VARIANT : IssueInfo.OBJECT_TYPE),
                                               ObjectAttachmentsCategories.ISSUE, IssueInfo.OBJECT_TYPE_VARIANT, ObjectAttachmentsCategories.ISSUE, guids);
            if (guids.Count > 0)
            {
                for (int i = 0; i < guids.Count; i += 2)
                {
                    issueVariant.IssueText = LinkConverter.ReplaceInLink(issueVariant.IssueText, guids[i].ToString(), guids[i + 1].ToString());
                }
            }
        }

        // Create scheduled task for variant mail-out
        issueVariant.IssueScheduledTaskID = CreateScheduledTask(issueVariant);
        // Update issue variant
        IssueInfoProvider.SetIssueInfo(issueVariant);

        if (origVariantId > 0)
        {
            // New A/B test issue created => create new A/B test info
            ABTestInfo abi = new ABTestInfo
            {
                TestIssueID = parentIssue.IssueID, TestSizePercentage = 50, TestWinnerOption = ABTestWinnerSelectionEnum.OpenRate, TestSelectWinnerAfter = 60
            };
            ABTestInfoProvider.SetABTestInfo(abi);

            // Move attachments (meta files) from parent issue to first variant
            MetaFileInfoProvider.MoveMetaFiles(parentIssue.IssueID, origVariantId, IssueInfo.OBJECT_TYPE, ObjectAttachmentsCategories.ISSUE, IssueInfo.OBJECT_TYPE_VARIANT, ObjectAttachmentsCategories.ISSUE);
            MetaFileInfoProvider.MoveMetaFiles(parentIssue.IssueID, origVariantId, IssueInfo.OBJECT_TYPE_VARIANT, ObjectAttachmentsCategories.ISSUE, IssueInfo.OBJECT_TYPE_VARIANT, ObjectAttachmentsCategories.ISSUE);
        }

        if (OnAddVariant != null)
        {
            VariantEventArgs args = new VariantEventArgs(name, issueVariant.IssueID);
            OnAddVariant(this, args);
        }
    }
Example #3
0
    /// <summary>
    /// Creates new or updates existing newsletter issue.
    /// </summary>
    public bool Save()
    {
        if (mValidated || IsValid())
        {
            IssueInfo issue;

            if (IssueID == 0)
            {
                // Initialize new issue
                issue = new IssueInfo();
                issue.IssueUnsubscribed = 0;
                issue.IssueSentEmails   = 0;
                issue.IssueNewsletterID = NewsletterID;
                issue.IssueSiteID       = SiteContext.CurrentSiteID;
            }
            else
            {
                issue = IssueInfoProvider.GetIssueInfo(IssueID);
            }

            if (issue != null)
            {
                issue.IssueTemplateID = TemplateID;
                issue.IssueShowInNewsletterArchive = chkShowInArchive.Checked;
                issue.IssueSenderName  = txtSenderName.Text.Trim();
                issue.IssueSenderEmail = txtSenderEmail.Text.Trim();
                issue.IssueUseUTM      = chkIssueUseUTM.Checked;

                var normalizedUtmSource = Normalize(txtIssueUTMSource.Text.Trim());
                if (string.IsNullOrEmpty(normalizedUtmSource))
                {
                    normalizedUtmSource = Normalize(Newsletter.NewsletterName + "_" + txtSubject.Text.Trim());
                }
                txtIssueUTMSource.Text = issue.IssueUTMSource = normalizedUtmSource;

                if (radUTMCampaignNew.Checked)
                {
                    var normalizedUtmCampaign = Normalize(txtIssueUTMCampaign.Text.Trim());
                    if (string.IsNullOrEmpty(normalizedUtmCampaign))
                    {
                        normalizedUtmCampaign = Normalize(Newsletter.NewsletterName);
                    }
                    txtIssueUTMCampaign.Text = issue.IssueUTMCampaign = normalizedUtmCampaign;
                }
                else
                {
                    issue.IssueUTMCampaign = selectorUTMCampaign.Value.ToString().ToLower();
                }

                if (issue.IssueIsABTest)
                {
                    SynchronizeUTMParameters(issue);
                }

                // Saves content of editable region(s)
                // Get content from hidden field
                string   content = hdnIssueContent.Value;
                string[] regions = null;
                if (!string.IsNullOrEmpty(content))
                {
                    // Split content for each region, separator is '#|#'
                    regions = content.Split(new[] { "#|#" }, StringSplitOptions.RemoveEmptyEntries);
                }
                issue.IssueText = IssueHelper.GetContentXML(regions);

                // Remove '#' from macros if included
                txtSubject.Text = txtSubject.Text.Trim().Replace("#%}", "%}");

                // Sign macros if included in the subject
                issue.IssueSubject = MacroSecurityProcessor.AddSecurityParameters(txtSubject.Text, MembershipContext.AuthenticatedUser.UserName, null);

                // Save issue
                IssueInfoProvider.SetIssueInfo(issue);

                // Update IssueID
                IssueID = issue.IssueID;

                return(true);
            }
        }

        return(false);
    }