GlobalObjects

From Request Tracker Wiki
Jump to navigation Jump to search

[=$RT::Logger] object

Logging framework in RT is based on Log::Dispatch(http://search.cpan.org/dist/Log-Dispatch) distribution. Debug describe how to configure logging in RT and list all available log levels.

[=RT::[InitLogging]] sub init this object while RT initializing.

Examples:

$RT::Logger->debug( 'debug entry' );

$RT::Logger->critical( 'Something terrible goes wrong' );

You can use this object in Core, Web UI and CLI tools.

[=$RT::SystemUser] object

The object of the [=RT::CurrentUser] class that represent RT system. This user has global SuperUser right. You can use this object as argument to constructors of RT::Record objects. Very useful when you want to do something with RT record and want to be sure that operation wouldn't fail because of permissions problems.

See also ObjectModel section CurrentUser

[=$RT::Nobody] object

Similar as above, but represent user Nobody

if( $TicketObj->Owner == $RT::Nobody->Id ) {

  # ticket has no owner yet, now, owner is nobody
  ...
}

[=$RT::System] object

RT object that represents the RT system itself and is used to check global rights.

$user_obj->HasRight(Right => 'AdminUsers', Object => $RT::System);

Code checks whether user has global right 'AdminUsers' on success return true in other case false.

[=%session] hash (Web UI only)

The Session hash is available in Web UI code only and is used to store user related info. This hash is persistent between requests but only while the session is the same. By default RT uses "session" cookies to track users, the browser typically deletes such cookies if you close it. This object is based on class from Apache::Session distribution.

Hash has standard keys that can be useful in your code:

  • [=$session{'CurrentUser'}] - object of the RT::User class that represent user making current request
  • $session{'i'} - magic variable to force storing of data. Session data is stored only if you change some value in its hash directly only. For eg: changing the real name of the current user doesn't change the session hash because there is a stored reference on the object in the hash, so Apache::Session thinks that data is unchanged and doesn't renew it in storage. traditionally RT uses the following trick $session{'i'}++.
  • ... there are other things that are stored in this hash under different conditions in RT. Grep in Web UI code and/or feel free to describe it here.

Config options

All options that you define in the RT config files are also global variables in RT namespace. You can use them in your code read-only. Yes, you can change them, but don't do that without local and do it only if you know what are you doing and why.

$RT::rtname

$RT::Organisation
$RT::NotifyActor

See [=RT_Config.pm] file for full list of options.