Partially refactor database configuration

This patch refactors database handling in certain development scripts
This commit is contained in:
Peter Kokot
2018-11-14 16:25:23 +01:00
parent c0757d9cf6
commit b30636c313
8 changed files with 53 additions and 7 deletions

View File

@@ -2,7 +2,7 @@
# the settings in the config directory files.
# Application environment
PECL_ENV=dev
PECL_ENV="dev"
# http or https
PECL_SCHEME="http"
@@ -10,5 +10,17 @@ PECL_SCHEME="http"
# PECL channel host (domain name)
PECL_HOST="pecl.localhost"
# Database username
PECL_DB_USERNAME="nobody"
# Database password
PECL_DB_PASSWORD="password"
# Database host
PECL_DB_HOST="localhost"
# Database name
PECL_DB_NAME="pecl"
# Path where new PECL account requests are sent when requesting a SVN account
PECL_MASTER_API_URL="http://pecl.localhost"

View File

@@ -27,12 +27,17 @@ require_once __DIR__.'/../include/bootstrap.php';
$svnusers = '/home/pierre/project/pecl/migration/svnusers';
$svn_accounts = file($svnusers);
function nonl(&$var) {$var = str_replace(["\n","\r", "\r\n"], '', $var);}
function nonl(&$var) {
$var = str_replace(["\n","\r", "\r\n"], '', $var);
}
array_walk($svn_accounts, 'nonl');
$sql = 'select handle from users where handle NOT IN (select handle from maintains)';
$dh = new \PDO(PECL_DB_DSN, PECL_DB_USER, PECL_DB_PASSWORD);
$dsn = 'mysql:host='.$config->get('db_host').';dbname='.$config->get('db_name');
$dh = new \PDO($dsn, $config->get('db_username'), $config->get('db_password'));
$res = $dh->query($sql);
$sql_del = 'DELETE FROM users WHERE handle=';

View File

@@ -31,5 +31,6 @@ DROP TABLE IF EXISTS
elections, election_votes_single, election_votes_multiple, election_votes_abstain, election_results, election_handle_votes, election_choices, election_account_request, zendinfo, trackbacks, apidoc_queue, tagnames, tag_package_link, `comments`, manual_notes
';
$dh = new \PDO(PECL_DB_DSN, PECL_DB_USER, PECL_DB_PASSWORD);
$dsn = 'mysql:host='.$config->get('db_host').';dbname='.$config->get('db_name');
$dh = new \PDO($dsn, $config->get('db_username'), $config->get('db_password'));
$res = $dh->query($sql);

View File

@@ -25,7 +25,8 @@
require_once __DIR__.'/../include/bootstrap.php';
$dh = new \PDO(PECL_DB_DSN, PECL_DB_USER, PECL_DB_PASSWORD);
$dsn = 'mysql:host='.$config->get('db_host').';dbname='.$config->get('db_name');
$dh = new \PDO($dsn, $config->get('db_username'), $config->get('db_password'));
$sql = "update karma set level='developer' where level='pear.dev' or level='pecl.dev';";
$res = $dh->query($sql);

View File

@@ -44,7 +44,8 @@ IF (cvs_link REGEXP('cvs.php.net\/cvs.php(.*)'),
where package_type='pecl' and cvs_link like '%cvs.php.net%';
";
$dh = new \PDO(PECL_DB_DSN, PECL_DB_USER, PECL_DB_PASSWORD);
$dsn = 'mysql:host='.$config->get('db_host').';dbname='.$config->get('db_name');
$dh = new \PDO($dsn, $config->get('db_username'), $config->get('db_password'));
$res = $dh->query($sql_movetosvn);
if (!$res) {

View File

@@ -34,6 +34,21 @@ return [
// PECL channel URL host (domain name)
'host' => isset($_SERVER['PECL_HOST']) ? $_SERVER['PECL_HOST'] : 'pecl.php.net',
// Database username
'db_username' => isset($_SERVER['PECL_DB_USERNAME']) ? $_SERVER['PECL_DB_USERNAME'] : 'nobody',
// Database password
'db_password' => isset($_SERVER['PECL_DB_PASSWORD']) ? $_SERVER['PECL_DB_PASSWORD'] : 'password',
// Database name
'db_name' => isset($_SERVER['PECL_DB_NAME']) ? $_SERVER['PECL_DB_NAME'] : 'pecl',
// Database host
'db_host' => isset($_SERVER['PECL_DB_HOST']) ? $_SERVER['PECL_DB_HOST'] : 'localhost',
// Database driver
'db_driver' => (function_exists('mysql_connect') ? 'mysql' : (function_exists('mysqli_connect') ? 'mysqli' : '')),
// REST static files directory
'rest_dir' => isset($_SERVER['PECL_REST_DIR']) ? $_SERVER['PECL_REST_DIR'] : __DIR__.'/../public_html/rest',

View File

@@ -25,6 +25,18 @@
*/
return [
// Database username
'db_username' => isset($_SERVER['PECL_DB_USERNAME']) ? $_SERVER['PECL_DB_USERNAME'] : 'pear',
// Database password
'db_password' => isset($_SERVER['PECL_DB_PASSWORD']) ? $_SERVER['PECL_DB_PASSWORD'] : 'pear',
// Database name
'db_name' => isset($_SERVER['PECL_DB_NAME']) ? $_SERVER['PECL_DB_NAME'] : 'pear',
// Database host
'db_host' => isset($_SERVER['PECL_DB_HOST']) ? $_SERVER['PECL_DB_HOST'] : 'localhost',
// REST static files directory
'rest_dir' => isset($_SERVER['PECL_REST_DIR']) ? $_SERVER['PECL_REST_DIR'] : '/var/lib/peclweb/rest',

View File

@@ -38,5 +38,4 @@ if (isset($_SERVER['PEAR_DATABASE_DSN'])) {
$driver = 'mysqli';
}
define('PEAR_DATABASE_DSN', $driver . '://' . PECL_DB_USER . ':' . PECL_DB_PASSWORD. '@' . PECL_DB_HOST. '/' . PECL_DB_NAME);
define('PECL_DB_DSN', 'mysql:host=' . PECL_DB_HOST . ';dbname=' . PECL_DB_NAME);
}