Skip to content
Browse files

Add imported entry eraser

This creates a page where people can choose to erase their imported
posts and the comments on those posts. This is a nuclear option that is
not linked from site nav and is intended to be used by people who have
imports gone awry.
  • Loading branch information...
1 parent 0196aaf commit dd9b5473af0f13d77d88db32e82ddfeeb913af14 @zorkian zorkian committed
View
26 bin/worker/import-eraser
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+#
+# bin/worker/import-eraser
+#
+# TheSchwartz worker for removing imported content.
+#
+# Authors:
+# Mark Smith <mark@dreamwidth.org>
+#
+# Copyright (c) 2012 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself. For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+
+use strict;
+use warnings;
+
+use lib "$ENV{LJHOME}/cgi-bin";
+use LJ::Worker::TheSchwartz;
+use DW::Worker::ImportEraser;
+
+schwartz_decl( $_ )
+ foreach (DW::Worker::ImportEraser->schwartz_capabilities);
+
+schwartz_work(); # Never returns.
View
67 cgi-bin/DW/Controller/Importer.pm
@@ -0,0 +1,67 @@
+#!/usr/bin/perl
+#
+# DW::Controller::Importer
+#
+# Controller for the /tools/importer pages.
+#
+# Authors:
+# Mark Smith <mark@dreamwidth.org>
+#
+# Copyright (c) 2012 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself. For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+
+package DW::Controller::Importer;
+
+use strict;
+use warnings;
+
+use DW::Routing;
+use DW::Template;
+use LJ::Hooks;
+
+DW::Routing->register_string( '/tools/importer/erase', \&erase_handler, app => 1 );
+sub erase_handler {
+ my ( $ok, $rv ) = controller( authas => 1 );
+ return $rv unless $ok;
+
+ my $r = DW::Request->get;
+ unless ( $r->did_post ) {
+ # No post, return form.
+ return DW::Template->render_template( 'tools/importer/erase.tt', {
+ authas_html => $rv->{authas_html},
+ u => $rv->{u},
+ } );
+ }
+
+ my $args = $r->post_args;
+ die "Invalid form auth.\n"
+ unless LJ::check_form_auth( $args->{lj_form_auth} );
+
+ unless ( $args->{confirm} eq 'DELETE' ) {
+ return DW::Template->render_template( 'tools/importer/erase.tt', {
+ notconfirmed => 1,
+ authas_html => $rv->{authas_html},
+ u => $rv->{u},
+ } );
+ }
+
+ # Confirmed, let's schedule.
+ my $sclient = LJ::theschwartz() or die "Unable to get TheSchwartz.\n";
+ my $job = TheSchwartz::Job->new_from_array( 'DW::Worker::ImportEraser', {
+ userid => $rv->{u}->userid
+ } );
+ die "Failed to insert eraser job.\n"
+ unless $job && $sclient->insert( $job );
+
+ return DW::Template->render_template( 'tools/importer/erase.tt', {
+ u => $rv->{u},
+ confirmed => 1,
+ } );
+}
+
+
+1;
View
54 cgi-bin/DW/Worker/ImportEraser.pm
@@ -0,0 +1,54 @@
+#!/usr/bin/perl
+#
+# DW::Worker::ImportEraser
+#
+# Erases imported content.
+#
+# Authors:
+# Mark Smith <mark@dreamwidth.org>
+#
+# Copyright (c) 2012 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself. For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+
+
+use v5.10;
+use strict;
+use warnings;
+
+package DW::Worker::ImportEraser;
+use base 'TheSchwartz::Worker';
+use DW::Worker::ContentImporter::Local::Entries;
+use DW::Worker::ContentImporter::Local::Comments;
+
+sub schwartz_capabilities { 'DW::Worker::ImportEraser' }
+sub max_retries { 5 }
+sub retry_delay { (30, 120, 300, 600, 900)[$_[1]] };
+sub keep_exit_status_for { 86400 } # 24 hours
+sub grab_for { 3600 }
+
+sub work {
+ my ($class, $job) = @_;
+ my %arg = %{$job->arg};
+
+ # This is a very simple process. Find the user, find all of their importer
+ # entries, then delete them one by one. THIS IS VERY DESTRUCTIVE. There is
+ # no turning back.
+ my $u = LJ::load_userid($arg{userid})
+ or return $job->failed("Userid can't be loaded. Will retry.");
+ my %map = %{ DW::Worker::ContentImporter::Local::Entries->get_entry_map( $u ) || {} };
+ my ($ct, $max) = (0, scalar keys %map);
+ foreach my $jitemid ( values %map ) {
+ $ct++;
+ $0 = sprintf( "import-eraser: %s(%d) - %d/%d - %0.2f%%", $u->user, $u->userid, $ct, $max, $ct/$max*100 );
+ LJ::delete_entry( $u, $jitemid, 0, undef );
+ }
+
+ $job->completed;
+ $0 = 'import-eraser: idle';
+}
+
+1;
View
46 views/tools/importer/erase.tt
@@ -0,0 +1,46 @@
+[%# erase.tt
+
+Allows you to erase your imported entries and comments.
+
+Authors:
+ Mark Smith <mark@dreamwidth.org>
+
+This program is free software; you may redistribute it and/or modify it under
+the same terms as Perl itself. For a copy of the license, please reference
+'perldoc perlartistic' or 'perldoc perlgpl'.
+%]
+
+[%- sections.title = '.title' | ml -%]
+
+<style type='text/css'>
+.form-error {
+ color: red;
+ font-weight: bold;
+}
+</style>
+
+[% IF confirmed %]
+
+ <h2>[% '.heading' | ml %]</h2>
+ <p>[% '.confirmed' | ml(ljuser = u.ljuser_display) %]</p>
+
+[% ELSE %]
+ <form method="get">
+ [% authas_html %]
+ </form>
+
+ <h2>[% '.heading' | ml %]</h2>
+
+ <p>[% '.about1' | ml(sitename = site.name) %]</p>
+
+ <p>[% '.about2' | ml %]</p>
+
+ <form method="POST" id="renameform">
+ [%- dw.form_auth # hidden input field HTML -%]
+
+ <p>[% '.admonition' | ml %] <input type="text" name="confirm" />
+ [% IF notconfirmed %]<span class='form-error'>[% '.error.noconfirm' | ml %]</span>[% END %]</p>
+
+ <input type="submit" value="[% '.commit' | ml %]" /> [% '.in' | ml(ljuser = u.ljuser_display) %]
+ </form>
+[% END %]
View
18 views/tools/importer/erase.tt.text
@@ -0,0 +1,18 @@
+;; -*- coding: utf-8 -*-
+.about1=This page allows you to permanently erase entries (and comments that you have imported into your [[sitename]] account. <strong>This action is irrevocable.</strong>
+
+.about2=Once you click the button below, a job will be scheduled to delete the posts. When the job is done, you will see that the posts have been deleted.
+
+.admonition=Please type <strong>DELETE</strong> in this box:
+
+.commit=Erase All Imported Entries
+
+.confirmed=The job has been scheduled for [[ljuser]]. Entries that have been imported from a remote site will now be deleted. This job may take some time depending on how many other jobs are in the queue.
+
+.error.noconfirm=<strong>Please type "DELETE" in this box.</strong>
+
+.heading=Delete Entries
+
+.in=in [[ljuser]]
+
+.title=Imported Entry Eraser

0 comments on commit dd9b547

Please sign in to comment.
Something went wrong with that request. Please try again.