public IList <ArchiveBE> Archive_GetPagesInTransaction(ulong pageId, out uint transactionId) { uint tempTranId = 0; List <ArchiveBE> archivedPagesInTransaction = new List <ArchiveBE>(); Catalog.NewQuery(@" /* Archive_GetPagesInTransaction */ select t.*, archive.* from archive join ( select * from transactions where t_type = 5 and t_reverted = 0 and t_page_id = ?PAGEID order by t_timestamp desc limit 1 ) t on t.t_id = ar_transaction_id where ar_old_id = 0 order by ar_title asc;") .With("PAGEID", pageId) .Execute(delegate(IDataReader dr) { while (dr.Read()) { tempTranId = DbUtils.Convert.To <uint>(dr["t_id"]) ?? 0; //Populate list of archived pages in trans. (assumes sort by transaction with first archived page being the transaction 'root') ArchiveBE archive = Archive_Populate(dr); archivedPagesInTransaction.Add(archive); } }); transactionId = tempTranId; return(archivedPagesInTransaction); }
public Dictionary <ulong, IList <ArchiveBE> > Archive_GetRevisionsByPageIds(IList <ulong> pageIds) { Dictionary <ulong, IList <ArchiveBE> > archivesRevsByPageId = new Dictionary <ulong, IList <ArchiveBE> >(); string pageidsString = pageIds.ToCommaDelimitedString(); Catalog.NewQuery(string.Format(@" /* Archive_GetRevisionsByPageIds */ select * from archive where ar_last_page_id in ({0}) order by ar_last_page_id desc, ar_timestamp asc ", pageidsString)).Execute(delegate(IDataReader dr) { while (dr.Read()) { IList <ArchiveBE> revisions = null; ArchiveBE p = Archive_Populate(dr); archivesRevsByPageId.TryGetValue(p.LastPageId, out revisions); if (revisions == null) { revisions = new List <ArchiveBE>(); } revisions.Add(p); archivesRevsByPageId[p.LastPageId] = revisions; } }); return(archivesRevsByPageId); }
private static XDoc GetArchivePageXml(XDoc doc, ArchiveBE archivedPage, UserBE user, DateTime ts) { XDoc ret = doc; bool singlePage = false; if (ret == null || ret.IsEmpty) { ret = new XDoc("page.archive"); singlePage = true; } else { ret = ret.Start("page.archive"); } ret = ret.Attr("id", archivedPage.LastPageId).Attr("href", DekiContext.Current.ApiUri.At("archive", "pages", archivedPage.LastPageId.ToString(), "info")) .Start("title").Value(archivedPage.Title.AsUserFriendlyName()).End() .Start("path").Value(archivedPage.Title.AsPrefixedDbPath()).End() .Start("contents").Attr("type", archivedPage.ContentType).Attr("href", DekiContext.Current.ApiUri.At("archive", "pages", archivedPage.LastPageId.ToString(), "contents")).End(); if (user != null) { ret.Add(UserBL.GetUserXml(user, "deleted", false)); } if (ts != DateTime.MinValue) { ret.Elem("date.deleted", ts); } if (!singlePage) { ret.End(); } return(ret); }
public static DreamMessage BuildDeletedPageContents(uint pageid) { ArchiveBE page = DbUtils.CurrentSession.Archive_GetPageHeadById(pageid); if (page == null) { throw new PageArchiveLogicNotFoundException(pageid); } //HACKHACKHACK MaxM: Copy data to a PageBE object since parser will not work on an ArchiveBE. ArchiveBE needs to go away. PageBE tempP = new PageBE(); tempP.Title = page.Title; tempP.SetText(page.Text); tempP.ContentType = page.ContentType; ParserResult parserResult = DekiXmlParser.Parse(tempP, ParserMode.VIEW_NO_EXECUTE); // TODO (steveb): this code is almost identical to the one in "GET:pages/{pageid}/contents"; consider merging // post process tail DekiXmlParser.PostProcessParserResults(parserResult); // wrap the result in a content tag and return it to the user XDoc result = new XDoc("content").Attr("type", parserResult.ContentType); foreach (XDoc entry in parserResult.Content.Elements) { if (entry.HasName("body")) { result.Start("body").Attr("target", entry["@target"].AsText).Value(entry.ToInnerXHtml()).End(); } else { result.Elem(entry.Name, entry.ToInnerXHtml()); } } // check if we hit a snag, which is indicated by a plain-text response if ((parserResult.ContentType == MimeType.TEXT.FullType) && (page.ContentType != MimeType.TEXT.FullType)) { // something happened during parsing return(new DreamMessage(DreamStatus.NonAuthoritativeInformation, null, result)); } else { return(DreamMessage.Ok(result)); } }
public void RestoreAttachment(ResourceBE attachmentToRestore, PageBE toPage, DateTime timestamp, uint transactionId) { if (toPage == null || toPage.ID == 0) { ArchiveBE archivesMatchingPageId = _session.Archive_GetPageHeadById(attachmentToRestore.ParentPageId.Value); if (archivesMatchingPageId == null) { throw new AttachmentRestoreFailedNoParentFatalException(); } else { toPage = PageBL.GetPageByTitle(archivesMatchingPageId.Title); if (0 == toPage.ID) { PageBL.Save(toPage, _resources.Localize(DekiResources.RESTORE_ATTACHMENT_NEW_PAGE_TEXT()), DekiMimeType.DEKI_TEXT, null); } } } string filename = attachmentToRestore.Name; //Check for name conflicts on target page ResourceBE conflictingFile = GetPageAttachment(toPage.ID, filename); if (conflictingFile != null) { //rename the restored file filename = string.Format("{0}(restored {1}){2}", attachmentToRestore.FilenameWithoutExtension, DateTime.Now.ToString("g"), string.IsNullOrEmpty(attachmentToRestore.FilenameExtension) ? string.Empty : "." + attachmentToRestore.FilenameExtension); conflictingFile = GetPageAttachment(toPage.ID, filename); if (conflictingFile != null) { throw new AttachmentRestoreNameConflictException(); } } //Build new revision for restored file attachmentToRestore = BuildRevForRestore(attachmentToRestore, toPage, filename, transactionId); //Insert new revision into DB attachmentToRestore = SaveResource(attachmentToRestore); //Recent Changes RecentChangeBL.AddFileRecentChange(_dekiContext.Now, toPage, _dekiContext.User, DekiResources.FILE_RESTORED(attachmentToRestore.Name), transactionId); _dekiContext.Instance.EventSink.AttachmentRestore(_dekiContext.Now, attachmentToRestore, _dekiContext.User); }
public ArchiveBE Archive_GetPageHeadById(ulong pageId) { ArchiveBE page = null; Catalog.NewQuery(@" /* Archive_GetPageHeadById */ select * from archive where ar_last_page_id = ?PAGEID and ar_old_id = 0;") .With("PAGEID", pageId) .Execute(delegate(IDataReader dr) { if (dr.Read()) { page = Archive_Populate(dr); } }); return(page); }
private static void RestorePageRevisionsForPage(ArchiveBE[] archivedRevs, Title newTitle, uint transactionId, bool minorChange, DateTime utcTimestamp) { // add the most recent archive entry to the pages table // NOTE: this will preserve the page id if it was saved with the archive or create a new page id if it is not available ArchiveBE mostRecentArchiveRev = archivedRevs[archivedRevs.Length - 1]; PageBE restoredPage = null; if (0 < archivedRevs.Length) { restoredPage = new PageBE(); restoredPage.Title = newTitle; restoredPage.Revision = mostRecentArchiveRev.Revision; restoredPage.MinorEdit = mostRecentArchiveRev.MinorEdit; bool conflict; PageBL.Save(restoredPage, null, mostRecentArchiveRev.Comment, mostRecentArchiveRev.Text, mostRecentArchiveRev.ContentType, mostRecentArchiveRev.Title.DisplayName, mostRecentArchiveRev.Language, -1, null, mostRecentArchiveRev.TimeStamp, mostRecentArchiveRev.LastPageId, false, false, null, false, out conflict); RecentChangeBL.AddRestorePageRecentChange(utcTimestamp, restoredPage, DekiContext.Current.User, DekiResources.UNDELETED_ARTICLE(restoredPage.Title.AsPrefixedUserFriendlyPath()), minorChange, transactionId); } // add all other archive entries to the old table // NOTE: this will preserve the old ids if they were saved with the archive or create new old ids if not available for (int i = 0; i < archivedRevs.Length - 1; i++) { ArchiveBE archivedRev = archivedRevs[i]; PageBE currentPage = new PageBE(); currentPage.Title = newTitle; if (i < archivedRevs.Length - 1) { ParserResult parserResult = DekiXmlParser.ParseSave(currentPage, archivedRev.ContentType, currentPage.Language, archivedRev.Text, -1, null, false, null); currentPage.SetText(parserResult.BodyText); currentPage.ContentType = parserResult.ContentType; currentPage.UserID = archivedRev.UserID; currentPage.TimeStamp = archivedRev.TimeStamp; currentPage.MinorEdit = archivedRev.MinorEdit; currentPage.Comment = archivedRev.Comment; currentPage.Language = archivedRev.Language; currentPage.IsHidden = archivedRev.IsHidden; currentPage.Revision = archivedRev.Revision; currentPage.ID = restoredPage.ID; PageBL.InsertOld(currentPage, archivedRev.OldId); } } }
private IList <KeyValuePair <uint, IList <ArchiveBE> > > Archive_PopulateByTransactionQuery(DataCommand cmd, out Dictionary <uint, TransactionBE> transactionsById, out uint?queryTotalTransactionCount) { Dictionary <uint, TransactionBE> transactionsByIdtemp = new Dictionary <uint, TransactionBE>(); List <KeyValuePair <uint, IList <ArchiveBE> > > archivedPagesByTransaction = new List <KeyValuePair <uint, IList <ArchiveBE> > >(); uint?queryTotalTransactionCountTemp = null; cmd.Execute(delegate(IDataReader dr) { KeyValuePair <uint, IList <ArchiveBE> > currentTrans = new KeyValuePair <uint, IList <ArchiveBE> >(); while (dr.Read()) { //Populate list of archived pages per trans. (assumes sort by transaction with first archived page being the transaction 'root') uint tranId = DbUtils.Convert.To <uint>(dr["t_id"]) ?? 0; ArchiveBE archivedPage = Archive_Populate(dr); TransactionBE tran = null; if (!transactionsByIdtemp.TryGetValue(tranId, out tran)) { tran = Transactions_Populate(dr); transactionsByIdtemp[tranId] = tran; } if (currentTrans.Key != tranId) { currentTrans = new KeyValuePair <uint, IList <ArchiveBE> >(tranId, new List <ArchiveBE>()); archivedPagesByTransaction.Add(currentTrans); } currentTrans.Value.Add(archivedPage); } if (dr.NextResult() && dr.Read()) { queryTotalTransactionCountTemp = DbUtils.Convert.To <uint>(dr["queryTotalTransactionCount"]); } }); transactionsById = transactionsByIdtemp; queryTotalTransactionCount = queryTotalTransactionCountTemp; return(archivedPagesByTransaction); }
private ArchiveBE Archive_Populate(IDataReader dr) { ArchiveBE archive = new ArchiveBE(); archive._Comment = dr.Read <byte[]>("ar_comment"); archive._DisplayName = dr.Read <string>("ar_display_name"); archive._Namespace = dr.Read <ushort>("ar_namespace"); archive._Title = dr.Read <string>("ar_title"); archive._TimeStamp = dr.Read <string>("ar_timestamp"); archive.ContentType = dr.Read <string>("ar_content_type"); archive.Id = dr.Read <uint>("ar_id"); archive.IsHidden = dr.Read <bool>("ar_is_hidden"); archive.Language = dr.Read <string>("ar_language"); archive.LastPageId = dr.Read <ulong>("ar_last_page_id"); archive.Meta = dr.Read <string>("ar_meta"); archive.MinorEdit = dr.Read <bool>("ar_minor_edit"); archive.OldId = dr.Read <ulong>("ar_old_id"); archive.Text = dr.Read <string>("ar_text"); archive.TransactionId = dr.Read <uint>("ar_transaction_id"); archive.UserID = dr.Read <uint>("ar_user"); archive.Revision = dr.Read <uint>("ar_revision"); return(archive); }
public static XDoc GetArchivePageXml(uint pageid) { XDoc ret = XDoc.Empty; ArchiveBE page = DbUtils.CurrentSession.Archive_GetPageHeadById(pageid); if (page == null) { throw new PageArchiveLogicNotFoundException(pageid); } //Retrieve metadata about the deletion to populate page info TransactionBE t = DbUtils.CurrentSession.Transactions_GetById(page.TransactionId); DateTime deleteTs = DateTime.MinValue; UserBE deletedBy = null; if (t != null) { deletedBy = UserBL.GetUserById(t.UserId); deleteTs = t.TimeStamp; } return(GetArchivePageXml(ret, page, deletedBy, deleteTs)); }
private ArchiveBE Archive_Populate(IDataReader dr) { ArchiveBE archive = new ArchiveBE(); archive._Comment = dr.Read<byte[]>("ar_comment"); archive._DisplayName = dr.Read<string>("ar_display_name"); archive._Namespace = dr.Read<ushort>("ar_namespace"); archive._Title = dr.Read<string>("ar_title"); archive._TimeStamp = dr.Read<string>("ar_timestamp"); archive.ContentType = dr.Read<string>("ar_content_type"); archive.Id = dr.Read<uint>("ar_id"); archive.IsHidden = dr.Read<bool>("ar_is_hidden"); archive.Language = dr.Read<string>("ar_language"); archive.LastPageId = dr.Read<ulong>("ar_last_page_id"); archive.Meta = dr.Read<string>("ar_meta"); archive.MinorEdit = dr.Read<bool>("ar_minor_edit"); archive.OldId = dr.Read<ulong>("ar_old_id"); archive.Text = dr.Read<string>("ar_text"); archive.TransactionId = dr.Read<uint>("ar_transaction_id"); archive.UserID = dr.Read<uint>("ar_user"); archive.Revision = dr.Read<uint>("ar_revision"); return archive; }