Exemplo n.º 1
0
    /// <summary>
    /// Button destroy history click.
    /// </summary>
    protected void btnDestroy_Click(object sender, EventArgs e)
    {
        var obj = Object;

        if (obj != null)
        {
            // Check permissions
            if (CheckPermissions && !AllowDestroy)
            {
                ShowError(GetString("History.ErrorNotAllowedToDestroy"));
                return;
            }

            var ti = obj.TypeInfo;

            ObjectVersionManager.DestroyObjectHistory(ti.ObjectType, obj.Generalized.ObjectID);

            string objType     = GetString("Objecttype." + ti.ObjectType.Replace(".", "_"));
            string description = String.Format(GetString("objectversioning.historydestroyed"), SqlHelper.GetSafeQueryString(obj.Generalized.ObjectDisplayName, false));

            var logData = new EventLogData(EventTypeEnum.Information, objType, "DESTROYHISTORY")
            {
                EventDescription = description,
                EventUrl         = RequestContext.RawURL
            };

            Service.Resolve <IEventLogService>().LogEvent(logData);

            ReloadData();
        }
        else
        {
            UIContext.EditedObject = null;
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Button destroy history click.
    /// </summary>
    protected void btnDestroy_Click(object sender, EventArgs e)
    {
        if (Object != null)
        {
            // Check permissions
            if (CheckPermissions && !AllowDestroy)
            {
                lblError.Text     = GetString("History.ErrorNotAllowedToDestroy");
                plcLabels.Visible = true;
                return;
            }
            ObjectVersionManager.DestroyObjectHistory(Object.ObjectType, Object.ObjectID);

            UserInfo currentUser = CMSContext.CurrentUser;
            string   objType     = GetString("Objecttype." + Object.ObjectType.Replace(".", "_"));
            string   description = GetString(String.Format("objectversioning.historydestroyed", SqlHelperClass.GetSafeQueryString(Object.ObjectDisplayName, false)));

            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, objType, "DESTROYHISTORY", HTTPHelper.GetAbsoluteUri(), description);

            ReloadData();
        }
        else
        {
            CMSPage.EditedObject = null;
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Destroys version history. Called when the "Destroy history" button is pressed.
    /// Expects the CreateVersionedObject method to be run first.
    /// </summary>
    private bool DestroyHistory()
    {
        // Get the css stylesheet
        CssStylesheetInfo stylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewVersionedStylesheet");

        if (stylesheet != null)
        {
            // Destroy version history
            ObjectVersionManager.DestroyObjectHistory(stylesheet.ObjectType, stylesheet.StylesheetID);

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// Button destroy history click.
    /// </summary>
    protected void btnDestroy_Click(object sender, EventArgs e)
    {
        if (Object != null)
        {
            // Check permissions
            if (CheckPermissions && !AllowDestroy)
            {
                ShowError(GetString("History.ErrorNotAllowedToDestroy"));
                return;
            }
            ObjectVersionManager.DestroyObjectHistory(Object.ObjectType, Object.Generalized.ObjectID);

            string objType     = GetString("Objecttype." + Object.ObjectType.Replace(".", "_"));
            string description = String.Format(GetString("objectversioning.historydestroyed"), SqlHelper.GetSafeQueryString(Object.Generalized.ObjectDisplayName, false));

            EventLogProvider.LogEvent(EventType.INFORMATION, objType, "DESTROYHISTORY", description, RequestContext.RawURL);

            ReloadData();
        }
        else
        {
            UIContext.EditedObject = null;
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void ugRecycleBin_OnAction(string actionName, object actionArgument)
    {
        int versionHistoryId = ValidationHelper.GetInteger(actionArgument, 0);

        actionName = actionName.ToLowerCSafe();

        switch (actionName)
        {
        case "restorechilds":
        case "restorewithoutbindings":
        case "restorecurrentsite":
            try
            {
                if (MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.globalpermissions", "RestoreObjects"))
                {
                    switch (actionName)
                    {
                    case "restorechilds":
                        ObjectVersionManager.RestoreObject(versionHistoryId, true);
                        break;

                    case "restorewithoutbindings":
                        ObjectVersionManager.RestoreObject(versionHistoryId, 0);
                        break;

                    case "restorecurrentsite":
                        ObjectVersionManager.RestoreObject(versionHistoryId, SiteContext.CurrentSiteID);
                        break;
                    }

                    ShowConfirmation(GetString("ObjectVersioning.Recyclebin.RestorationOK"));
                }
                else
                {
                    ShowError(ResHelper.GetString("objectversioning.recyclebin.restorationfailedpermissions"));
                }
            }
            catch (CodeNameNotUniqueException ex)
            {
                ShowError(String.Format(GetString("objectversioning.restorenotuniquecodename"), (ex.Object != null) ? "('" + ex.Object.ObjectCodeName + "')" : null));
            }
            catch (Exception ex)
            {
                ShowError(GetString("objectversioning.recyclebin.restorationfailed") + GetString("general.seeeventlog"));

                // Log to event log
                LogException("OBJECTRESTORE", ex);
            }
            break;

        case "destroy":
            ObjectVersionHistoryInfo verInfo = ObjectVersionHistoryInfoProvider.GetVersionHistoryInfo(versionHistoryId);
            if (verInfo != null)
            {
                // Get object site name
                string siteName = (CurrentSite != null) ? CurrentSite.SiteName : SiteInfoProvider.GetSiteName(verInfo.VersionObjectSiteID);

                if (CurrentUser.IsAuthorizedPerObject(PermissionsEnum.Destroy, verInfo.VersionObjectType, siteName))
                {
                    ObjectVersionManager.DestroyObjectHistory(verInfo.VersionObjectType, verInfo.VersionObjectID);
                    ShowConfirmation(GetString("ObjectVersioning.Recyclebin.DestroyOK"));
                }
                else
                {
                    ShowError(String.Format(ResHelper.GetString("objectversioning.recyclebin.destructionfailedpermissions"), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(verInfo.VersionObjectDisplayName))));
                }
            }
            break;
        }

        ugRecycleBin.ResetSelection();
    }
Exemplo n.º 6
0
    /// <summary>
    /// Empties recycle bin.
    /// </summary>
    private void EmptyBin(BinSettingsContainer settings)
    {
        // Begin log
        AddLog(ResHelper.GetString("Recyclebin.EmptyingBin", mCurrentCulture));

        try
        {
            DataSet recycleBin = GetRecycleBinSeletedItems(settings, "VersionID, VersionObjectType, VersionObjectID, VersionObjectDisplayName, VersionObjectSiteID");
            if (!DataHelper.DataSourceIsEmpty(recycleBin))
            {
                foreach (DataRow dr in recycleBin.Tables[0].Rows)
                {
                    string   versionObjType = Convert.ToString(dr["VersionObjectType"]);
                    string   objName        = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ValidationHelper.GetString(dr["VersionObjectDisplayName"], string.Empty)));
                    SiteInfo currentSite    = settings.Site;

                    string siteName;
                    if (currentSite != null)
                    {
                        siteName = currentSite.SiteName;
                    }
                    else
                    {
                        int siteId = ValidationHelper.GetInteger(dr["VersionObjectSiteID"], 0);
                        siteName = SiteInfoProvider.GetSiteName(siteId);
                    }

                    // Check permissions
                    UserInfo currentUserInfo = settings.User;
                    if (!currentUserInfo.IsAuthorizedPerObject(PermissionsEnum.Destroy, versionObjType, siteName))
                    {
                        CurrentError = String.Format(ResHelper.GetString("objectversioning.Recyclebin.DestructionFailedPermissions", mCurrentCulture), objName);
                        AddLog(CurrentError);
                    }
                    else
                    {
                        AddLog(ResHelper.GetString("general.object", mCurrentCulture) + " '" + objName + "'");

                        // Destroy the version
                        int versionObjId = ValidationHelper.GetInteger(dr["VersionObjectID"], 0);
                        ObjectVersionManager.DestroyObjectHistory(versionObjType, versionObjId);
                        LogContext.LogEventToCurrent(EventType.INFORMATION, "Objects", "DESTROYOBJECT", String.Format(ResHelper.GetString("objectversioning.Recyclebin.objectdestroyed"), objName), RequestContext.RawURL, currentUserInfo.UserID, currentUserInfo.UserName, 0, null, RequestContext.UserHostAddress, (currentSite != null) ? currentSite.SiteID : 0, SystemContext.MachineName, RequestContext.URLReferrer, RequestContext.UserAgent, DateTime.Now);
                    }
                }
                if (!String.IsNullOrEmpty(CurrentError))
                {
                    CurrentError = ResHelper.GetString("objectversioning.recyclebin.errorsomenotdestroyed", mCurrentCulture);
                    AddLog(CurrentError);
                }
                else
                {
                    CurrentInfo = ResHelper.GetString("ObjectVersioning.Recyclebin.DestroyOK", mCurrentCulture);
                    AddLog(CurrentInfo);
                }
            }
        }
        catch (ThreadAbortException ex)
        {
            if (!CMSThread.Stopped(ex))
            {
                // Log error
                CurrentError = "Error occurred: " + ResHelper.GetString("general.seeeventlog", mCurrentCulture);
                AddLog(CurrentError);

                // Log to event log
                LogException("EMPTYINGBIN", ex);
            }
        }
        catch (Exception ex)
        {
            // Log error
            CurrentError = "Error occurred: " + ResHelper.GetString("general.seeeventlog", mCurrentCulture);
            AddLog(CurrentError);

            // Log to event log
            LogException("EMPTYINGBIN", ex);
        }
    }
    /// <summary>
    /// Empties recycle bin.
    /// </summary>
    private void EmptyBin(object parameter)
    {
        // Begin log
        AddLog(ResHelper.GetString("Recyclebin.EmptyingBin", currentCulture));
        BinSettingsContainer settings        = (BinSettingsContainer)parameter;
        CurrentUserInfo      currentUserInfo = settings.User;
        SiteInfo             currentSite     = settings.Site;

        DataSet recycleBin = null;

        string where = IsSingleSite ? "VersionObjectSiteID IS NULL" : null;

        switch (settings.CurrentWhat)
        {
        case What.AllObjects:
            if (currentSite != null)
            {
                where = SqlHelper.AddWhereCondition(where, "VersionObjectSiteID = " + currentSite.SiteID, "OR");
            }
            where = GetWhereCondition(where);
            where = SqlHelper.AddWhereCondition(where, filter.WhereCondition);
            break;

        case What.SelectedObjects:
            List <string> toRestore = ugRecycleBin.SelectedItems;
            // Restore selected objects
            if (toRestore.Count > 0)
            {
                where = SqlHelper.GetWhereCondition("VersionID", toRestore);
            }
            break;
        }
        recycleBin = ObjectVersionHistoryInfoProvider.GetRecycleBin(where, null, -1, "VersionID, VersionObjectType, VersionObjectID, VersionObjectDisplayName, VersionObjectSiteID");

        try
        {
            if (!DataHelper.DataSourceIsEmpty(recycleBin))
            {
                foreach (DataRow dr in recycleBin.Tables[0].Rows)
                {
                    int    versionHistoryId = Convert.ToInt32(dr["VersionID"]);
                    string versionObjType   = Convert.ToString(dr["VersionObjectType"]);
                    string objName          = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ValidationHelper.GetString(dr["VersionObjectDisplayName"], string.Empty)));
                    string siteName         = null;
                    if (currentSite != null)
                    {
                        siteName = currentSite.SiteName;
                    }
                    else
                    {
                        int siteId = ValidationHelper.GetInteger(dr["VersionObjectSiteID"], 0);
                        siteName = SiteInfoProvider.GetSiteName(siteId);
                    }

                    // Check permissions
                    if (!currentUserInfo.IsAuthorizedPerObject(PermissionsEnum.Destroy, versionObjType, siteName))
                    {
                        CurrentError = String.Format(ResHelper.GetString("objectversioning.Recyclebin.DestructionFailedPermissions", currentCulture), objName);
                        AddLog(CurrentError);
                    }
                    else
                    {
                        AddLog(ResHelper.GetString("general.object", currentCulture) + " '" + objName + "'");

                        // Destroy the version
                        int versionObjId = ValidationHelper.GetInteger(dr["VersionObjectID"], 0);
                        ObjectVersionManager.DestroyObjectHistory(versionObjType, versionObjId);
                        LogContext.LogEvent(EventType.INFORMATION, "Objects", "DESTROYOBJECT", ResHelper.GetString("objectversioning.Recyclebin.objectdestroyed"), RequestContext.RawURL, currentUserInfo.UserID, currentUserInfo.UserName, 0, null, RequestContext.UserHostAddress, (currentSite != null) ? currentSite.SiteID : 0, SystemContext.MachineName, RequestContext.URLReferrer, RequestContext.UserAgent, DateTime.Now);
                    }
                }
                if (!String.IsNullOrEmpty(CurrentError))
                {
                    CurrentError = ResHelper.GetString("objectversioning.recyclebin.errorsomenotdestroyed", currentCulture);
                    AddLog(CurrentError);
                }
                else
                {
                    CurrentInfo = ResHelper.GetString("ObjectVersioning.Recyclebin.DestroyOK", currentCulture);
                    AddLog(CurrentInfo);
                }
            }
        }
        catch (ThreadAbortException ex)
        {
            string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty);
            if (state != CMSThread.ABORT_REASON_STOP)
            {
                // Log error
                CurrentError = "Error occurred: " + ResHelper.GetString("general.seeeventlog", currentCulture);
                AddLog(CurrentError);

                // Log to event log
                LogException("EMPTYINGBIN", ex);
            }
        }
        catch (Exception ex)
        {
            // Log error
            CurrentError = "Error occurred: " + ResHelper.GetString("general.seeeventlog", currentCulture);
            AddLog(CurrentError);

            // Log to event log
            LogException("EMPTYINGBIN", ex);
        }
    }
Exemplo n.º 8
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);
        }
    }
Exemplo n.º 9
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void ugRecycleBin_OnAction(string actionName, object actionArgument)
    {
        int versionHistoryId = ValidationHelper.GetInteger(actionArgument, 0);

        actionName = actionName.ToLower();

        switch (actionName)
        {
        case "restorechilds":
        case "restorewithoutbindings":
        case "restorecurrentsite":
            try
            {
                if (CMSContext.CurrentUser.IsAuthorizedPerResource("cms.globalpermissions", "RestoreObjects"))
                {
                    switch (actionName)
                    {
                    case "restorechilds":
                        ObjectVersionManager.RestoreObject(versionHistoryId, true);
                        break;

                    case "restorewithoutbindings":
                        ObjectVersionManager.RestoreObject(versionHistoryId, 0);
                        break;

                    case "restorecurrentsite":
                        ObjectVersionManager.RestoreObject(versionHistoryId, CMSContext.CurrentSiteID);
                        break;
                    }

                    lblInfo.Visible = true;
                    lblInfo.Text    = GetString("ObjectVersioning.Recyclebin.RestorationOK");
                }
                else
                {
                    lblError.Visible = true;
                    lblError.Text    = ResHelper.GetString("objectversioning.recyclebin.restorationfailedpermissions");
                }
            }
            catch (CodeNameNotUniqueException ex)
            {
                lblError.Visible = true;
                lblError.Text    = String.Format(GetString("objectversioning.restorenotuniquecodename"), (ex.Object != null) ? "('" + ex.Object.ObjectCodeName + "')" : null);
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text    = GetString("objectversioning.recyclebin.restorationfailed") + GetString("general.seeeventlog");

                // Log to event log
                LogException("OBJECTRESTORE", ex);
            }
            break;

        case "destroy":

            ObjectVersionHistoryInfo verInfo = ObjectVersionHistoryInfoProvider.GetVersionHistoryInfo(versionHistoryId);

            // Get object site name
            string siteName = null;
            if (CurrentSite != null)
            {
                siteName = CurrentSite.SiteName;
            }
            else
            {
                siteName = SiteInfoProvider.GetSiteName(verInfo.VersionObjectSiteID);
            }

            if ((verInfo != null) && CurrentUser.IsAuthorizedPerObject(PermissionsEnum.Destroy, verInfo.VersionObjectType, siteName))
            {
                ObjectVersionManager.DestroyObjectHistory(verInfo.VersionObjectType, verInfo.VersionObjectID);
                lblInfo.Visible = true;
                lblInfo.Text    = GetString("ObjectVersioning.Recyclebin.DestroyOK");
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = String.Format(ResHelper.GetString("objectversioning.recyclebin.destructionfailedpermissions"), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(verInfo.VersionObjectDisplayName)));
            }
            break;
        }

        ugRecycleBin.ResetSelection();
        pnlUpdateInfo.Update();
        ReloadFilter((CurrentSite != null) ? CurrentSite.SiteID : -1, IsSingleSite, false);
    }