Example #1
0
        public void Archive_MovePagesTo(IList<ulong> pageIdsToArchive, uint transactionId) {
            if(ArrayUtil.IsNullOrEmpty(pageIdsToArchive)) {
                return;
            }

            var pageIdsStr = pageIdsToArchive.ToCommaDelimitedString();
            Catalog.NewQuery(string.Format(@" /* Archive_MovePagesTo */
 	INSERT INTO archive (ar_namespace, ar_title, ar_text, ar_comment, ar_user, ar_timestamp, ar_minor_edit, ar_last_page_id, ar_old_id, ar_content_type, ar_language, ar_display_name, ar_transaction_id, ar_is_hidden, ar_meta, ar_revision) 
 		select page_namespace, page_title, old_text, old_comment, old_user, old_timestamp, old_minor_edit, old_page_id, old_id, old_content_type, old_language, old_display_name, ?TRANID, old_is_hidden, old_meta, old_revision
		from `old` o 
		join pages p
		on	o.old_page_id = p.page_id
		where p.page_id in ({0});

	INSERT INTO archive (ar_namespace, ar_title, ar_text, ar_comment, ar_user, ar_timestamp, ar_minor_edit, ar_last_page_id, ar_content_type, ar_language, ar_display_name, ar_transaction_id, ar_is_hidden, ar_meta, ar_revision) 
		select page_namespace, page_title, page_text, page_comment, page_user_id, page_timestamp, page_minor_edit, p.page_id, page_content_type, page_language, page_display_name, ?TRANID, page_is_hidden, page_meta, page_revision
		from `pages` p
		where page_is_redirect=0
        and p.page_id in ({0});

    delete from old
    where  old_page_id in ({0});

	delete from pages
	where page_id in ({0});", pageIdsStr))
                 .With("TRANID", transactionId)
                 .Execute();
        }
Example #2
0
        public void Archive_Delete(IList<uint> archiveIds) {
            if (ArrayUtil.IsNullOrEmpty(archiveIds)) {
                return;
            }

            var archiveIdsString = archiveIds.ToCommaDelimitedString();
            Catalog.NewQuery(string.Format(@" /* Archive_Delete */
delete from archive
where ar_id in ({0});",
            archiveIdsString)).Execute();
        }
Example #3
0
        public IList<ResourceIdMapping> ResourceMapping_GetByResourceIds(IList<uint> resourceIds) {
            List<ResourceIdMapping> ret = new List<ResourceIdMapping>();
            if(resourceIds.Count == 0) {
                return ret;
            }
            string query = @" /* ResourceMapping_GetByResourceIds */
select resource_id, 'file' as entity_type, file_id as entity_id
from resourcefilemap
where resource_id in ({0})
";
            Catalog.NewQuery(string.Format(query, resourceIds.ToCommaDelimitedString()))
            .Execute(dr => ret.AddRange(ResourceMapping_Populate(dr)));
            return ret;
        }
Example #4
0
        public void GroupMembers_UpdateUsersInGroup(uint groupid, IList<uint> userIds, DateTime timestamp) {
            string userIdInClause = userIds.ToCommaDelimitedString();
            string deleteQuery = "delete from user_groups where group_id = ?GROUPID";
            StringBuilder insertQuery = new StringBuilder();
            if (userIds.Count > 0) {
                deleteQuery = string.Format("{0} and user_id not in ({1})", deleteQuery, userIdInClause);
                insertQuery.Append("insert ignore into user_groups (user_id, group_id, last_edit) values ");
                for (int i = 0; i < userIds.Count; i++) {
                    insertQuery.AppendFormat("{0}({1}, ?GROUPID, ?TIMESTAMP)", i > 0 ? "," : "", userIds[i]);
                }
            }

            Catalog.NewQuery(string.Format(@" /* GroupMembers_UpdateUsersInGroup */
{0};
{1};", deleteQuery, insertQuery))
            .With("GROUPID", groupid)
            .With("TIMESTAMP", timestamp)
            .Execute();
        }
Example #5
0
        public IList<PageTextContainer> Pages_GetContents(IList<ulong> pageids) {
            List<PageTextContainer> ret = new List<PageTextContainer>();
            if(ArrayUtil.IsNullOrEmpty(pageids)) {
                return ret;
            }

            string pageIdsText = pageids.ToCommaDelimitedString();
            Catalog.NewQuery(
string.Format(
@"/* Pages_GetContents */
SELECT p.page_id, p.page_timestamp, p.page_text
FROM pages p
WHERE p.page_id in ({0})",
pageIdsText))
                .Execute(delegate(IDataReader dr) {
                while(dr.Read()) {
                    PageTextContainer ptc = new PageTextContainer(
                        DbUtils.Convert.To<ulong>(dr["page_id"], 0),
                        DbUtils.Convert.To<string>(dr["page_text"], string.Empty),
                        DbUtils.ToDateTime(dr["page_timestamp"].ToString())
                    );

                    ret.Add(ptc);
                }
            });
            return ret;
        }
Example #6
0
        public Dictionary<ulong, IList<PageBE>> Pages_GetRedirects(IList<ulong> pageIds) {
            Dictionary<ulong, IList<PageBE>> ret = new Dictionary<ulong, IList<PageBE>>();
            if(pageIds == null || pageIds.Count == 0) {
                return ret;
            }
            string pageIdsText = pageIds.ToCommaDelimitedString();
            string query = string.Format(@" /* PageDA::Pages_GetRedirects */
SELECT l_to, {0}
FROM pages p
JOIN links
	ON p.page_id = l_from
WHERE p.page_is_redirect=1 
AND l_to IN({1});
", PAGEFIELDS, pageIdsText);

            Catalog.NewQuery(query)
                .Execute(delegate(IDataReader dr) {
                while(dr.Read()) {
                    PageBE p = Pages_PopulatePage(dr);
                    ulong to = dr.Read<ulong>("l_to");
                    IList<PageBE> redirectsForId = null;
                    if(!ret.TryGetValue(to, out redirectsForId)) {
                        ret[to] = redirectsForId = new List<PageBE>();
                    }
                    redirectsForId.Add(p);
                }
            });
            return ret;
        }
Example #7
0
 public IList<GroupBE> Groups_GetByIds(IList<uint> groupIds) {
     if(groupIds.Count == 0) {
         return new List<GroupBE>();
     }
     return Groups_GetInternal(string.Format("where groups.group_id in ({0})", groupIds.ToCommaDelimitedString()), "Groups_GetByIds");
 }
Example #8
0
        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;
        }
Example #9
0
        public void Resources_Delete(IList<uint> resourceIds) {
            //TODO MaxM: Remove content as well

            if(resourceIds.Count == 0) {
                return;
            }
            string resourceIdsText = resourceIds.ToCommaDelimitedString();

            Catalog.NewQuery(string.Format(@" /* Resources_Delete */
delete from resources where res_id in ({0});
delete from resourcerevs where resrev_res_id in ({0});", resourceIdsText))
            .Execute();
        }
Example #10
0
        public void TagMapping_Delete(ulong pageId, IList<uint> tagids) {

            // deletes the specified page to tag mappings and removes the tag if it is no longer used
            if(0 < tagids.Count) {
                string tagIdsText = tagids.ToCommaDelimitedString();
                Catalog.NewQuery(String.Format(@" /* Tags_Delete */
DELETE FROM tag_map
WHERE tagmap_page_id = ?PAGEID AND tagmap_tag_id in ({0});

DELETE FROM tags
USING tags
LEFT JOIN tag_map tm ON tags.tag_id = tm.tagmap_tag_id
WHERE tag_id in ({0}) AND tm.tagmap_id IS NULL;", tagIdsText))
                            .With("PAGEID", pageId)
                            .Execute();
            }
        }
Example #11
0
        public void Links_MoveInboundToBrokenLinks(IList<ulong> deletedPageIds) {
            if (ArrayUtil.IsNullOrEmpty(deletedPageIds)) {
                return;
            }
            string pageIdsString = deletedPageIds.ToCommaDelimitedString();
            string query = String.Format(@" /* Links_MoveLinksToBrokenLinks */
insert ignore into brokenlinks(bl_from, bl_to)
	select t.l_from, p.page_title
	from pages p
	join (
		select l_from, l_to 
	        from links
        	where l_to in ({0})) t
	on p.page_id = t.l_to;

DELETE links FROM links
where 	l_from in ({0})
OR	l_to in ({0});", pageIdsString);

            Catalog.NewQuery(query)
                   .Execute();
        }