Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
59eb4aae
Commit
59eb4aae
authored
Oct 20, 2006
by
Nigel McNie
Committed by
Nigel McNie
Oct 20, 2006
Browse files
Added a simple script to add an log hook everywhere an error is set.
parent
563ee8ec
Changes
1
Hide whitespace changes
Inline
Side-by-side
scripts/xmldb-error-reporting.pl
0 → 100644
View file @
59eb4aae
#!/usr/bin/perl
#
# Takes an XMLDB directory and adds a hook for error reporting wherever error
# messages are defined.
#
# This will change your XMLDB directory and will not make a backup, so make
# one yourself before running this
#
# Author: Nigel McNie <nigel@catalyst.net.nz>
#
use
warnings
;
use
strict
;
use
Getopt::
Long
qw(:config permute)
;
sub
show_help
;
sub
show_version
;
my
(
$help
,
$version
);
GetOptions
(
'
help
'
=>
\
$help
,
'
version
'
=>
\
$version
);
show_help
if
$help
;
show_version
if
$version
;
my
$directory
=
$ARGV
[
0
];
die
(
$directory
.
'
is not a directory
')
unless
-
d
$directory
;
die
(
$directory
.
'
does not look like an XMLDB directory (no xmldb.dtd)
')
unless
-
e
"
$directory
/xmldb.dtd
";
# Add xmldb_dbg lines to each file that needs them
my
@files
=
('
XMLDBField.class.php
',
'
XMLDBFile.class.php
',
'
XMLDBIndex.class.php
',
'
XMLDBKey.class.php
',
'
XMLDBObject.class.php
',
'
XMLDBStatement.class.php
',
'
XMLDBStructure.class.php
',
'
XMLDBTable.class.php
');
for
my
$file
(
@files
)
{
print
"
processing
$file
...
\n
";
open
(
FH
,
"
$directory
/classes/
$file
");
my
@lines
=
<
FH
>
;
my
@newlines
=
();
for
my
$line
(
@lines
)
{
if
(
$line
=~
m/(.*)\$this->errormsg = '/
)
{
push
@newlines
,
$line
;
push
@newlines
,
"
$1xmldb_dbg(
\$
this->errormsg);
\n
";
}
else
{
push
@newlines
,
$line
;
}
}
close
(
FH
);
open
(
FH
,
"
>
$directory
/classes/
$file
");
for
my
$line
(
@newlines
)
{
print
FH
$line
;
}
close
(
FH
);
}
print
<<EOF;
Done!
Now you must define the xmldb_dbg function somewhere such that it will be
available whenever an error occurs. A simple version might be:
function xmldb_dbg(\$message) {
error_log(\$message);
}
EOF
#
# Subroutines
#
sub
show_help
{
print
<<EOF;
Takes an XMLDB directory and adds a hook for error reporting wherever error
messages are defined.
Usage: $0 /path/to/XMLDB/directory
EOF
exit
0
;
}
sub
show_version
{
print
"
0.1.0
\n
";
exit
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment