From e229f4f3836015d79b952a88d115538db77a9458 Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Fri, 1 Jul 2022 10:36:44 +0000
Subject: [PATCH] remove mail sending from error reporting in evaluation
 classes and fix error display, fixes #1242

Closes #1242

Merge request studip/studip!758
---
 lib/classes/AuthorObject.class.php            | 112 ++----------------
 lib/evaluation/classes/Evaluation.class.php   |   2 -
 .../classes/EvaluationExportManager.class.php |   2 -
 .../EvaluationExportManagerCSV.class.php      |   2 -
 .../classes/EvaluationGroup.class.php         |   2 -
 .../classes/EvaluationObject.class.php        |   2 -
 .../classes/EvaluationTreeEditView.class.php  |   1 -
 lib/evaluation/evaluation.lib.php             |  51 +++-----
 8 files changed, 24 insertions(+), 150 deletions(-)

diff --git a/lib/classes/AuthorObject.class.php b/lib/classes/AuthorObject.class.php
index d5e35b601e4..b3e98e3a8ef 100644
--- a/lib/classes/AuthorObject.class.php
+++ b/lib/classes/AuthorObject.class.php
@@ -51,20 +51,6 @@ class AuthorObject
      */
     public $errorArray;
 
-    /**
-     * Holds the emailadress of the author
-     * @access   private
-     * @var      array $authorEmail
-     */
-    public $authorEmail;
-
-    /**
-     * Holds the name of the author
-     * @access   private
-     * @var      array $authorName
-     */
-    public $authorName;
-
     /**
      * Holds the type of object. See INSTANCEOF_*
      * @access   private
@@ -82,56 +68,6 @@ class AuthorObject
         $this->errorArray = [];
     }
 
-
-    /**
-     * Destructor. Should be used every time after an object is not longer
-     * usefull!
-     * @access   public
-     */
-    public function finalize()
-    {
-    }
-
-    /**
-     * Sets the emailaddress of the author
-     * @access  public
-     * @param string $email The emailaddress
-     */
-    public function setAuthorEmail($email)
-    {
-        $this->authorEmail = $email;
-    }
-
-    /**
-     * Gets the emailaddress of the author
-     * @access  public
-     * @return  string The emailaddress
-     */
-    public function getAuthorEmail()
-    {
-        return $this->authorEmail;
-    }
-
-    /**
-     * Sets the name of the author
-     * @access  public
-     * @param string $name The name
-     */
-    public function setAuthorName($name)
-    {
-        $this->authorNmae = $name;
-    }
-
-    /**
-     * Gets the name of the author
-     * @access  public
-     * @return  string The name
-     */
-    public function getAuthorName()
-    {
-        return $this->authorName;
-    }
-
     /**
      * Gets the type of object
      * @access  public
@@ -149,7 +85,7 @@ class AuthorObject
      */
     public function isError()
     {
-        return (count($this->errorArray) != 0);
+        return count($this->errorArray) > 0;
     }
 
     /**
@@ -176,33 +112,17 @@ class AuthorObject
      * @access  public
      * @param integer $errcode The code of the error
      * @param string $errstring The description of the error
-     * @param integer $errline The line
-     * @param string $errfile The file
-     * @param integer $errtype Defines wheter the error is critical
      */
-    public function throwError($errcode, $errstring, $errline = 0, $errfile = 0, $errtype = ERROR_NORMAL)
+    public function throwError($errcode, $errstring)
     {
         if (!is_array($this->errorArray)) {
             $this->errorArray = [];
         }
 
-        array_push($this->errorArray,
-            ["code" => $errcode,
-                "string" => $errstring,
-                "file" => $errfile,
-                "line" => $errline,
-                "type" => $errtype]
-        );
-        if ($errtype == ERROR_CRITICAL) {
-            @mail($this->getAuthorEmail(),
-                "Critical error in Stud.IP",
-                "Hello " . $this->getAuthorName() . "\n\n" .
-                "there is an error in file " . $errfile . " " .
-                "in line " . $errline . ". \n" .
-                "The code is " . $errcode . "\n" .
-                "Description: " . $errstring . ".\n\n\n" .
-                "regards, *an AuthorObject*\n\n");
-        }
+        $this->errorArray [] = [
+            'code'   => $errcode,
+            'string' => $errstring,
+        ];
     }
 
     /**
@@ -210,28 +130,10 @@ class AuthorObject
      * @access  private
      * @param object $class The class with the error
      */
-    public function throwErrorFromClass(&$class)
+    public function throwErrorFromClass(AuthorObject $class)
     {
         $this->errorArray = $class->getErrors();
         $class->resetErrors();
     }
-
-    /**
-     * An errorHandler for PHP-errors
-     * @access  private
-     * @param int $no Errornumber
-     * @param string $str Errordescription
-     * @param string $file Filename
-     * @param int $line Linenumber
-     * @param array $ctx All variables
-     */
-    public function errorHandler($no, $str, $file, $line, $ctx)
-    {
-        if (!($no & error_reporting())) {
-            return;
-        }
-        $this->throwError($no, $str, $line, $file, ERROR_CRITICAL);
-        echo MessageBox::error("Schwerer PHP-Laufzeitfehler");
-    }
 }
 
diff --git a/lib/evaluation/classes/Evaluation.class.php b/lib/evaluation/classes/Evaluation.class.php
index df8a2ce3bee..2fd240c739c 100644
--- a/lib/evaluation/classes/Evaluation.class.php
+++ b/lib/evaluation/classes/Evaluation.class.php
@@ -125,8 +125,6 @@ class Evaluation extends EvaluationObject implements PrivacyObject
     public function __construct($objectID = "", $parentObject = null, $loadChildren = EVAL_LOAD_NO_CHILDREN)
     {
         parent::__construct($objectID, $parentObject, $loadChildren);
-        $this->setAuthorEmail("mail@AlexanderWillner.de");
-        $this->setAuthorName("Alexander Willner");
         $this->instanceof = INSTANCEOF_EVAL;
 
         $this->rangeID = [];
diff --git a/lib/evaluation/classes/EvaluationExportManager.class.php b/lib/evaluation/classes/EvaluationExportManager.class.php
index 6155f3605a8..890a9a869fe 100644
--- a/lib/evaluation/classes/EvaluationExportManager.class.php
+++ b/lib/evaluation/classes/EvaluationExportManager.class.php
@@ -121,8 +121,6 @@ class EvaluationExportManager extends AuthorObject
         register_shutdown_function([&$this, "_EvaluationExportManager"]);
 
         parent::__construct();
-        $this->setAuthorEmail("mail@AlexanderWillner.de");
-        $this->setAuthorName("Alexander Willner");
         $this->instanceof = INSTANCEOF_EVALEXPORTMANAGER;
 
         $this->filename = "";
diff --git a/lib/evaluation/classes/EvaluationExportManagerCSV.class.php b/lib/evaluation/classes/EvaluationExportManagerCSV.class.php
index ca3374f7e6f..7d8a47c6983 100644
--- a/lib/evaluation/classes/EvaluationExportManagerCSV.class.php
+++ b/lib/evaluation/classes/EvaluationExportManagerCSV.class.php
@@ -94,8 +94,6 @@ class EvaluationExportManagerCSV extends EvaluationExportManager {
     register_shutdown_function([&$this, "_EvaluationExportManagerCSV"]);
     ini_set('memory_limit', '256M');
     parent::__construct($evalID);
-    $this->setAuthorEmail ("mail@AlexanderWillner.de");
-    $this->setAuthorName ("Alexander Willner");
     $this->instanceof = INSTANCEOF_EVALEXPORTMANAGERCSV;
 
     $this->extension     = EVALEXPORT_EXTENSION;
diff --git a/lib/evaluation/classes/EvaluationGroup.class.php b/lib/evaluation/classes/EvaluationGroup.class.php
index daa04804b8f..fbe84af3bc6 100644
--- a/lib/evaluation/classes/EvaluationGroup.class.php
+++ b/lib/evaluation/classes/EvaluationGroup.class.php
@@ -87,8 +87,6 @@ class EvaluationGroup extends EvaluationObject {
                               $loadChildren = EVAL_LOAD_NO_CHILDREN) {
     /* Set default values ------------------------------------------------- */
     parent::__construct($objectID, $parentObject, $loadChildren);
-    $this->setAuthorEmail ("mail@AlexanderWillner.de");
-    $this->setAuthorName ("Alexander Willner");
     $this->instanceof = INSTANCEOF_EVALGROUP;
 
     $this->childType = NULL;
diff --git a/lib/evaluation/classes/EvaluationObject.class.php b/lib/evaluation/classes/EvaluationObject.class.php
index 26b2d5ec3a6..4bb9423b5a0 100644
--- a/lib/evaluation/classes/EvaluationObject.class.php
+++ b/lib/evaluation/classes/EvaluationObject.class.php
@@ -156,8 +156,6 @@ class EvaluationObject extends StudipObject {
 
     /* Set default values -------------------------------------------------- */
     parent::__construct($objectID);
-    $this->setAuthorEmail ("mail@AlexanderWillner.de");
-    $this->setAuthorName ("Alexander Willner");
     $this->instanceof = INSTANCEOF_EVALOBJECT;
 
     $this->parentObject   = $parentObject;
diff --git a/lib/evaluation/classes/EvaluationTreeEditView.class.php b/lib/evaluation/classes/EvaluationTreeEditView.class.php
index aa423949fba..ef053c78a6d 100644
--- a/lib/evaluation/classes/EvaluationTreeEditView.class.php
+++ b/lib/evaluation/classes/EvaluationTreeEditView.class.php
@@ -3267,7 +3267,6 @@ class EvaluationTreeEditView
         else $group =  &$this->tree->getGroupObject($parentID);
 
         $numberchildren = $group->getNumberChildren();
-        $instance = $group->x_instanceof();
 
         if ($direction == "up") {
             if ($oldposition == 0)
diff --git a/lib/evaluation/evaluation.lib.php b/lib/evaluation/evaluation.lib.php
index 6314454fa31..811e27db67e 100644
--- a/lib/evaluation/evaluation.lib.php
+++ b/lib/evaluation/evaluation.lib.php
@@ -163,48 +163,31 @@ class EvalCommon
 
 
     /**
-     * Creates an errormessage from an object
-     * @param object StudipObejct   $object   A Stud.IP-object
+     * @param $object
+     * @param string $errortitle
+     * @return MessageBox
+     * @deprecated
      */
-    public static function showErsrorReport(&$object, $errortitle = "")
+    public static function createErrorReport(AuthorObject $object, string $errortitle = ''): MessageBox
     {
         $errors = $object->getErrors();
-        if (empty ($errortitle)) {
-            if ($errors && count($errors) > 1) {
-                $errortitle = _("Es sind Fehler aufgetreten.");
+
+        if (!$errortitle) {
+            if (count($errors) > 1) {
+                $errortitle = _('Es sind Fehler aufgetreten.');
             } else {
-                $errortitle = _("Es ist ein Fehler aufgetreten.");
+                $errortitle = _('Es ist ein Fehler aufgetreten.');
             }
         }
 
-        if (!$object->isError()) {
-            return MessageBox::success(_("Es ist kein Fehler aufgetreten"));
-        } else {
-            $details = [];
-            if (!empty($errors)) {
-                foreach ($errors as $error) {
-                    $string = $error['string'];
-                    if ($error["type"] == ERROR_CRITICAL) {
-                        $string .= _("Datei: ") . $error["file"] . '<br>';
-                        $string .= _("Zeile: ") . $error["line"] . '<br>';
-
-                    }
-                    $details[] = $string;
-                }
-            }
-            return MessageBox::error($errortitle, $details);
-        }
-    }
+        $details = array_map(
+            function ($error) {
+                return "#{$error['code']}: {$error['string']}";
+            },
+            $errors
+        );
 
-    /**
-     * @param $object
-     * @param string $errortitle
-     * @return MessageBox|object
-     * @deprecated
-     */
-    public static function createErrorReport(&$object, $errortitle = "")
-    {
-        return MessageBox::error($errortitle);
+        return MessageBox::error($errortitle, $details);
     }
 
     /**
-- 
GitLab