From 231f749d833d55f6d004927c171fab6a873f2a91 Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Thu, 18 May 2017 13:33:32 +0200
Subject: [PATCH] handle draftdeletion in draftdel action only

This was the last remaining function in inc/action.php that could be
moved to the actions.

We now have quite the elegant cascade in the action handling.
---
 inc/Action/Cancel.php   |  1 +
 inc/Action/Draftdel.php | 12 +++++++++++-
 inc/Action/Revert.php   | 10 +++-------
 inc/Action/Save.php     |  8 ++------
 inc/actions.php         | 15 ---------------
 5 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/inc/Action/Cancel.php b/inc/Action/Cancel.php
index c72644607..c3e185534 100644
--- a/inc/Action/Cancel.php
+++ b/inc/Action/Cancel.php
@@ -14,6 +14,7 @@ use dokuwiki\Action\Exception\ActionAbort;
 class Cancel extends AbstractAliasAction {
 
     public function preProcess() {
+        // continue with draftdel -> redirect -> show
         throw new ActionAbort('draftdel');
     }
 
diff --git a/inc/Action/Draftdel.php b/inc/Action/Draftdel.php
index d7707b30d..77378f7cb 100644
--- a/inc/Action/Draftdel.php
+++ b/inc/Action/Draftdel.php
@@ -18,8 +18,18 @@ class Draftdel extends AbstractAction {
         return AUTH_EDIT;
     }
 
+    /**
+     * Delete an existing draft if any
+     *
+     * Reads draft information from $INFO. Redirects to show, afterwards.
+     *
+     * @throws ActionAbort
+     */
     public function preProcess() {
-        act_draftdel('fixme'); // FIXME replace this utility function
+        global $INFO;
+        @unlink($INFO['draft']);
+        $INFO['draft'] = null;
+
         throw new ActionAbort('redirect');
     }
 
diff --git a/inc/Action/Revert.php b/inc/Action/Revert.php
index 4fd9d622f..ca35374f2 100644
--- a/inc/Action/Revert.php
+++ b/inc/Action/Revert.php
@@ -56,14 +56,10 @@ class Revert extends AbstractAction {
 
         saveWikiText($ID, $text, $sum, false);
         msg($sum, 1);
-
-        //delete any draft
-        act_draftdel('fixme'); // FIXME replace this utility function
-        //session_write_close(); // FIXME sessions should be close somewhere higher up, maybe ActionRouter
-
-        // when done, show current page
         $REV = '';
-        throw new ActionAbort('redirect');
+
+        // continue with draftdel -> redirect -> show
+        throw new ActionAbort('draftdel');
     }
 
 }
diff --git a/inc/Action/Save.php b/inc/Action/Save.php
index 419108e1a..0b2472983 100644
--- a/inc/Action/Save.php
+++ b/inc/Action/Save.php
@@ -53,12 +53,8 @@ class Save extends AbstractAction {
         //unlock it
         unlock($ID);
 
-        //delete draft
-        act_draftdel('fixme'); // FIXME replace this utility function
-        //session_write_close(); // FIXME close session higher up
-
-        // when done, show page
-        throw new ActionAbort('redirect');
+        // continue with draftdel -> redirect -> show
+        throw new ActionAbort('draftdel');
     }
 
 }
diff --git a/inc/actions.php b/inc/actions.php
index cde691595..22954ae7a 100644
--- a/inc/actions.php
+++ b/inc/actions.php
@@ -59,18 +59,3 @@ function act_clean($act){
     if($act === '') $act = 'show';
     return $act;
 }
-
-/**
- * Handle 'draftdel'
- *
- * Deletes the draft for the current page and user
- *
- * @param string $act action command
- * @return string action command
- */
-function act_draftdel($act){
-    global $INFO;
-    @unlink($INFO['draft']);
-    $INFO['draft'] = null;
-    return 'show';
-}
-- 
GitLab