Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
carlcs committed Jul 23, 2015
0 parents commit 4437f60
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.DS_Store
*Thumbs.db
_notes/
40 changes: 40 additions & 0 deletions deleteallentryversions/DeleteAllEntryVersionsPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
namespace Craft;

/**
* Delete All Entry Versions plugin
*/
class DeleteAllEntryVersionsPlugin extends BasePlugin
{
function getName()
{
return 'Delete All Entry Versions';
}

function getVersion()
{
return '1.0';
}

function getDeveloper()
{
return 'carlcs';
}

function getDeveloperUrl()
{
return 'https://github.com/carlcs/craft-deleteallentryversions';
}

public function getSettingsUrl()
{
return 'settings/plugins/deleteallentryversions/index';
}

public function registerCpRoutes()
{
return array(
'settings/plugins/deleteallentryversions/index' => 'deleteallentryversions/_settings',
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
namespace Craft;

class DeleteAllEntryVersionsController extends BaseController
{
// Public Methods
// =========================================================================

/**
* Deletes all entry versions.
*
* @return null
*/
public function actionDelete()
{
if (craft()->getEdition() >= Craft::Client)
{
// Delete them all.
craft()->db->createCommand()->truncateTable('entryversions');

// Save a new version for all entries' current content, to make it possible to revert back to it.
$sections = craft()->sections->getAllSections();

foreach ($sections as $section)
{
if ($section->enableVersioning)
{
$criteria = craft()->elements->getCriteria(ElementType::Entry);

$criteria->sectionId = $section->id;
$criteria->status = null;
$criteria->localeEnabled = null;
$criteria->limit = null;

foreach ($criteria as $entry)
{
craft()->entryRevisions->saveVersion($entry);
}
}
}
}

$this->redirectToPostedUrl();
}



}
21 changes: 21 additions & 0 deletions deleteallentryversions/templates/_settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends '_layouts/cp' %}
{% set title = 'Delete All Entry Versions' %}

{% set crumbs = [
{ label: 'Settings'|t, url: url('settings') },
{ label: 'Plugins'|t, url: url('settings/plugins') },
] %}

{% import '_includes/forms' as forms %}

{% set content %}
<form method="post" accept-charset="UTF-8" data-saveshortcut>
<input type="hidden" name="action" value="deleteAllEntryVersions/delete">

<p class="first">{{ 'Backup your Database first! This deletes all entry versions, but keeps the current version of each entry, so you can revert back to it.'|t }}</p>

<div class="buttons">
<input type="submit" class="btn submit" value="{{ 'Delete Entry Versions'|t }}">
</div>
</form>
{% endset %}
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Delete All Entry Versions plugin for Craft

This deletes all entry versions, but keeps the current version of each entry, so you can revert back to it.

## Installation

To install the plugin, copy the deleteallentryversions/ folder into craft/plugins/. Then go to Settings → Plugins and click the "Install" button next to "Delete All Entry Versions".

0 comments on commit 4437f60

Please sign in to comment.