+ require RT::Attributes;
+ require RT::Dashboard;
+ require RT::Approval;
+ require RT::Lifecycle;
+ require RT::Link;
+ require RT::Links;
+ require RT::Article;
+ require RT::Articles;
+ require RT::Class;
+ require RT::Classes;
+ require RT::ObjectClass;
+ require RT::ObjectClasses;
+ require RT::ObjectTopic;
+ require RT::ObjectTopics;
+ require RT::Topic;
+ require RT::Topics;
+
+ # on a cold server (just after restart) people could have an object
+ # in the session, as we deserialize it so we never call constructor
+ # of the class, so the list of accessible fields is empty and we die
+ # with "Method xxx is not implemented in RT::SomeClass"
+
+ # without this, we also can never call _ClassAccessible, because we
+ # won't have filled RT::Record::_TABLE_ATTR
+ $_->_BuildTableAttributes foreach qw(
+ RT::Ticket
+ RT::Transaction
+ RT::Attachment
+ RT::User
+ RT::Principal
+ RT::Template
+ RT::Queue
+ RT::ScripAction
+ RT::ScripCondition
+ RT::Scrip
+ RT::Group
+ RT::GroupMember
+ RT::CustomField
+ RT::CustomFieldValue
+ RT::ObjectCustomField
+ RT::ObjectCustomFieldValue
+ RT::Attribute
+ RT::ACE
+ RT::Link
+ RT::Article
+ RT::Class
+ RT::ObjectClass
+ RT::ObjectTopic
+ RT::Topic
+ );
+
+ if ( $args{'Heavy'} ) {
+ # load scrips' modules
+ my $scrips = RT::Scrips->new(RT->SystemUser);
+ $scrips->Limit( FIELD => 'Stage', OPERATOR => '!=', VALUE => 'Disabled' );
+ while ( my $scrip = $scrips->Next ) {
+ local $@;
+ eval { $scrip->LoadModules } or
+ $RT::Logger->error("Invalid Scrip ".$scrip->Id.". Unable to load the Action or Condition. ".
+ "You should delete or repair this Scrip in the admin UI.\n$@\n");
+ }
+
+ foreach my $class ( grep $_, RT->Config->Get('CustomFieldValuesSources') ) {
+ local $@;
+ eval "require $class; 1" or $RT::Logger->error(
+ "Class '$class' is listed in CustomFieldValuesSources option"
+ ." in the config, but we failed to load it:\n$@\n"
+ );
+ }
+
+ }
+}
+
+=head2 InitSystemObjects
+
+Initializes system objects: C<$RT::System>, C<< RT->SystemUser >>
+and C<< RT->Nobody >>.
+
+=cut
+
+sub InitSystemObjects {
+
+ #RT's system user is a genuine database user. its id lives here
+ require RT::CurrentUser;
+ $SystemUser = RT::CurrentUser->new;
+ $SystemUser->LoadByName('RT_System');
+
+ #RT's "nobody user" is a genuine database user. its ID lives here.
+ $Nobody = RT::CurrentUser->new;
+ $Nobody->LoadByName('Nobody');
+
+ require RT::System;
+ $System = RT::System->new( $SystemUser );
+}
+
+=head1 CLASS METHODS
+
+=head2 Config
+
+Returns the current L<config object|RT::Config>, but note that
+you must L<load config|/LoadConfig> first otherwise this method
+returns undef.
+
+Method can be called as class method.
+
+=cut
+
+sub Config { return $Config || shift->LoadConfig(); }
+
+=head2 DatabaseHandle
+
+Returns the current L<database handle object|RT::Handle>.
+
+See also L</ConnectToDatabase>.
+
+=cut
+
+sub DatabaseHandle { return $Handle }
+
+=head2 Logger
+
+Returns the logger. See also L</InitLogging>.
+
+=cut
+
+sub Logger { return $Logger }
+
+=head2 System
+
+Returns the current L<system object|RT::System>. See also
+L</InitSystemObjects>.
+
+=cut
+
+sub System { return $System }
+
+=head2 SystemUser
+
+Returns the system user's object, it's object of
+L<RT::CurrentUser> class that represents the system. See also
+L</InitSystemObjects>.
+
+=cut
+
+sub SystemUser { return $SystemUser }
+
+=head2 Nobody
+
+Returns object of Nobody. It's object of L<RT::CurrentUser> class
+that represents a user who can own ticket and nothing else. See
+also L</InitSystemObjects>.
+
+=cut
+
+sub Nobody { return $Nobody }
+
+sub PrivilegedUsers {
+ if (!$_Privileged) {
+ $_Privileged = RT::Group->new(RT->SystemUser);
+ $_Privileged->LoadSystemInternalGroup('Privileged');
+ }
+ return $_Privileged;
+}
+
+sub UnprivilegedUsers {
+ if (!$_Unprivileged) {
+ $_Unprivileged = RT::Group->new(RT->SystemUser);
+ $_Unprivileged->LoadSystemInternalGroup('Unprivileged');
+ }
+ return $_Unprivileged;
+}
+
+
+=head2 Plugins
+
+Returns a listref of all Plugins currently configured for this RT instance.
+You can define plugins by adding them to the @Plugins list in your RT_SiteConfig
+
+=cut
+
+our @PLUGINS = ();
+sub Plugins {
+ my $self = shift;
+ unless (@PLUGINS) {
+ $self->InitPluginPaths;
+ @PLUGINS = $self->InitPlugins;
+ }
+ return \@PLUGINS;
+}
+
+=head2 PluginDirs
+
+Takes an optional subdir (e.g. po, lib, etc.) and returns a list of
+directories from plugins where that subdirectory exists.
+
+This code does not check plugin names, plugin validitity, or load
+plugins (see L</InitPlugins>) in any way, and requires that RT's
+configuration have been already loaded.
+
+=cut
+
+sub PluginDirs {
+ my $self = shift;
+ my $subdir = shift;
+
+ require RT::Plugin;
+
+ my @res;
+ foreach my $plugin (grep $_, RT->Config->Get('Plugins')) {
+ my $path = RT::Plugin->new( name => $plugin )->Path( $subdir );
+ next unless -d $path;
+ push @res, $path;
+ }
+ return @res;