Index: /trunk/lib/MT.pm
===================================================================
--- /trunk/lib/MT.pm (revision 3581)
+++ /trunk/lib/MT.pm (revision 3892)
@@ -545,5 +545,5 @@
             $settings = $plugin->{registry}{config_settings} = $settings->()
               if ref($settings) eq 'CODE';
-            $class->config->define($settings);
+            $class->config->define($settings) if $settings;
         }
     }
@@ -828,14 +828,18 @@
     my ($param) = @_;
 
-    my $cfg_file = $mt->find_config($param);
-    return $mt->error(
-"Missing configuration file. Maybe you forgot to move mt-config.cgi-original to mt-config.cgi?"
-    ) unless $cfg_file;
-    $cfg_file = File::Spec->rel2abs($cfg_file);
+    unless ($mt->{cfg_file}) {
+        my $cfg_file = $mt->find_config($param);
+
+        return $mt->error(
+            "Missing configuration file. Maybe you forgot to move mt-config.cgi-original to mt-config.cgi?"
+        ) unless $cfg_file;
+        $cfg_file = File::Spec->rel2abs($cfg_file);
+        $mt->{cfg_file} = $cfg_file;
+    }
 
     # translate the config file's location to an absolute path, so we
     # can use that directory as a basis for calculating other relative
     # paths found in the config file.
-    my $config_dir = $mt->{config_dir} = dirname($cfg_file);
+    my $config_dir = $mt->{config_dir} = dirname($mt->{cfg_file});
 
     # store the mt_dir (home) as an absolute path; fallback to the config
@@ -850,19 +854,20 @@
     # checking the PWD environment variable, the dirname of $0,
     # the directory of SCRIPT_FILENAME and lastly, falls back to mt_dir
-    $mt->{app_dir} = $ENV{PWD} || "";
-    $mt->{app_dir} = dirname($0)
-      if !$mt->{app_dir}
-      || !File::Spec->file_name_is_absolute( $mt->{app_dir} );
-    $mt->{app_dir} = dirname( $ENV{SCRIPT_FILENAME} )
-      if $ENV{SCRIPT_FILENAME}
-      && ( !$mt->{app_dir}
-        || ( !File::Spec->file_name_is_absolute( $mt->{app_dir} ) ) );
-    $mt->{app_dir} ||= $mt->{mt_dir};
-    $mt->{app_dir} = File::Spec->rel2abs( $mt->{app_dir} );
+    unless ($mt->{app_dir}) {
+        $mt->{app_dir} = $ENV{PWD} || "";
+        $mt->{app_dir} = dirname($0)
+          if !$mt->{app_dir}
+          || !File::Spec->file_name_is_absolute( $mt->{app_dir} );
+        $mt->{app_dir} = dirname( $ENV{SCRIPT_FILENAME} )
+          if $ENV{SCRIPT_FILENAME}
+          && ( !$mt->{app_dir}
+            || ( !File::Spec->file_name_is_absolute( $mt->{app_dir} ) ) );
+        $mt->{app_dir} ||= $mt->{mt_dir};
+        $mt->{app_dir} = File::Spec->rel2abs( $mt->{app_dir} );
+    }
 
     my $cfg = $mt->config;
     $cfg->define( $mt->registry('config_settings') );
-    $cfg->read_config($cfg_file) or return $mt->error( $cfg->errstr );
-    $mt->{cfg_file} = $cfg_file;
+    $cfg->read_config($mt->{cfg_file}) or return $mt->error( $cfg->errstr );
 
     my @mt_paths = $cfg->paths;
@@ -881,4 +886,5 @@
             }
             else {
+                next if ref($path); # unexpected referene, ignore
                 if ( !File::Spec->file_name_is_absolute($path) ) {
                     $path = File::Spec->catfile( $config_dir, $path );
@@ -1054,8 +1060,15 @@
     my ($param) = @_;
     my $cfg = $mt->config;
+
+    # Tell any instantiated drivers to reconfigure themselves as necessary
+    require MT::ObjectDriverFactory;
+    if (MT->config('ObjectDriver')) {
+        my $driver = MT::ObjectDriverFactory->instance;
+        $driver->configure if $driver;
+    } else {
+        MT::ObjectDriverFactory->configure();
+    }
+
     $cfg->read_config_db();
-
-    # Tell any instantiated drivers to reconfigure themselves as necessary
-    MT::ObjectDriverFactory->configure;
 
     1;
@@ -1197,5 +1210,5 @@
     $mt->init_lang_defaults(@_) or return;
     require MT::Plugin;
-    $mt->init_addons(@_)       or return;
+    $mt->init_addons(@_)        or return;
     $mt->init_config_from_db( \%param ) or return;
     $mt->init_plugins(@_)       or return;
@@ -1405,4 +1418,5 @@
                             next;
                         }
+                        next if exists $Plugins{$plugin_dir};
                         my $id = lc $plugin_dir;
                         $id =~ s/\.\w+$//;
@@ -1418,6 +1432,5 @@
                         local $plugin_sig = $plugin_dir;
                         MT->add_plugin($p);
-                        $p->init_callbacks()
-                            if $pclass eq 'MT::Plugin';
+                        $p->init_callbacks();
                         next;
                     }
@@ -2296,4 +2309,5 @@
     my $timeout = exists $opt->{timeout} ? $opt->{timeout} : $cfg->HTTPTimeout || $cfg->PingTimeout;
     my $proxy = exists $opt->{proxy} ? $opt->{proxy} : $cfg->HTTPProxy || $cfg->PingProxy;
+    my $sec_proxy = exists $opt->{sec_proxy} ? $opt->{sec_proxy} : $cfg->HTTPSProxy;
     my $no_proxy = exists $opt->{no_proxy} ? $opt->{no_proxy} : $cfg->HTTPNoProxy || $cfg->PingNoProxy;
     my $agent = $opt->{agent} || 'MovableType/' . $MT::VERSION;
@@ -2315,4 +2329,7 @@
         my @domains = split( /,\s*/, $no_proxy ) if $no_proxy;
         $ua->no_proxy(@domains) if @domains;
+    }
+    if ( defined $sec_proxy ) {
+        $ua->proxy ( https => $sec_proxy );
     }
     return $ua;
@@ -3047,9 +3064,5 @@
 }
 
-sub DESTROY {
-    # save_config here so not to miss any dirty config change to persist
-    # particulary for those which does not construct MT::App.
-    $_[0]->config->save_config();
-}
+sub DESTROY { }
 
 1;
