/// <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 the document from the recycle bin. Called when the "Restore document" button is pressed. /// Expects the "CreateDocumentStructure" and "MoveDocumentToRecycleBin" methods to be run first. /// </summary> private bool RestoreFromRecycleBin() { // Prepare the where condition string where = "VersionNodeAliasPath LIKE N'/API-Example/Document-1'"; // Get the recycled document DataSet recycleBin = VersionHistoryInfoProvider.GetRecycleBin(CMSContext.CurrentSiteID, where, null, 0, "VersionHistoryID"); if (!DataHelper.DataSourceIsEmpty(recycleBin)) { // Create a new version history info object from the data row VersionHistoryInfo version = new VersionHistoryInfo(recycleBin.Tables[0].Rows[0]); // Create a new version manager instance and restore the document VersionManager manager = new VersionManager(new TreeProvider(CMSContext.CurrentUser)); manager.RestoreDocument(version.VersionHistoryID); return(true); } return(false); }
/// <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> /// 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); } }