]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1284263 - Add optional support for $DATABASE_URL instead of localconfig for db_...
authorDylan William Hardison <dylan@hardison.net>
Mon, 4 Jul 2016 14:43:48 +0000 (10:43 -0400)
committerDylan William Hardison <dylan@hardison.net>
Sat, 10 Sep 2016 16:40:58 +0000 (12:40 -0400)
Bugzilla/Install/Localconfig.pm
META.json
META.yml
Makefile.PL
template/en/default/global/user-error.html.tmpl
template/en/default/setup/strings.txt.pl

index 82ec9ae35e9a22b6d2cca5871f5a5a2001223c95..d591ece15051aa0fd6fc52400a3deca8d133364b 100644 (file)
@@ -59,6 +59,10 @@ use constant LOCALCONFIG_VARS => (
         name    => 'use_suexec',
         default => 0,
     },
+    {
+        name => 'db_from_env',
+        default => 0,
+    },
     {
         name    => 'db_driver',
         default => 'sqlite',
@@ -198,6 +202,25 @@ sub read_localconfig {
             }
         }
     }
+    require Bugzilla::Error;
+    if ($localconfig{db_from_env}) {
+        if (Bugzilla->has_feature('db_from_env')) {
+            require URI::db;
+            unless ($ENV{DATABASE_URL}) {
+                Bugzilla::Error::ThrowUserError('missing_database_url');
+            }
+            my $uri = URI::db->new($ENV{DATABASE_URL});
+            $localconfig{db_driver} = $uri->canonical_engine;
+            $localconfig{db_name}   = $uri->dbname;
+            $localconfig{db_host}   = $uri->host;
+            $localconfig{db_user}   = $uri->user;
+            $localconfig{db_pass}   = $uri->password;
+            $localconfig{db_port}   = $uri->port // 0;
+        }
+        else {
+            Bugzilla::Error::ThrowUserError('feature_disabled', { feature => 'db_from_env' });
+        }
+    }
 
     return \%localconfig;
 }
@@ -233,6 +256,7 @@ sub update_localconfig {
     my $output      = $params->{output} || 0;
     my $answer      = Bugzilla->installation_answers;
     my $localconfig = read_localconfig('include deprecated');
+    my $db_from_env = Bugzilla->localconfig->{db_from_env};
 
     my @new_vars;
     foreach my $var (LOCALCONFIG_VARS) {
@@ -258,7 +282,7 @@ sub update_localconfig {
                 # an answer file, then we don't notify about site_wide_secret
                 # because we assume the intent was to auto-generate it anyway.
                 if (!scalar(keys %$answer) || $name ne 'site_wide_secret') {
-                    push(@new_vars, $name);
+                    push(@new_vars, $name) unless $db_from_env && $name =~ /^db_(?!from_env)/;
                 }
                 $localconfig->{$name} = $var->{default};
             }
@@ -298,6 +322,9 @@ sub update_localconfig {
     foreach my $var (LOCALCONFIG_VARS) {
         my $name = $var->{name};
         my $desc = $var->{desc};
+
+        next if $db_from_env && $name =~ /^db_(?!from_env)/;
+
         if(!length $desc){
             $desc = install_string("localconfig_$name", { root => ROOT_USER });
             chomp($desc);
index 26053a8e2efb70832dfe42e69e15909d4102795f..8b939e4962eec69740c5c885b68e4bf5ab6ae485 100644 (file)
--- a/META.json
+++ b/META.json
@@ -4,7 +4,7 @@
       "Bugzilla Developers <developers@bugzilla.org>"
    ],
    "dynamic_config" : 1,
-   "generated_by" : "ExtUtils::MakeMaker version 7.18, CPAN::Meta::Converter version 2.143240",
+   "generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150005",
    "license" : [
       "unknown"
    ],
             }
          }
       },
+      "db_from_env" : {
+         "description" : "Support for using $ENV{DATABASE_URL}",
+         "prereqs" : {
+            "runtime" : {
+               "requires" : {
+                  "URI::db" : "0.17"
+               }
+            }
+         }
+      },
       "detect_charset" : {
          "description" : "Automatic charset detection for text attachments",
          "prereqs" : {
       }
    },
    "release_status" : "stable",
-   "version" : "v5.1.1+"
+   "version" : "v5.1.1+",
+   "x_serialization_backend" : "JSON::PP version 2.27300"
 }
index c606232de305cf631cc26d487845bab1c72cda76..3e7792e9c2d5caa86b56d5cd72de93b5475906a1 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -12,7 +12,7 @@ build_requires:
 configure_requires:
   ExtUtils::MakeMaker: '6.55'
 dynamic_config: 1
-generated_by: 'ExtUtils::MakeMaker version 7.18, CPAN::Meta::Converter version 2.143240'
+generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150005'
 license: unknown
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -40,6 +40,10 @@ optional_features:
     requires:
       MooX::StrictConstructor: '0.008'
       Type::Tiny: '1'
+  db_from_env:
+    description: 'Support for using $ENV{DATABASE_URL}'
+    requires:
+      URI::db: '0.17'
   detect_charset:
     description: 'Automatic charset detection for text attachments'
     requires:
@@ -190,3 +194,4 @@ requires:
   URI: '1.55'
   perl: '5.014000'
 version: v5.1.1+
+x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
index 36559b63c9b91b3ec77ddb2bbc059e8da8c9370b..3af1d58e5925c311c92341c90b7afdd38c413525 100644 (file)
@@ -298,6 +298,14 @@ my %optional_features = (
             }
         }
     },
+    db_from_env => {
+        description => 'Support for using $ENV{DATABASE_URL}',
+        prereqs => {
+            runtime => {
+                requires => { 'URI::db' => '0.17' },
+            },
+        },
+    },
 );
 
 for my $file ( glob("extensions/*/Config.pm") ) {
index dd6c71539b5eea7e5eaecd2de197fad001bccd65..fa5af632ce8831714e423e029399f2b073d6f946 100644 (file)
 
   [% ELSIF error == "feature_disabled" %]
     The [% feature_description(feature) FILTER html %] feature is not available in this Bugzilla.
-    [% IF user.in_group('admin') %]
+    [% IF user.in_group('admin') || Bugzilla.usage_mode != constants.USAGE_MODE_BROWSER %]
       If you would like to enable this feature, please run
       <kbd>cpanm -l local --installdeps --with-feature [% feature FILTER html %] "."</kbd>
     [% END %]
     the results of your last search. I'm afraid you will have to start
     again from the <a href="query.cgi">search page</a>.
 
+  [% ELSIF error == "missing_database_url" %]
+    [% title = "Missing \$DATABASE_URL" %]
+    $DATABASE_URL must be defined when localconfig "db_from_env" option is enabled.
+
   [% ELSIF error == "missing_datasets" %]
     [% title = "No Datasets Selected" %]
     [% docslinks = {'using/reports-and-charts.html' => 'Reporting'} %]
index 3adb06b8571f878ce777f705ca25478b82c1f787..34bbba2b794f3d1cf253f44b7c464998d7593c51 100644 (file)
@@ -128,6 +128,11 @@ Should checksetup.pl try to verify that your database setup is correct?
 With some combinations of database servers/Perl modules/moonphase this
 doesn't work, and so you can try setting this to 0 to make checksetup.pl
 run.
+END
+    localconfig_db_from_env => <<'END',
+If this is set, the other db_* values will be ignored and instead the $DATABASE_URL
+will be used to provide the database connection information.
+Note this requires the 'db_from_env' feature to be enabled.
 END
     localconfig_db_driver => <<'END',
 What SQL database to use. Default is mysql. List of supported databases