Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
best-practical
rt
Commits
c95221e4
Commit
c95221e4
authored
Sep 30, 2009
by
Jesse Vincent
Browse files
Working to refactor the autohandler to be more maintainable
parent
e86e90bd
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/RT/Interface/Web.pm
View file @
c95221e4
...
...
@@ -317,6 +317,107 @@ sub StripContent {
}
sub
DecodeARGS
{
my
$ARGS
=
shift
;
return
map
{
# if they've passed multiple values, they'll be an array. if they've
# passed just one, a scalar whatever they are, mark them as utf8
my
$type
=
ref
(
$_
);
(
!
$type
)
?
Encode::
is_utf8
(
$_
)
?
$_
:
Encode::
decode
(
'
UTF-8
'
=>
$_
,
Encode::
FB_PERLQQ
)
:
(
$type
eq
'
ARRAY
'
)
?
[
map
{
(
ref
(
$_
)
or
Encode::
is_utf8
(
$_
)
)
?
$_
:
Encode::
decode
(
'
UTF-8
'
=>
$_
,
Encode::
FB_PERLQQ
)
}
@
$_
]
:
(
$type
eq
'
HASH
'
)
?
{
map
{
(
ref
(
$_
)
or
Encode::
is_utf8
(
$_
)
)
?
$_
:
Encode::
decode
(
'
UTF-8
'
=>
$_
,
Encode::
FB_PERLQQ
)
}
%
$_
}
:
$_
}
%$ARGS
;
}
sub
PreprocessTimeUpdates
{
my
$ARGS
=
shift
;
# Later in the code we use
# $m->comp( { base_comp => $m->request_comp }, $m->fetch_next, %ARGS );
# instead of $m->call_next to avoid problems with UTF8 keys in arguments.
# The call_next method pass through original arguments and if you have
# an argument with unicode key then in a next component you'll get two
# records in the args hash: one with key without UTF8 flag and another
# with the flag, which may result into errors. "{ base_comp => $m->request_comp }"
# is copied from mason's source to get the same results as we get from
# call_next method, this feature is not documented, so we just leave it
# here to avoid possible side effects.
# This code canonicalizes time inputs in hours into minutes
foreach
my
$field
(
keys
%$ARGS
)
{
next
unless
$field
=~
/^(.*)-TimeUnits$/i
&&
$ARGS
->
{
$
1
};
my
$local
=
$
1
;
$ARGS
->
{
$local
}
=~
s{\b (?: (\d+) \s+ )? (\d+)/(\d+) \b}
{($1 || 0) + $3 ? $2 / $3 : 0}xe
;
if
(
$ARGS
->
{
$field
}
&&
$ARGS
->
{
$field
}
=~
/hours/i
)
{
$ARGS
->
{
$local
}
*=
60
;
}
delete
$ARGS
->
{
$field
};
}
}
sub
MaybeEnableSQLStatementLog
{
my
$log_sql_statements
=
RT
->
Config
->
Get
('
StatementLog
');
if
(
$log_sql_statements
)
{
$
RT::
Handle
->
ClearSQLStatementLog
;
$
RT::
Handle
->
LogSQLStatements
(
1
);
}
}
sub
LogRecordedSQLStatements
{
my
$log_sql_statements
=
RT
->
Config
->
Get
('
StatementLog
');
return
unless
(
$log_sql_statements
);
my
@log
=
$
RT::
Handle
->
SQLStatementLog
;
$
RT::
Handle
->
ClearSQLStatementLog
;
for
my
$stmt
(
@log
)
{
my
(
$time
,
$sql
,
$bind
,
$duration
)
=
@
{
$stmt
};
my
@bind
;
if
(
ref
$bind
)
{
@bind
=
@
{
$bind
};
}
else
{
# Older DBIx-SB
$duration
=
$bind
;
}
$
RT::
Logger
->
log
(
level
=>
$log_sql_statements
,
message
=>
"
SQL(
"
.
sprintf
(
"
%.6f
",
$duration
)
.
"
s):
$sql
;
"
.
(
@bind
?
"
[ bound values:
@{
[
map
{
qq
|'$
_
'|
}
@bind
]} ]
"
:
""
)
);
}
}
package
HTML::Mason::
Commands
;
use
vars
qw/$r $m %session/
;
...
...
share/html/autohandler
View file @
c95221e4
...
...
@@ -65,12 +65,8 @@ if (RT->InstallMode) {
# Roll back any dangling transactions from a previous failed connection
$
RT::
Handle
->
ForceRollback
()
if
$
RT::
Handle
->
TransactionDepth
;
my
$log_sql_statements
=
RT
->
Config
->
Get
('
StatementLog
');
if
(
$log_sql_statements
)
{
$
RT::
Handle
->
ClearSQLStatementLog
;
$
RT::
Handle
->
LogSQLStatements
(
1
);
}
RT::Interface::Web::
MaybeEnableSQLStatementLog
();
# avoid reentrancy, as suggested by masonbook
local
*session
unless
$m
->
is_subrequest
;
...
...
@@ -80,56 +76,12 @@ if ( $m->request_comp->attr_exists('AutoFlush') ) {
$m
->
autoflush
(
$m
->
request_comp
->
attr
('
AutoFlush
')
);
}
%ARGS
=
map
{
# if they've passed multiple values, they'll be an array. if they've
# passed just one, a scalar whatever they are, mark them as utf8
my
$type
=
ref
(
$_
);
(
!
$type
)
?
Encode::
is_utf8
(
$_
)
?
$_
:
Encode::
decode
(
'
UTF-8
'
=>
$_
,
Encode::
FB_PERLQQ
)
:
(
$type
eq
'
ARRAY
'
)
?
[
map
{
(
ref
(
$_
)
or
Encode::
is_utf8
(
$_
)
)
?
$_
:
Encode::
decode
(
'
UTF-8
'
=>
$_
,
Encode::
FB_PERLQQ
)
}
@
$_
]
:
(
$type
eq
'
HASH
'
)
?
{
map
{
(
ref
(
$_
)
or
Encode::
is_utf8
(
$_
)
)
?
$_
:
Encode::
decode
(
'
UTF-8
'
=>
$_
,
Encode::
FB_PERLQQ
)
}
%
$_
}
:
$_
}
%ARGS
;
# Later in the code we use
# $m->comp( { base_comp => $m->request_comp }, $m->fetch_next, %ARGS );
# instead of $m->call_next to avoid problems with UTF8 keys in arguments.
# The call_next method pass through original arguments and if you have
# an argument with unicode key then in a next component you'll get two
# records in the args hash: one with key without UTF8 flag and another
# with the flag, which may result into errors. "{ base_comp => $m->request_comp }"
# is copied from mason's source to get the same results as we get from
# call_next method, this feature is not documented, so we just leave it
# here to avoid possible side effects.
# This code canonicalizes time inputs in hours into minutes
foreach
my
$field
(
keys
%ARGS
)
{
next
unless
$field
=~
/^(.*)-TimeUnits$/i
&&
$ARGS
{
$
1
};
my
$local
=
$
1
;
$ARGS
{
$local
}
=~
s{\b (?: (\d+) \s+ )? (\d+)/(\d+) \b}
{($1 || 0) + $3 ? $2 / $3 : 0}xe
;
if
(
$ARGS
{
$field
}
&&
$ARGS
{
$field
}
=~
/hours/i
)
{
$ARGS
{
$local
}
*=
60
;
}
delete
$ARGS
{
$field
};
}
%ARGS
=
RT::Interface::Web::
DecodeARGS
(
\
%ARGS
);
RT::Interface::Web::
PreprocessTimeUpdates
(
\
%ARGS
);
$m
->
{'
rt_base_time
'}
=
[
Time::HiRes::
gettimeofday
()
];
...
...
@@ -288,9 +240,7 @@ unless( $session{'CurrentUser'} ) {
# now it applies not only to home page, but any dashboard
# that can be used as a workspace
if
(
$ARGS
{'
HomeRefreshInterval
'}
)
{
$session
{'
home_refresh_interval
'}
=
$ARGS
{'
HomeRefreshInterval
'};
}
$session
{'
home_refresh_interval
'}
=
$ARGS
{'
HomeRefreshInterval
'}
if
(
$ARGS
{'
HomeRefreshInterval
'}
);
# we've got credentials, let's serve the file up.
# Process per-page global callbacks
...
...
@@ -319,27 +269,8 @@ else {
$m
->
comp
(
{
base_comp
=>
$m
->
request_comp
},
$m
->
fetch_next
,
%ARGS
);
}
if
(
$log_sql_statements
)
{
my
@log
=
$
RT::
Handle
->
SQLStatementLog
;
$
RT::
Handle
->
ClearSQLStatementLog
;
for
my
$stmt
(
@log
)
{
my
(
$time
,
$sql
,
$bind
,
$duration
)
=
@
{
$stmt
};
my
@bind
;
if
(
ref
$bind
)
{
@bind
=
@
{
$bind
};
}
else
{
# Older DBIx-SB
$duration
=
$bind
;
}
$
RT::
Logger
->
log
(
level
=>
$log_sql_statements
,
message
=>
"
SQL(
"
.
sprintf
(
"
%.6f
",
$duration
)
.
"
s):
$sql
;
"
.
(
@bind
?
"
[ bound values:
@{
[
map
{
qq
|'$
_
'|
}
@bind
]} ]
"
:
""
)
);
}
}
RT::Interface::Web::
LogRecordedSQLStatements
();
$m
->
comp
(
'
/Elements/Footer
',
%ARGS
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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