Post by Eton Bones on Apr 5, 2020 9:10:02 GMT -8
I recently saw yet another thread where the owner was lamenting the loss of forum content due to erroneous deletions and wishing for a solution. I know there's a recycle bin plugin in the library but the two major complaints for that plugin is that it cannot backup post deletions only threads and that it is only available in the moderation menu. This plugin addresses the first issue by redirecting post deletions in addition to threads. The second obstacle is however left unaddressed since this plugin uses the move post/thread mechanism which means no normal members only staff with that ability get to use this feature.
This is an (alpha) work-in-progress I started tinkering with on my day off yesterday but since I'll be working crazy and long hours during this virus lockdown I can't guarantee there will be any consistent progress on it so I am releasing it so anybody can improve upon it if they have downtime during this lockdown. If you have questions regarding the coding just post them here and I'll try to answer (or someone else might) whenever I find some time. With V6 around the corner the shelf life is unknown.
The plugin currently works silently in the background redirecting all eligible deletions to move operations, only error conditions are made visible at the moment.
www.dropbox.com/s/xa7nia9vyb8r07q/deletion%20backup.pbp?dl=0
This is an (alpha) work-in-progress I started tinkering with on my day off yesterday but since I'll be working crazy and long hours during this virus lockdown I can't guarantee there will be any consistent progress on it so I am releasing it so anybody can improve upon it if they have downtime during this lockdown. If you have questions regarding the coding just post them here and I'll try to answer (or someone else might) whenever I find some time. With V6 around the corner the shelf life is unknown.
The plugin currently works silently in the background redirecting all eligible deletions to move operations, only error conditions are made visible at the moment.
www.dropbox.com/s/xa7nia9vyb8r07q/deletion%20backup.pbp?dl=0
(function () {
const settings = pb.plugin.get("eton_reprocess_post").settings;
const route = pb.data("route");
const page = pb.data("page");
let post_ids=[];
$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
if ((options.url == "/posts/dialog/delete" && $('.options_menu').slice(0, 1).filter(function () {
return !!$(this).find("." + $(this).idFromClass('post') + "-movePost").length
}).length !== 0) || (options.url == "/threads/dialog/delete" && $('.actions .move_thread').length)) {
//Redirect deletes so we move instead of delete posts and threads
if (settings.move_board /*&& settings.move_thread*/) {
//The designated deletion board in plugin settings should still allow permanent deletions without relocation
if (void 0 === page.board || page.board && $.isNumeric(settings.move_board) && page.board.id !== parseInt(settings.move_board, 10)) {
options.url = /posts/.test(options.url)? "/admin/move_posts_process":"/threads/move";
options.board_id = parseInt(settings.move_board, 10);
options.thread_id = parseInt(settings.move_thread, 10);
options.merging = options.thread_id ? "merge":"new";
options.merging === "new" && (options.subject="Moved Post" + (page.thread ? " From Thread #"+page.thread.id:""))
post_ids=[];
options.data = decodeURIComponent(options.data).replace(/ids\[\]\=([\d,]+)/g, function (m, p) {
//lastDeleted = p;
post_ids.push(p);
return "";
});
post_ids.length && (options.data = (/threads/.test(options.url)?"thread_ids%5B%5D="+post_ids.join("&thread_ids%5B%5D="):"post_ids="+ encodeURIComponent(JSON.stringify(post_ids)))+ "&merging="+options.merging+"&board_id=" + options.board_id + ($.isNumeric(options.thread_id)? "&thread_id=" + options.thread_id:"") + (options.subject? "&subject="+options.subject.replace("Post","Post #"+post_ids.join(',#')+" "):"")+options.data);
options.data = options.data.replace(/\&{2,}/g,"&");
jqXHR.success((xhresponse, xhrstatus, jqXHR) => {
$('#confirm-container').dialog("close");
//second dialog with HTML response opens so close it too
$(document).one('dialogopen', '#confirm-container', ()=>{$('#confirm-container').dialog("close");})
if(jqXHR.status == 200){
//Refresh post/thread list
proboards.listManagers[pb.data("lm_id")].research();
//hide just in case there's a delay on the backend and item still appears in refresh
//$("#post-"+post_ids.join(",#post-")).hide();
$('<style>'+"#"+(/thread_ids/.test(options.data)?"thread":"post")+"-"+post_ids.join(",#"+(/thread_ids/.test(options.data)?"thread":"post")+"-")+'{display:none!important;}</style>').appendTo('head');
}else{ pb.window.error('Something went wrong while moving content: status code '+jqXHR.status)}
}); //return "json"
}
}
}
})
})()