3 #########################
5 # Find duplicate exception timestamps and list them.
6 # Additionally find exceptions that have no exception code.
7 # Optionally write the list of found exception codes to the standard output stream in JSON format.
9 # It expects to be run from the core root.
11 ##########################
13 # --------------------------
14 # --- default parameters ---
15 # --------------------------
20 # auto generated file, shouldn't be checked
21 ignoreFiles
+="sysext/core/Tests/Acceptance/Support/_generated/BackendTesterActions.php"
22 ignoreFiles
+="sysext/core/Tests/Acceptance/Support/_generated/InstallTesterActions.php"
23 # an exception in here throws a code from a previous exception/error
24 ignoreFiles
+="sysext/extbase/Classes/Core/Bootstrap.php"
25 ignoreFiles
+="sysext/form/Classes/Mvc/Property/Exception/TypeConverterException.php"
26 ignoreFiles
+="sysext/core/Classes/Database/Driver/PDOStatement.php"
27 ignoreFiles
+="sysext/core/Classes/Database/Driver/PDOStatementImplementation.php"
28 ignoreFiles
+="sysext/core/Classes/Database/Driver/PDOConnection.php"
29 ignoreFiles
+="sysext/frontend/Classes/Typolink/PageLinkBuilder.php"
31 # ------------------------
32 # --- print usage info ---
33 # ------------------------
36 echo "Usage: $0 [options] "
38 echo "No arguments/default: Check exception numbers for duplicates. "
42 echo " Specifies whether the list of exceptions found should "
43 echo " be output as JSON in the standard output stream. "
46 echo " Show this help. "
51 # -----------------------
52 # --- parsing of args ---
53 # -----------------------
56 while getopts "hp" opt
;do
72 # ------------------------------------------------
73 # --- print list of found exceptions to stdout ---
74 # ------------------------------------------------
76 IFS
=$
'\n' sorted
=($
(sort -u <<<"${exceptionCodes[*]}")); unset IFS
78 local numExceptions
=${#sorted[@]}
81 printf " \"exceptions\": {\n"
82 if [ ${numExceptions} -gt 0 ]; then
83 for (( i
=0; i
<${numExceptions}-1; i
++ ));
85 printf " \"%s\":\"%s\",\n" "${sorted[$i]}" "${sorted[$i]}"
87 printf " \"%s\":\"%s\"\n" "${sorted[${numExceptions}-1]}" "${sorted[${numExceptions}-1]}"
90 printf " \"total\":%s\n" "${numExceptions}"
94 # -------------------------------------------------------------------------------
95 # --- check PHP files recursively for missing and duplicate exception numbers ---
96 # -------------------------------------------------------------------------------
100 local firstLineOfMatch
=""
101 local foundExceptionInFile
=1
102 local exceptionCodes
=()
106 # '--include '*.php'' in all .php files
107 # '-Pzoab' pcre regex, -zo remove all linebreaks for multiline match, treat all files as text, output position "filename:position: match", binary position
109 # (?:(?!Exception\()[\w\\])* negative lookahead. capture all alphanum and \ until we reach "Exception("
111 # (?:(?!\);).|[\r\n])*\);[\r\n]+ negative lookahead again, eat everything including a \n until we reach the first ");", then line breaks
113 cd "$scanPath" ||
exit 1
119 'new (?:(?!Exception\()[\w\\])*Exception\((?:(?!\);).|[\r\n])*\);[\r\n]+' \
124 possibleFilename
=`echo ${line} | cut -d':' -f1`
125 if [[ ${possibleFilename} =~ .php$
]]; then
126 # the matched line consists of a file name match, we're dealing with a new match here.
128 oldFilename
=${currentFilename}
129 currentFilename
=${possibleFilename}
134 # skip file if in blacklist
135 if [[ {$ignoreFiles[@
]} =~
${currentFilename} ]]; then
139 # check for match in previous file name
140 if [[ ${foundNewFile} -eq 1 ]] && [[ ${foundExceptionInFile} -eq 0 ]]; then
141 if [ "$print" -ne "1" ]; then
142 # checking exception codes: exit
143 # listing exception codes: ignore
144 echo "File: $oldFilename"
145 echo "The created exception contains no 10 digit exception code as second argument, in or below this line:"
146 echo "$firstLineOfMatch"
151 # reset found flag if we're handling new file
152 if [[ ${foundNewFile} -eq 1 ]]; then
153 foundExceptionInFile
=0
154 firstLineOfMatch
=${line}
157 # see if the line consists of an exception code
158 if [[ "$line" =~ .
*([0-9]{10}).
* ]]; then
159 foundExceptionInFile
=1
160 exceptionCode
=${BASH_REMATCH[1]}
161 # check if that code was registered already
162 if [[ " ${exceptionCodes[@]} " =~
" ${exceptionCode} " ]]; then
163 if [ "$print" -ne "1" ]; then
164 # checking exception codes: exit
165 # listing exception codes: ignore
166 echo "Duplicate exception code ${exceptionCode} in file:"
167 echo ${currentFilename}
171 exceptionCodes
+=(${exceptionCode})
175 if [ "$print" -eq "1" ]; then