protected void btnOk_OnClick(object sender, EventArgs e) { pnlLog.Visible = true; CurrentError = string.Empty; int actionValue = ValidationHelper.GetInteger(drpAction.SelectedValue, 0); Action action = (Action)actionValue; int whatValue = ValidationHelper.GetInteger(drpWhat.SelectedValue, 0); currentWhat = (What)whatValue; BinSettingsContainer binSettings = new BinSettingsContainer(CurrentUser, currentWhat, CurrentSite); switch (currentWhat) { case What.SelectedObjects: if (ugRecycleBin.SelectedItems.Count <= 0) { return; } binSettings.SelectedItems = ugRecycleBin.SelectedItems; break; } switch (action) { case Action.Restore: case Action.RestoreToCurrentSite: case Action.RestoreWithoutSiteBindings: { ctlAsyncLog.TitleText = GetString("objectversioning.Recyclebin.Restoringobjects"); switch (action) { case Action.Restore: RunAsync(p => RestoreWithChildren(binSettings)); break; case Action.RestoreToCurrentSite: RunAsync(p => RestoreToCurrentSite(binSettings)); break; case Action.RestoreWithoutSiteBindings: RunAsync(p => RestoreWithoutSiteBindings(binSettings)); break; } } break; case Action.Delete: { ctlAsyncLog.TitleText = GetString("recyclebin.emptyingbin"); RunAsync(p => EmptyBin(binSettings)); } break; } }
private DataSet GetRecycleBinSeletedItems(BinSettingsContainer settings, string columns) { var where = new WhereCondition(); switch (settings.CurrentWhat) { case What.AllObjects: if (IsSingleSite) { where.WhereNull("VersionObjectSiteID"); } if (settings.Site != null) { where.Or().WhereEquals("VersionObjectSiteID", settings.Site.SiteID); } // Wrap filter condition with brackets where.Where(new WhereCondition(filter.WhereCondition) { WhereIsComplex = true }); where = GetWhereCondition(where); break; case What.SelectedObjects: // Restore selected objects var toRestore = settings.SelectedItems; where.WhereIn("VersionID", toRestore); break; } return(ObjectVersionHistoryInfoProvider.GetRecycleBin(where.ToString(true), OrderBy, -1, columns)); }
/// <summary> /// Restores documents selected in UniGrid. /// </summary> private void Restore(object parameter) { try { // Begin log AddLog(ResHelper.GetString("Recyclebin.RestoringDocuments", currentCulture)); BinSettingsContainer settings = (BinSettingsContainer)parameter; DataSet recycleBin = null; switch (settings.CurrentWhat) { case What.AllDocuments: DateTime modifiedFrom = DateTimeHelper.ZERO_TIME; DateTime modifiedTo = DateTimeHelper.ZERO_TIME; SetDocumentAge(ref modifiedFrom, ref modifiedTo); recycleBin = VersionHistoryInfoProvider.GetRecycleBin((mSelectedSite != null) ? mSelectedSite.SiteID : 0, 0, GetWhereCondition(filter.WhereCondition), "CMS_VersionHistory.DocumentNamePath ASC", -1, "VersionHistoryID, CMS_VersionHistory.DocumentNamePath, CMS_VersionHistory.VersionDocumentName", modifiedFrom, modifiedTo); break; case What.SelectedDocuments: List <string> toRestore = ugRecycleBin.SelectedItems; // Restore selected documents if (toRestore.Count > 0) { string where = SqlHelper.GetWhereCondition("VersionHistoryID", toRestore); recycleBin = VersionHistoryInfoProvider.GetRecycleBin(0, 0, where, "CMS_VersionHistory.DocumentNamePath ASC", -1, "VersionHistoryID, CMS_VersionHistory.DocumentNamePath, CMS_VersionHistory.VersionDocumentName"); } break; } if (!DataHelper.DataSourceIsEmpty(recycleBin)) { RestoreDataSet(settings.User, recycleBin); } } catch (ThreadAbortException ex) { string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty); if (state == CMSThread.ABORT_REASON_STOP) { // When canceled CurrentInfo = ResHelper.GetString("Recyclebin.RestorationCanceled", currentCulture); AddLog(CurrentInfo); } else { // Log error CurrentError = ResHelper.GetString("Recyclebin.RestorationFailed", currentCulture) + ": " + ex.Message; AddLog(CurrentError); } } catch (Exception ex) { // Log error CurrentError = ResHelper.GetString("Recyclebin.RestorationFailed", currentCulture) + ": " + ex.Message; AddLog(CurrentError); } }
/// <summary> /// Restores documents selected in UniGrid. /// </summary> private void Restore(object parameter) { try { // Begin log AddLog(ResHelper.GetString("Recyclebin.RestoringDocuments", mCurrentCulture)); BinSettingsContainer settings = (BinSettingsContainer)parameter; DataSet recycleBin = null; switch (settings.CurrentWhat) { case What.AllDocuments: DateTime modifiedFrom = DateTimeHelper.ZERO_TIME; DateTime modifiedTo = DateTimeHelper.ZERO_TIME; SetDocumentAge(ref modifiedFrom, ref modifiedTo); recycleBin = VersionHistoryInfoProvider.GetRecycleBin((mSelectedSite != null) ? mSelectedSite.SiteID : 0, 0, GetWhereCondition(filter.WhereCondition), "CMS_VersionHistory.DocumentNamePath ASC", -1, "VersionHistoryID, CMS_VersionHistory.DocumentNamePath, CMS_VersionHistory.VersionDocumentName", modifiedFrom, modifiedTo); break; case What.SelectedDocuments: // Restore selected documents var toRestore = settings.SelectedItems; if ((toRestore != null) && (toRestore.Count > 0)) { string where = new WhereCondition().WhereIn("VersionHistoryID", toRestore).ToString(true); recycleBin = VersionHistoryInfoProvider.GetRecycleBin(0, 0, where, "CMS_VersionHistory.DocumentNamePath ASC", -1, "VersionHistoryID, CMS_VersionHistory.DocumentNamePath, CMS_VersionHistory.VersionDocumentName"); } break; } if (!DataHelper.DataSourceIsEmpty(recycleBin)) { RestoreDataSet(settings.User, recycleBin); } } catch (ThreadAbortException ex) { if (CMSThread.Stopped(ex)) { // When canceled CurrentInfo = ResHelper.GetString("Recyclebin.RestorationCanceled", mCurrentCulture); AddLog(CurrentInfo); } else { // Log error LogException("RESTOREDOC", ex); } } catch (Exception ex) { // Log error LogException("RESTOREDOC", ex); } }
/// <summary> /// Restores objects selected in UniGrid. /// </summary> private void Restore(BinSettingsContainer settings, Action action) { try { // Begin log AddLog(ResHelper.GetString("objectversioning.recyclebin.restoringobjects", mCurrentCulture)); if (settings.User.IsAuthorizedPerResource("cms.globalpermissions", "RestoreObjects")) { DataSet recycleBin = GetRecycleBinSeletedItems(settings, "VersionID, VersionObjectDisplayName, VersionObjectType, VersionObjectID"); if (!DataHelper.DataSourceIsEmpty(recycleBin)) { RestoreDataSet(recycleBin, action); } } else { CurrentError = ResHelper.GetString("objectversioning.recyclebin.restorationfailedpermissions"); AddLog(CurrentError); } } catch (ThreadAbortException ex) { if (CMSThread.Stopped(ex)) { // When canceled CurrentInfo = ResHelper.GetString("Recyclebin.RestorationCanceled", mCurrentCulture); AddLog(CurrentInfo); } else { // Log error CurrentError = ResHelper.GetString("objectversioning.recyclebin.restorationfailed", mCurrentCulture) + ": " + ResHelper.GetString("general.seeeventlog", mCurrentCulture); AddLog(CurrentError); // Log to event log LogException("OBJECTRESTORE", ex); } } catch (Exception ex) { // Log error CurrentError = ResHelper.GetString("objectversioning.recyclebin.restorationfailed", mCurrentCulture) + ": " + ResHelper.GetString("general.seeeventlog", mCurrentCulture); AddLog(CurrentError); // Log to event log LogException("OBJECTRESTORE", 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); } }
/// <summary> /// Restores set of given version histories. /// </summary> /// <param name="settings">Recycle bin settings object</param> /// <param name="recycleBin">DataSet with nodes to restore</param> /// <param name="action">Action to be performed</param> private void RestoreDataSet(BinSettingsContainer settings, DataSet recycleBin, Action action) { // Result flags bool resultOK = true; if (!DataHelper.DataSourceIsEmpty(recycleBin)) { // Restore all objects foreach (DataRow dataRow in recycleBin.Tables[0].Rows) { int versionId = ValidationHelper.GetInteger(dataRow["VersionID"], 0); // Log current event string taskTitle = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ValidationHelper.GetString(dataRow["VersionObjectDisplayName"], string.Empty))); // Restore object if (versionId > 0) { GeneralizedInfo restoredObj = null; try { switch (action) { case Action.Restore: restoredObj = ObjectVersionManager.RestoreObject(versionId, true); break; case Action.RestoreToCurrentSite: restoredObj = ObjectVersionManager.RestoreObject(versionId, SiteContext.CurrentSiteID); break; case Action.RestoreWithoutSiteBindings: restoredObj = ObjectVersionManager.RestoreObject(versionId, 0); break; } } catch (CodeNameNotUniqueException ex) { CurrentError = String.Format(GetString("objectversioning.restorenotuniquecodename"), (ex.Object != null) ? "('" + ex.Object.ObjectCodeName + "')" : null); AddLog(CurrentError); } if (restoredObj != null) { AddLog(ResHelper.GetString("general.object", currentCulture) + " '" + taskTitle + "'"); } else { // Set result flag if (resultOK) { resultOK = false; } } } } } if (resultOK) { CurrentInfo = ResHelper.GetString("ObjectVersioning.Recyclebin.RestorationOK", currentCulture); AddLog(CurrentInfo); } else { CurrentError = ResHelper.GetString("objectversioning.recyclebin.restorationfailed", currentCulture); AddLog(CurrentError); } }
/// <summary> /// Restores objects selected in UniGrid. /// </summary> private void Restore(object parameter, Action action) { try { // Begin log AddLog(ResHelper.GetString("objectversioning.recyclebin.restoringobjects", currentCulture)); BinSettingsContainer settings = (BinSettingsContainer)parameter; DataSet recycleBin = null; if (settings.User.IsAuthorizedPerResource("cms.globalpermissions", "RestoreObjects")) { string where = IsSingleSite ? "VersionObjectSiteID IS NULL" : null; switch (settings.CurrentWhat) { case What.AllObjects: if (settings.Site != null) { where = SqlHelper.AddWhereCondition(where, "VersionObjectSiteID = " + settings.Site.SiteID, "OR"); } where = SqlHelper.AddWhereCondition(where, filter.WhereCondition); recycleBin = ObjectVersionHistoryInfoProvider.GetRecycleBin(GetWhereCondition(where), null, -1, "VersionID, VersionObjectDisplayName, VersionObjectType, VersionObjectID"); break; case What.SelectedObjects: List <string> toRestore = ugRecycleBin.SelectedItems; // Restore selected objects if (toRestore.Count > 0) { where = SqlHelper.GetWhereCondition("VersionID", toRestore); recycleBin = ObjectVersionHistoryInfoProvider.GetRecycleBin(where, OrderBy, -1, "VersionID, VersionObjectDisplayName, VersionObjectType, VersionObjectID"); } break; } if (!DataHelper.DataSourceIsEmpty(recycleBin)) { RestoreDataSet(settings, recycleBin, action); } } else { CurrentError = ResHelper.GetString("objectversioning.recyclebin.restorationfailedpermissions"); AddLog(CurrentError); } } catch (ThreadAbortException ex) { string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty); if (state == CMSThread.ABORT_REASON_STOP) { // When canceled CurrentInfo = ResHelper.GetString("Recyclebin.RestorationCanceled", currentCulture); AddLog(CurrentInfo); } else { // Log error CurrentError = ResHelper.GetString("objectversioning.recyclebin.restorationfailed", currentCulture) + ": " + ResHelper.GetString("general.seeeventlog", currentCulture); AddLog(CurrentError); // Log to event log LogException("OBJECTRESTORE", ex); } } catch (Exception ex) { // Log error CurrentError = ResHelper.GetString("objectversioning.recyclebin.restorationfailed", currentCulture) + ": " + ResHelper.GetString("general.seeeventlog", currentCulture); AddLog(CurrentError); // Log to event log LogException("OBJECTRESTORE", 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; DataSet recycleBin = null; string where = null; DateTime modifiedFrom = DateTimeHelper.ZERO_TIME; DateTime modifiedTo = DateTimeHelper.ZERO_TIME; switch (settings.CurrentWhat) { case What.AllDocuments: SetDocumentAge(ref modifiedFrom, ref modifiedTo); where = GetWhereCondition(string.Empty); break; case What.SelectedDocuments: ArrayList toRestore = ugRecycleBin.SelectedItems; // Restore selected documents if (toRestore.Count > 0) { where = SqlHelperClass.GetWhereCondition("VersionHistoryID", (string[])toRestore.ToArray(typeof(string))); } break; } recycleBin = VersionHistoryInfoProvider.GetRecycleBin((mSelectedSite != null) ? mSelectedSite.SiteID : 0, 0, where, "DocumentNamePath ASC", -1, null, modifiedFrom, modifiedTo); try { if (!DataHelper.DataSourceIsEmpty(recycleBin)) { TreeProvider tree = new TreeProvider(currentUserInfo); tree.AllowAsyncActions = false; VersionManager verMan = new VersionManager(tree); foreach (DataRow dr in recycleBin.Tables[0].Rows) { int versionHistoryId = Convert.ToInt32(dr["VersionHistoryID"]); string documentNamePath = ValidationHelper.GetString(dr["DocumentNamePath"], string.Empty); // Check permissions TreeNode tn = null; if (!IsAuthorizedPerDocument(versionHistoryId, "Destroy", currentUser, out tn, verMan)) { CurrentError = String.Format(ResHelper.GetString("Recyclebin.DestructionFailedPermissions", currentCulture), documentNamePath); AddLog(CurrentError); } else { AddLog(ResHelper.GetString("general.document", currentCulture) + "'" + HTMLHelper.HTMLEncode(ValidationHelper.GetString(dr["DocumentNamePath"], string.Empty)) + "'"); // Destroy the version verMan.DestroyDocumentHistory(ValidationHelper.GetInteger(dr["DocumentID"], 0)); LogContext.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "DESTROYDOC", currentUser.UserID, currentUser.UserName, 0, null, HTTPHelper.UserHostAddress, string.Format(ResHelper.GetString("Recyclebin.documentdestroyed"), documentNamePath), currentSite.SiteID, HTTPHelper.GetAbsoluteUri(), HTTPHelper.MachineName, HTTPHelper.GetUrlReferrer(), HTTPHelper.GetUserAgent()); } } if (!String.IsNullOrEmpty(CurrentError)) { CurrentError = ResHelper.GetString("recyclebin.errorsomenotdestroyed", currentCulture); AddLog(CurrentError); } else { CurrentInfo = ResHelper.GetString("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: " + ex.Message; AddLog(CurrentError); } } catch (Exception ex) { // Log error CurrentError = "Error occurred: " + ex.Message; AddLog(CurrentError); } }
/// <summary> /// Restores objects selected in UniGrid with site bindings and children. /// </summary> private void RestoreWithChildren(BinSettingsContainer settings) { Restore(settings, Action.Restore); }
/// <summary> /// Restores objects selected in UniGrid with binding to current site. /// </summary> private void RestoreToCurrentSite(BinSettingsContainer settings) { Restore(settings, Action.RestoreToCurrentSite); }
/// <summary> /// Restores objects selected in UniGrid without site bindings. /// </summary> private void RestoreWithoutSiteBindings(BinSettingsContainer settings) { Restore(settings, Action.RestoreWithoutSiteBindings); }
/// <summary> /// Empties recycle bin. /// </summary> private void EmptyBin(object parameter) { // Begin log AddLog(ResHelper.GetString("Recyclebin.EmptyingBin", mCurrentCulture)); BinSettingsContainer settings = (BinSettingsContainer)parameter; CurrentUserInfo currentUserInfo = settings.User; string where = null; DateTime modifiedFrom = DateTimeHelper.ZERO_TIME; DateTime modifiedTo = DateTimeHelper.ZERO_TIME; switch (settings.CurrentWhat) { case What.AllDocuments: SetDocumentAge(ref modifiedFrom, ref modifiedTo); where = GetWhereCondition(filter.WhereCondition); break; case What.SelectedDocuments: // Restore selected documents var toRestore = settings.SelectedItems; if ((toRestore != null) && (toRestore.Count > 0)) { where = new WhereCondition().WhereIn("VersionHistoryID", toRestore).ToString(true); } break; } DataSet recycleBin = VersionHistoryInfoProvider.GetRecycleBin((mSelectedSite != null) ? mSelectedSite.SiteID : 0, 0, @where, "DocumentNamePath ASC", -1, null, modifiedFrom, modifiedTo); try { if (!DataHelper.DataSourceIsEmpty(recycleBin)) { TreeProvider tree = new TreeProvider(currentUserInfo); tree.AllowAsyncActions = false; VersionManager verMan = VersionManager.GetInstance(tree); foreach (DataRow dr in recycleBin.Tables[0].Rows) { int versionHistoryId = Convert.ToInt32(dr["VersionHistoryID"]); string documentNamePath = ValidationHelper.GetString(dr["DocumentNamePath"], string.Empty); // Check permissions TreeNode tn; if (!IsAuthorizedPerDocument(versionHistoryId, "Destroy", mCurrentUser, out tn, verMan)) { CurrentError = String.Format(ResHelper.GetString("Recyclebin.DestructionFailedPermissions", mCurrentCulture), documentNamePath); AddLog(CurrentError); } else { AddLog(ResHelper.GetString("general.document", mCurrentCulture) + "'" + HTMLHelper.HTMLEncode(ValidationHelper.GetString(dr["DocumentNamePath"], string.Empty)) + "'"); // Destroy the version verMan.DestroyDocumentHistory(ValidationHelper.GetInteger(dr["DocumentID"], 0)); LogContext.LogEventToCurrent(EventType.INFORMATION, "Content", "DESTROYDOC", string.Format(ResHelper.GetString("Recyclebin.documentdestroyed"), documentNamePath), RequestContext.RawURL, mCurrentUser.UserID, mCurrentUser.UserName, 0, null, RequestContext.UserHostAddress, SiteContext.CurrentSiteID, SystemContext.MachineName, RequestContext.URLReferrer, RequestContext.UserAgent, DateTime.Now); } } if (!String.IsNullOrEmpty(CurrentError)) { CurrentError = ResHelper.GetString("recyclebin.errorsomenotdestroyed", mCurrentCulture); AddLog(CurrentError); } else { CurrentInfo = ResHelper.GetString("recyclebin.destroyok", mCurrentCulture); AddLog(CurrentInfo); } } } catch (ThreadAbortException ex) { if (!CMSThread.Stopped(ex)) { // Log error LogException("DESTROYDOC", ex); } } catch (Exception ex) { // Log error LogException("DESTROYDOC", ex); } }
/// <summary> /// Restores set of given version histories. /// </summary> /// <param name="currentUserInfo">Current user info</param> /// <param name="recycleBin">DataSet with nodes to restore</param> private void RestoreDataSet(BinSettingsContainer settings, DataSet recycleBin, Action action) { // Result flags bool resultOK = true; if (!DataHelper.DataSourceIsEmpty(recycleBin)) { // Restore all objects foreach (DataRow dataRow in recycleBin.Tables[0].Rows) { int versionId = ValidationHelper.GetInteger(dataRow["VersionID"], 0); // Log current event string taskTitle = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ValidationHelper.GetString(dataRow["VersionObjectDisplayName"], string.Empty))); // Restore object if (versionId > 0) { GeneralizedInfo restoredObj = null; try { switch (action) { case Action.Restore: restoredObj = ObjectVersionManager.RestoreObject(versionId, true); break; case Action.RestoreToCurrentSite: restoredObj = ObjectVersionManager.RestoreObject(versionId, CMSContext.CurrentSiteID); break; case Action.RestoreWithoutSiteBindings: restoredObj = ObjectVersionManager.RestoreObject(versionId, 0); break; } } catch (CodeNameNotUniqueException ex) { CurrentError = String.Format(GetString("objectversioning.restorenotuniquecodename"), (ex.Object != null) ? "('" + ex.Object.ObjectCodeName + "')" : null); AddLog(CurrentError); } if (restoredObj != null) { AddLog(ResHelper.GetString("general.object", currentCulture) + " '" + taskTitle + "'"); } else { // Set result flag if (resultOK) { resultOK = false; } } } } } if (resultOK) { CurrentInfo = ResHelper.GetString("ObjectVersioning.Recyclebin.RestorationOK", currentCulture); AddLog(CurrentInfo); } else { CurrentError = ResHelper.GetString("objectversioning.recyclebin.restorationfailed", currentCulture); AddLog(CurrentError); } }
protected void btnOk_OnClick(object sender, EventArgs e) { pnlLog.Visible = true; CurrentError = string.Empty; CurrentLog.Close(); EnsureLog(); int actionValue = ValidationHelper.GetInteger(drpAction.SelectedValue, 0); Action action = (Action)actionValue; int whatValue = ValidationHelper.GetInteger(drpWhat.SelectedValue, 0); currentWhat = (What)whatValue; BinSettingsContainer binSettings = new BinSettingsContainer(CurrentUser, currentWhat, CurrentSite); switch (currentWhat) { case What.SelectedObjects: if (ugRecycleBin.SelectedItems.Count <= 0) { return; } binSettings.SelectedItems = ugRecycleBin.SelectedItems; break; } ctlAsyncLog.Parameter = binSettings; switch (action) { case Action.Restore: case Action.RestoreToCurrentSite: case Action.RestoreWithoutSiteBindings: { ctlAsyncLog.TitleText = GetString("objectversioning.Recyclebin.Restoringobjects"); switch (action) { case Action.Restore: RunAsync(RestoreWithChildren); break; case Action.RestoreToCurrentSite: RunAsync(RestoreToCurrentSite); break; case Action.RestoreWithoutSiteBindings: RunAsync(RestoreWithoutSiteBindings); break; } } break; case Action.Delete: { ctlAsyncLog.TitleText = GetString("recyclebin.emptyingbin"); RunAsync(EmptyBin); } break; } }
private DataSet GetRecycleBinSeletedItems(BinSettingsContainer settings, string columns) { var where = new WhereCondition(); switch (settings.CurrentWhat) { case What.AllObjects: if (IsSingleSite) { where.WhereNull("VersionObjectSiteID"); } if (settings.Site != null) { where.Or().WhereEquals("VersionObjectSiteID", settings.Site.SiteID); } // Wrap filter condition with brackets where.Where(new WhereCondition(filter.WhereCondition) { WhereIsComplex = true }); where = GetWhereCondition(where); break; case What.SelectedObjects: // Restore selected objects var toRestore = settings.SelectedItems; where.WhereIn("VersionID", toRestore); break; } return ObjectVersionHistoryInfoProvider.GetRecycleBin(where.ToString(true), OrderBy, -1, columns); }
/// <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.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", 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(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); } }
protected void btnOk_OnClick(object sender, EventArgs e) { pnlLog.Visible = true; CurrentError = string.Empty; int actionValue = ValidationHelper.GetInteger(drpAction.SelectedValue, 0); Action action = (Action)actionValue; int whatValue = ValidationHelper.GetInteger(drpWhat.SelectedValue, 0); currentWhat = (What)whatValue; BinSettingsContainer binSettings = new BinSettingsContainer(mCurrentUser, currentWhat); switch (currentWhat) { case What.SelectedDocuments: if (ugRecycleBin.SelectedItems.Count <= 0) { return; } binSettings.SelectedItems = ugRecycleBin.SelectedItems; break; } switch (action) { case Action.Restore: { ctlAsyncLog.TitleText = GetString("Recyclebin.RestoringDocuments"); RunAsync(p => Restore(binSettings)); } break; case Action.Delete: { ctlAsyncLog.TitleText = GetString("recyclebin.emptyingbin"); RunAsync(p => EmptyBin(binSettings)); } break; } }