Skip to content

Commit

Permalink
Version Bump to 2.0
Browse files Browse the repository at this point in the history
see changelog inside README for more informations
  • Loading branch information
Hirbod Mirjavadi committed Mar 2, 2017
1 parent 17310d8 commit 9a88cc0
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 62 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,43 @@ Mit diesem AddOn kann ein gelöschter Artikel oder eine gelöschte Kategorie wie

![Screenshot](https://raw.githubusercontent.com/FriendsOfREDAXO/undo/assets/screenshot.png)

Changelog
------------
Version 2.0.0
* Support für mehrsprachige Seiten
* Performanceoptimierungen
* Priorität wurde behoben
* Man springt nicht mehr in den Kategorie-Root zurück

Settingspage
------------
Dieses AddOn hat keine Konfigurationsparameter. Die Aktionslinks erscheinen, sobald ein Artikel oder eine Kategorie gelöscht wurden.

Installation
------------
Hinweis: dies ist kein Plugin!

* Release herunterladen und entpacken.
* Ordner umbenennen in `undo`.
* In den Addons-Ordner legen: `/redaxo/src/addons`.

Oder den REDAXO-Installer / ZIP-Upload AddOn nutzen!

Voraussetzungen
------------

* REDAXO >= 5.3.0

ToDo
-----
* Undo für Module
* Undo für Templates
* Beachtung der Arbeitsversion

Ich würde gerne noch die Möglichkeit für Templates und Module anbieten, hierzu gibt es aber aktuell noch keine EPs. Sobald das REX-Core Team diese zur Verfügung gestellt hat, wird diese Funktionalität nachgereicht.

Weitere Hinweise
-----
* Die Arbeitsversion / Revision wird aktuell noch nicht wiederhergestellt.

Da REDAXO aktuell noch keinen EP bei einem Core-Update zur Verfügung stellt, sollte dieses AddOn nach jedem Core-Update deinstalliert und wieder installiert werden (reinstallieren funktioniert nicht). Dadurch werden Änderungen an der Tabelle rex_article und rex_article_slice automatisch übernommen.
129 changes: 69 additions & 60 deletions boot.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

/**
* media_manager_autorewrite Addon.
* undo Addon.
*
* @author Friends Of REDAXO
*
* @var rex_addon
*/

if (rex::isBackend() && is_object(rex::getUser())) {
rex_perm::register('undo[]');

Expand All @@ -17,93 +17,102 @@
$type = rex_request('type', 'string', '');
$deleteQueue = true;


/*
ARTIKEL UND KATEGORIEN
ARTIKEL UND KATEGORIEN
*/

// An Extionsion-Point andocken
// Listen on EP to save a tmp state
rex_extension::register('ART_PRE_DELETED', function (rex_extension_point $ep) {
$content = $ep->getParams();

// Daten in die temporäre Tabelle kopieren
$ART = rex_sql::factory();
$ART->setQuery('INSERT INTO '.rex::getTablePrefix().'article_undo SELECT * FROM '.rex::getTablePrefix().'article where id=? and clang_id=?', [$content['id'], rex_clang::getStartId()]);
$ART->setQuery('INSERT INTO '.rex::getTablePrefix().'article_undo SELECT * FROM '.rex::getTablePrefix().'article where id=?', [$content['id']]);
$ART->setQuery('INSERT INTO '.rex::getTablePrefix().'article_slice_undo SELECT * FROM '.rex::getTablePrefix().'article_slice where article_id=?', [$content['id']]);

});

// output message with undo-link for articles
rex_extension::register('ART_DELETED', function (rex_extension_point $ep) use (&$deleteQueue, $category_id) {
$content = $ep->getParams();
$deleteQueue = false;

return rex_i18n::msg('article_deleted') . " <a href='?page=structure&mode=undo&type=art&category_id=".$category_id.'&aid='.$content['id']."'>".rex_i18n::msg('undo_undo_action')."</a>.";
return rex_i18n::msg('article_deleted')." <a href='?page=structure&mode=undo&type=art&category_id=".$category_id."&aid=".$content['id']."&clang=".rex_clang::getCurrentId()."'>".rex_i18n::msg('undo_undo_action').'</a>.';
});

rex_extension::register('CAT_DELETED', function (rex_extension_point $ep) use (&$deleteQueue) {
// output message with undo-link for categories
rex_extension::register('CAT_DELETED', function (rex_extension_point $ep) use (&$deleteQueue, $category_id) {
$content = $ep->getParams();
$deleteQueue = false;

return rex_i18n::msg('category_deleted') . " <a href='?page=structure&mode=undo&type=cat&aid=".$content['id']."'>".rex_i18n::msg('undo_undo_action')."</a>.";
return rex_i18n::msg('category_deleted')." <a href='?page=structure&mode=undo&type=cat&category_id=".$category_id."&aid=".$content['id']."&clang=".rex_clang::getCurrentId()."'>".rex_i18n::msg('undo_undo_action').'</a>.';
});

// undo magic if link was clicked
if ($mode == 'undo') {
$outputMsg = '';

$sql = rex_sql::factory();
$sql->setQuery('SELECT parent_id,catpriority,priority FROM '.rex::getTablePrefix().'article_undo where id=? and clang_id=?', [$aid, rex_clang::getStartId()]);

if ($sql->getRows()) {
$parent_id = $sql->getValue('parent_id');
$artpriority = $sql->getValue('priority');
$catpriority = $sql->getValue('catpriority');

$ART = rex_sql::factory();
$ART->setQuery('INSERT INTO '.rex::getTablePrefix().'article SELECT * FROM '.rex::getTablePrefix().'article_undo where id=? and clang_id=?', [$aid, rex_clang::getStartId()]);
$ART->setQuery('INSERT INTO '.rex::getTablePrefix().'article_slice SELECT * FROM '.rex::getTablePrefix().'article_slice_undo where article_id=?', [$aid]);

switch ($type) {
case 'cat':
$outputMsg = rex_i18n::msg('undo_category_restored');
foreach (rex_clang::getAllIds() as $clang) {
rex_category_service::newCatPrio($parent_id, $clang, 0, $catpriority);
// we need to register late, or we wont be able to triggr ART_UPDATED / CAT_UPDATED
rex_extension::register('PACKAGES_INCLUDED', function (rex_extension_point $ep) use ($mode, $aid, $category_id, $type) {

$outputMsg = '';

$sql = rex_sql::factory();
//$sql->setDebug();
$elements = $sql->getArray('SELECT name,catname,parent_id,catpriority,priority,status,clang_id,template_id FROM '.rex::getTablePrefix().'article_undo where id=?', [$aid]);

if ($sql->getRows()) {
$i = 1;
foreach ($elements as $e) {
$parent_id = $e['parent_id'];
$template_id = $e['template_id'];
$status = $e['status'];

$artpriority = $e['priority'];
$artname = $e['name'];

$catname = $e['catname'];
$catpriority = $e['catpriority'];

$clang = $e['clang_id'];

$ART = rex_sql::factory();
$ART->setQuery('INSERT INTO '.rex::getTablePrefix().'article SELECT * FROM '.rex::getTablePrefix().'article_undo where id=? and clang_id=?', [$aid, $clang]);
// slices just need to get inserted once
if ($counter === 1) {
$ART->setQuery('INSERT INTO '.rex::getTablePrefix().'article_slice SELECT * FROM '.rex::getTablePrefix().'article_slice_undo where article_id=?', [$aid]);
}

switch ($type) {
case 'cat':
$outputMsg = rex_i18n::msg('undo_category_restored');
rex_category_service::newCatPrio($parent_id, $clang, $catpriority, 0);
rex_category_service::editCategory($aid, $clang, array('catpriority' => $catpriority, 'catname' => $catname));
break;

default:
$outputMsg = rex_i18n::msg('undo_article_restored');
rex_article_service::newArtPrio($category_id, $clang, $artpriority, 0);
rex_article_service::editArticle($aid, $clang, array('name' => $artname, 'template_id' => $template_id, 'priority' => $artpriority, 'status' => $status));
break;
}
++$i;
}

break;
rex_extension::register('PAGE_TITLE', function (rex_extension_point $ep) use ($outputMsg) {
return rex_view::success($outputMsg);
});

default:
$outputMsg = rex_i18n::msg('undo_article_restored');
foreach (rex_clang::getAllIds() as $clang) {
rex_article_service::newArtPrio($aid, $clang, 0, $artpriority);
}
break;
}

rex_extension::register('PAGE_TITLE', function (rex_extension_point $ep) use ($outputMsg) {
return rex_view::success($outputMsg);
});

}, rex_extension::LATE);

// clear the cache
rex_delete_cache();
} else {
/* Undo-Action will only last for one page reload */
if ($deleteQueue) {
$ART = rex_sql::factory();
$ART->setQuery('SELECT id FROM '.rex::getTablePrefix().'article_undo LIMIT 1');
if ($ART->getRows()) {
$ART->setQuery('DELETE FROM '.rex::getTablePrefix().'article_undo');
$ART->setQuery('DELETE FROM '.rex::getTablePrefix().'article_slice_undo');
}
}
}


/*
MODULE
*/



/*
TEMPLATES
*/

/* Undo-Action will only last for one page reload */
if ($deleteQueue) {
$ART = rex_sql::factory();
$ART->setQuery('DELETE FROM '.rex::getTablePrefix().'article_undo');
$ART->setQuery('DELETE FROM '.rex::getTablePrefix().'article_slice_undo');
}
}
4 changes: 2 additions & 2 deletions package.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package: undo
version: '1.0.1-RC2'
version: '2.0.0'
author: Friends Of REDAXO
supportpage: github.com/FriendsOfREDAXO/undo

requires:
redaxo: '^5.3.0-beta1' # benötigt mindestens REDAXO 5.0
redaxo: '^5.3.0' # benötigt mindestens REDAXO 5.0
php:
version: '>=5.6' # benötigt mindestens PHP 5.6

0 comments on commit 9a88cc0

Please sign in to comment.