Skip to content

Commit

Permalink
Initial commit of an older plugin I had laying around.
Browse files Browse the repository at this point in the history
  • Loading branch information
danwolfgang committed Oct 31, 2013
0 parents commit 23d5a75
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 0 deletions.
20 changes: 20 additions & 0 deletions plugins/RemoveObjects/config.yaml
@@ -0,0 +1,20 @@
key: removeobjects
id: removeobjects
name: 'Remove Objects'
description: 'Allows System Administrators to easily remove any objects.'
author_name: 'Dan Wolfgang'
author_link: http://endevver.com
plugin_link: https://github.com/danwolfgang/mt-plugin-remove-objects
version: 1.0.0

applications:
cms:
menus:
tools:remove_objects:
label: 'Remove Objects'
mode: remove_objects
order: 10000
view: system
permission: administer
methods:
remove_objects: RemoveObjects::Plugin::remove_objects_interface
71 changes: 71 additions & 0 deletions plugins/RemoveObjects/lib/RemoveObjects/Plugin.pm
@@ -0,0 +1,71 @@
package RemoveObjects::Plugin;

use strict;
use warnings;

# This method handles both the initial loading of the Remove Objects screen,
# and is also responsible for doing the actual work of deleting objects.
sub remove_objects_interface {
my $app = shift;
my $q = $app->can('query') ? $app->query : $app->param;
my $plugin = $app->component('removeobjects');
my $param = {};

# Permissions check -- only system administrators can delete objects here.
if ( ! $app->user->is_superuser ) {
return $app->errstr(
'System Administrator privileges are required to remove objects.'
);
}

# Some object IDs have been supplied. Parse the supplied IDs, try to load
# them, and delete them.
if ( $q->param('object_type') && $q->param('object_id') ) {
my @object_ids = split( /\s?(\d+)\s?,\s?/, $q->param('object_id') );

my $iter = $app->model( $q->param('object_type') )->load_iter({
id => \@object_ids,
});

my @deleted_ids;
while ( my $obj = $iter->() ) {
$obj->remove;

push @deleted_ids, $obj->id;
}

# If anything was deleted, we want to tell the user about it.
if (@deleted_ids) {
$param->{objects_removed} = join(', ', @deleted_ids);

$app->log({
level => $app->model('log')->INFO(),
class => 'removeobjects',
author_id => $app->user->id,
message => 'The Remove Objects plugin was used to remove '
. 'objects of type "' . $q->param('object_type')
. '" with the IDs: ' . $param->{objects_removed} . '.',
});
}
}

my $object_types = $app->registry('object_types');
my @types;
foreach my $type (
sort { $object_types->{$a} cmp $object_types->{$b} }
keys %{$object_types}
) {
my $label = eval { $app->model($type)->class_label_plural }
|| 'Unkown Label';

push @types, {
type => $type,
label => $label,
};
}
$param->{object_types} = \@types;

return $plugin->load_tmpl( 'remove-objects.tmpl', $param );
}

1;
71 changes: 71 additions & 0 deletions plugins/RemoveObjects/tmpl/remove-objects.tmpl
@@ -0,0 +1,71 @@
<mt:SetVarBlock name="page_title">Remove Objects</mt:SetVarBlock>

<mt:Var name="position_actions_bottom" value="1">
<mt:SetVarTemplate name="action_buttons">
<button
type="submit"
accesskey="s"
class="primary-button primary action button"
title="<__trans phrase="Delete (s)">">
<__trans phrase="Delete">
</button>
</mt:SetVarTemplate>

<mt:SetVarBlock name="system_msg">
<div id="msg-block">
<mtapp:statusmsg
class="info">
<__trans phrase="Deleting objects is permanent. Proceed with caution!">
</mtapp:statusmsg>
<mt:if name="objects_removed">
<mtapp:statusmsg
class="success">
<__trans phrase="The selected objects have been removed:">
<mt:Var name="objects_removed">.
</mtapp:statusmsg>
</mt:if>
</div>
</mt:SetVarBlock>

<mt:SetVarBlock name="form_header">
<form method="post" action="<mt:Var name="script_url">" target="_top">
<input type="hidden" name="__mode" value="remove_objects" />
</mt:SetVarBlock>

<mt:Include name="include/header.tmpl">

<p>
Specify the object type and ID to be deleted. This is a <em>permanent</em>
operation and can <em>not</em> be undone. Make your selections carefully.
</p>

<mtapp:Setting
label="Object Type"
id="object-type"
hint="Select the object type to be deleted."
show_hint="1"
required="1">
<select name="object_type" id="object_type">
<option value="0">None</option>
<mt:Loop name="object_types">
<option value="<mt:Var name="type">"><mt:Var name="label"> (<mt:Var name="type">)</option>
</mt:Loop>
</select>
</mtapp:Setting>

<mtapp:Setting
label="Object ID(s)"
id="object-id"
hint="Specify the ID of an object to remove, or specify a comma-separated list to delete multiple objects."
show_hint="1"
required="1">
<input name="object_id" id="object_id" class="text full-width" value="" />
</mtapp:Setting>

<mt:Include name="include/actions_bar.tmpl" bar_position="bottom" hide_pager="1">

<mt:SetVarBlock name="form_footer">
</form>
</mt:SetVarBlock>

<mt:Include name="include/footer.tmpl">
53 changes: 53 additions & 0 deletions readme.md
@@ -0,0 +1,53 @@
# Remove Objects plugin for Movable Type

The Remove Objects plugin provides a way for administrators to easily delete
objects in Movable Type.

"But I can just click the Delete button on the Edit Entry screen." True, but
there are many other types of objects you may want to delete and some of them
don't have a Delete button. Plus, if you've got a bunch to delete, going one at
a time can be a pain.

"But I can just go to the database and delete the row." You can, but you
shouldn't. Movable Type is a *relational* database, so often stores some pieces
in one table and some pieces in another table. Directly editing the database is
a great way to fragment your install. This plugin uses the object's `remove`
method to correctly delete objects.

"But Movable Type comes with the simple `tools/remove-object` script." Yes!
This plugin is most like that script, but better in two ways: this plugin will
allow you to delete multiple objects at one time, and this plugin will log the
deletion to the Activity Log for a "paper trail." Additionally, you don't need
to figure out the object class to use this plugin; just choose it from the list
of available object types.

You'll need System Administrator privileges to use this plugin. Also, and I can
not overstate this enough, you can completely destory your installation with
this plugin by deleting different objects. Be sure you know what you want to
delete before charging in!

# Prerequisites

* Movable Type 4.x
* Movable Type 5.x
* Movable Type 6.x

# Installation

To install this plugin follow the instructions found here:

http://tinyurl.com/easy-plugin-install

# Use

Only System Administrators can use this plugin. At the System Overview level,
go to Tools > Remove Objects. Choose the object type and specify the object IDs
to be deleted. Click Delete.

# License

This plugin is licensed under the same terms as Perl itself.

# Copyright

Copyright 2013, uiNNOVATIONS LLC. All rights reserved.

0 comments on commit 23d5a75

Please sign in to comment.