Error.php 6.82 KB
Newer Older
1
2
3
4
<?php
/***************************************************************
 *  Copyright notice
 *
Carsten  Rose's avatar
Carsten Rose committed
5
 *  (c) 2010 Glowbase GmbH
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

namespace qfq;

//use qfq;

/**
 * syntaxException: Webmaster made a mistake in tt_content record or form definition
 *
Carsten  Rose's avatar
Carsten Rose committed
31
32
33
34
 * @param    string $message
 * @param    string $code
 * @param    string $file
 * @param    string $line
Carsten  Rose's avatar
Carsten Rose committed
35
36
 * @param    string|array $customMessage =array()   a) string: "key: value",  b) array("key1: value1","key2: value2",
 *                                       ...) - all items will be displayed on an own line in the error message.
37
38
39
40
 */
class SyntaxReportException extends \Exception {
    private $fr_error;

Carsten  Rose's avatar
Carsten Rose committed
41
    /**
Carsten  Rose's avatar
Carsten Rose committed
42
43
     * @param string $message
     * @param int $code
44
     * @param \Exception $previous
Carsten  Rose's avatar
Carsten Rose committed
45
46
     * @param            $file
     * @param            $line
Carsten  Rose's avatar
Carsten Rose committed
47
48
     * @param array $customMessage
     * @param array $fr_error
Carsten  Rose's avatar
Carsten Rose committed
49
     */
50
    public function __construct($message, $code, $previous, $file, $line, $customMessage = array(), $fr_error = array()) {
51
52
53
54
55
56
57
58
59
        parent::__construct($message);
        $this->code = $code;
        $this->file = $file;
        $this->line = $line;
        $this->customMessage = $customMessage;
        $this->fr_error = $fr_error;

    }

Carsten  Rose's avatar
Carsten Rose committed
60
61
62
    /**
     * @return string
     */
63
    public function errorMessage() {
64
65
        $store = Store::getInstance();

66
        // If '$this->customMessage' is a string, convert it to an array.
67
68
        if ($this->customMessage && !is_array($this->customMessage))
            $this->customMessage = [$this->customMessage];
69
70

        //error message
71
        if (Support::findInSet(SYSTEM_SHOW_DEBUG_INFO_YES, $store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM))) {
72

73
74
75
76
77
78
79
80
            $errorMsg = nl2br("<hr />Error: <strong>" . htmlentities($this->getMessage()) . "</strong><br />");
            $errorMsg .= "Formreport statement: <strong>" . htmlentities($this->fr_error["row"]) . "</strong><br />";

            // Print custom messages.
            foreach ($this->customMessage as $value) {
                $tmparr = explode(":", $value, 2);
                $errorMsg .= $tmparr[0] . ":<strong>" . htmlentities($tmparr[1]) . "</strong><br />";
            }
81

82
83
84
85
86
87
88
            $errorMsg .= "T3 Page pid: <strong>" . $this->fr_error["pid"] . "</strong><br />";
            $errorMsg .= "ttcontent record uid: <strong>" . $this->fr_error["uid"] . "</strong><br />";
            $errorMsg .= "File:  <strong>" . $this->file . "</strong><br />Line:  <strong>" . $this->line . "</strong><br />MSG: <strong>" . $this->code . "</strong><br />";
            $errorMsg .= "StackTrace<pre>" . nl2br($this->getTraceAsString()) . "</pre><hr />";
        } else {
            $errorMsg = "<hr />Error: <strong>" . htmlentities($this->getMessage()) . "</strong><hr />";
        }
89

90
        return $errorMsg;
91

92
93
94
95
96
97
98
99
100
101
102
    }  // errorMessage()
} // class syntaxException

/**
 * sqlException: An SQL-Query returned an unexpected result
 *
 * @param    string $message
 * @param    string $sql
 * @param    string $file
 * @param    string $line
 */
103
class SqlReportExceptionUnused extends \Exception {
104
105
    private $fr_error;

Carsten  Rose's avatar
Carsten Rose committed
106
    /**
Carsten  Rose's avatar
Carsten Rose committed
107
108
     * @param string $message
     * @param int $sql
Carsten  Rose's avatar
Carsten Rose committed
109
     * @param \Exception $file
Carsten  Rose's avatar
Carsten Rose committed
110
     * @param            $line
Carsten  Rose's avatar
Carsten Rose committed
111
     * @param array $fr_error
Carsten  Rose's avatar
Carsten Rose committed
112
     */
113
114
115
116
117
118
119
120
    public function __construct($message, $sql, $file, $line, $fr_error = array()) {
        parent::__construct($message);
        $this->file = $file;
        $this->line = $line;
        $this->sql = $sql;
        $this->fr_error = $fr_error;
    }

Carsten  Rose's avatar
Carsten Rose committed
121
122
123
    /**
     * @return string
     */
124
125
126
    public function errorMessage() {
//		global $BE_USER; TA: Du sollst kein global verwenden!!

127
128
129
130
        $formreport = Session::get(FORMREPORT);
        $beUserUid = ($formreport !== false && isset($formreport['be_user_uid'])) ? $formreport['be_user_uid'] : 0;

        if ($GLOBALS['BE_USER']->user["uid"] > 0 || $beUserUid > 0) {
131
132
133
134
135
136
137
138
139
140
141
            $errorMsg = nl2br("<hr />Error: <strong>" . htmlentities($this->getMessage()) . "</strong><br />MySQL:  <strong>" . mysql_error() . "</strong><hr />");
            $errorMsg .= "SQL: <strong>" . htmlentities($this->sql) . "</strong><hr />";
            $errorMsg .= "Formreport: <strong>" . $this->fr_error["row"] . "</strong><hr />";
            $errorMsg .= "T3 Page pid: <strong>" . $this->fr_error["pid"] . "</strong><br>";
            $errorMsg .= "ttcontent record uid: <strong>" . $this->fr_error["uid"] . "</strong><br />";
            $errorMsg .= "Line: <strong>" . $this->line . "</strong><br />File: <strong>" . $this->file . "</strong><hr />";

            $errorMsg .= "StackTrace<pre>" . nl2br($this->getTraceAsString()) . "</pre><hr />";
        } else {
            $errorMsg = "<hr />Error: <strong>" . htmlentities($this->getMessage()) . "</strong><hr />";
        }
Carsten  Rose's avatar
Carsten Rose committed
142

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
        return $errorMsg;
    }  // errorMessage()
} // class sqlException

/**
 * codeException: Error in formreport code
 *
 * @param    string $message
 * @param    string $file
 * @param    string $line
 */
class CodeReportException extends \Exception {

    protected $file;
    protected $line;

Carsten  Rose's avatar
Carsten Rose committed
159
160
161
162
163
    /**
     * @param string $message
     * @param string $file
     * @param string $line
     */
164
165
166
167
168
169
    public function __construct($message, $file = "undefined", $line = "undefined") {
        parent::__construct($message);
        $this->file = $file;
        $this->line = $line;
    }

Carsten  Rose's avatar
Carsten Rose committed
170
171
172
    /**
     * @return string
     */
173
174
    public function errorMessage() {

175
176
177
        $formreport = Session::get(FORMREPORT);
        $beUserUid = ($formreport !== false && isset($formreport['be_user_uid'])) ? $formreport['be_user_uid'] : 0;
        if ($GLOBALS['BE_USER']->user["uid"] > 0 || $beUserUid > 0) {
178
179
180
181
182
183
184
185
186
187
188
189
190
            $errorMsg = nl2br("<hr />Error: <strong>" . $this->getMessage() . "</strong><br />File:  <strong>" . $this->file . "</strong><br />Line:  <strong>" . $this->line . "</strong><hr />");
            $errorMsg .= "StackTrace<pre>" . nl2br($this->getTraceAsString()) . "</pre><hr />";
        } else {
            $errorMsg = "<hr />Error: <strong>" . $this->getMessage() . "</strong><hr />";
        }

        return $errorMsg;
    }  // errorMessage()
} // class codeException