Skip to content

Commit

Permalink
cs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
skerbis committed Apr 3, 2024
1 parent 89abc76 commit 1a57ea6
Showing 1 changed file with 36 additions and 39 deletions.
75 changes: 36 additions & 39 deletions boot.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?php


namespace FriendsOfRedaxo\Undo;

use rex;
use function rex_request;
use rex_extension;
use rex_extension_point;
use rex_sql;
use rex_clang;
use rex_i18n;
use rex_view;
use rex_article_service;
use rex_category_service;
use rex_article_cache;
use rex_perm;
use function rex_session;
use Exception;

use Exception;
use rex;
use rex_article_cache;
use rex_article_service;
use rex_category_service;
use rex_clang;
use rex_extension;
use rex_extension_point;
use rex_i18n;
use rex_perm;
use rex_sql;
use rex_view;

use function is_object;
use function rex_request;
use function rex_session;

if (rex::isBackend() && is_object(rex::getUser())) {
rex_perm::register('undo[]');
Expand All @@ -38,7 +38,7 @@
*/

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

try {
Expand All @@ -48,10 +48,9 @@
Undo::saveArticle($content['id']);
}
}

});

rex_extension::register('SLICE_DELETE', function (rex_extension_point $ep): void {
rex_extension::register('SLICE_DELETE', static function (rex_extension_point $ep): void {
$content = $ep->getParams();

try {
Expand All @@ -61,11 +60,10 @@
Undo::saveSlice($content['slice_id']);
}
}

});

// output message with undo-link for articles
rex_extension::register('ART_DELETED', function (rex_extension_point $ep) use (&$deleteQueue, $category_id): string {
rex_extension::register('ART_DELETED', static function (rex_extension_point $ep) use (&$deleteQueue, $category_id): string {
$content = $ep->getParams();
$deleteQueue = false;
rex_set_session('undo_timestamp', time());
Expand All @@ -74,7 +72,7 @@
});

// output message with undo-link for slices
rex_extension::register('SLICE_DELETED', function (rex_extension_point $ep) use (&$deleteQueue, $category_id): string {
rex_extension::register('SLICE_DELETED', static function (rex_extension_point $ep) use (&$deleteQueue, $category_id): string {
$content = $ep->getParams();
$deleteQueue = false;
rex_set_session('undo_timestamp', time());
Expand All @@ -83,7 +81,7 @@
});

// output message with undo-link for categories
rex_extension::register('CAT_DELETED', function (rex_extension_point $ep) use (&$deleteQueue, $category_id): string {
rex_extension::register('CAT_DELETED', static function (rex_extension_point $ep) use (&$deleteQueue, $category_id): string {
$content = $ep->getParams();
$deleteQueue = false;
rex_set_session('undo_timestamp', time());
Expand All @@ -93,10 +91,8 @@

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

// 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 ($aid, $category_id, $type, $slice_restore_id, $ctype, $article_id): void {

rex_extension::register('PACKAGES_INCLUDED', static function (rex_extension_point $ep) use ($aid, $category_id, $type, $slice_restore_id, $ctype, $article_id): void {
$outputMsg = '';

if ($type == 'cat' || $type == 'art') {
Expand All @@ -122,27 +118,29 @@

try {
$ART->setQuery('INSERT INTO '.rex::getTable('article').' SELECT * FROM '.rex::getTable('article_undo').' where id=? and clang_id=?', [$aid, $clang]);
} catch (Exception $e) {}
} catch (Exception $e) {
}

// slices just need to get inserted once
if ($i === 1) {
if ($i === 1) {
try {
$ART->setQuery('INSERT INTO '.rex::getTable('article_slice').' SELECT * FROM '.rex::getTable('article_slice_undo').' where article_id=?', [$aid]);
} catch (Exception $e) {}
} catch (Exception $e) {
}
}

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;
$outputMsg = rex_i18n::msg('undo_category_restored');
rex_category_service::newCatPrio($parent_id, $clang, $catpriority, 0);
rex_category_service::editCategory($aid, $clang, ['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;
$outputMsg = rex_i18n::msg('undo_article_restored');
rex_article_service::newArtPrio($category_id, $clang, $artpriority, 0);
rex_article_service::editArticle($aid, $clang, ['name' => $artname, 'template_id' => $template_id, 'priority' => $artpriority, 'status' => $status]);
break;
}
++$i;
}
Expand All @@ -157,11 +155,10 @@
}

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

}, rex_extension::LATE);
} else {
/* Undo-Action will only last for one page reload */
Expand Down

0 comments on commit 1a57ea6

Please sign in to comment.