From 3985a4bc43cb923ed0348a0881d5aa11a13d70ef Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 25 Jun 2018 20:56:07 -0400 Subject: [PATCH] Remove extraneous dba::connect calls --- bin/auth_ejabberd.php | 5 ----- bin/daemon.php | 9 ++++----- bin/worker.php | 5 ----- index.php | 5 +---- src/Core/Console/ArchiveContact.php | 8 ++------ src/Core/Console/Config.php | 8 ++------ src/Core/Console/DatabaseStructure.php | 6 +----- src/Core/Console/GlobalCommunityBlock.php | 8 ++------ src/Core/Console/GlobalCommunitySilence.php | 8 ++------ src/Core/Console/Maintenance.php | 8 ++------ src/Core/Console/NewPassword.php | 8 ++------ 11 files changed, 18 insertions(+), 60 deletions(-) diff --git a/bin/auth_ejabberd.php b/bin/auth_ejabberd.php index 10b9d874f1..6c078e2249 100755 --- a/bin/auth_ejabberd.php +++ b/bin/auth_ejabberd.php @@ -33,7 +33,6 @@ */ use Friendica\App; -use Friendica\Core\Config; use Friendica\Util\ExAuth; if (sizeof($_SERVER["argv"]) == 0) { @@ -55,10 +54,6 @@ require_once "include/dba.php"; $a = new App(dirname(__DIR__)); -@include ".htconfig.php"; -dba::connect($db_host, $db_user, $db_pass, $db_data); -unset($db_host, $db_user, $db_pass, $db_data); - $oAuth = new ExAuth(); $oAuth->readStdin(); \ No newline at end of file diff --git a/bin/daemon.php b/bin/daemon.php index acb4a2c682..2450e4223e 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -28,8 +28,9 @@ require_once "include/dba.php"; $a = new App(dirname(__DIR__)); -require_once ".htconfig.php"; -dba::connect($db_host, $db_user, $db_pass, $db_data); +if ($a->mode === App::MODE_INSTALL) { + die("Friendica isn't properly installed yet.\n"); +} Config::load(); @@ -125,11 +126,9 @@ if (!$foreground) { file_put_contents($pidfile, $pid); // We lose the database connection upon forking - dba::connect($db_host, $db_user, $db_pass, $db_data); + $a->loadDatabase(); } -unset($db_host, $db_user, $db_pass, $db_data); - Config::set('system', 'worker_daemon_mode', true); // Just to be sure that this script really runs endlessly diff --git a/bin/worker.php b/bin/worker.php index 77c85b1d58..2abfa0ad92 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -24,14 +24,9 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) { } require_once "boot.php"; -require_once "include/dba.php"; $a = new App(dirname(__DIR__)); -require_once ".htconfig.php"; -dba::connect($db_host, $db_user, $db_pass, $db_data); -unset($db_host, $db_user, $db_pass, $db_data); - Config::load(); // Check the database structure and possibly fixes it diff --git a/index.php b/index.php index d83e202d2a..501235f497 100644 --- a/index.php +++ b/index.php @@ -41,10 +41,7 @@ if (!$a->mode == App::MODE_INSTALL) { require_once "include/dba.php"; if (!$a->mode == App::MODE_INSTALL) { - $result = dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { + if (!dba::connected()) { System::unavailable(); } diff --git a/src/Core/Console/ArchiveContact.php b/src/Core/Console/ArchiveContact.php index 7a973f3116..63ace91c0f 100644 --- a/src/Core/Console/ArchiveContact.php +++ b/src/Core/Console/ArchiveContact.php @@ -54,12 +54,8 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; - $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { - throw new \RuntimeException('Unable to connect to database'); + if ($a->mode === App::MODE_INSTALL) { + throw new \RuntimeException('Friendica isn\'t properly installed yet.'); } $nurl = normalise_link($this->getArgument(0)); diff --git a/src/Core/Console/Config.php b/src/Core/Console/Config.php index 306e1c275e..4f7d090d5c 100644 --- a/src/Core/Console/Config.php +++ b/src/Core/Console/Config.php @@ -92,12 +92,8 @@ HELP; throw new CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; - $result = dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { - throw new \RuntimeException('Unable to connect to database'); + if ($a->mode === \Friendica\App::MODE_INSTALL) { + $this->out('Database isn\'t ready or populated yet, showing file config only'); } if (count($this->args) == 3) { diff --git a/src/Core/Console/DatabaseStructure.php b/src/Core/Console/DatabaseStructure.php index eb4c6df998..1190484310 100644 --- a/src/Core/Console/DatabaseStructure.php +++ b/src/Core/Console/DatabaseStructure.php @@ -56,11 +56,7 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; - $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { + if (!\dba::connected()) { throw new \RuntimeException('Unable to connect to database'); } diff --git a/src/Core/Console/GlobalCommunityBlock.php b/src/Core/Console/GlobalCommunityBlock.php index 26c5d13131..5fcc6be160 100644 --- a/src/Core/Console/GlobalCommunityBlock.php +++ b/src/Core/Console/GlobalCommunityBlock.php @@ -56,12 +56,8 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; - $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { - throw new \RuntimeException('Unable to connect to database'); + if ($a->mode == \Friendica\App::MODE_INSTALL) { + throw new \RuntimeException('Database isn\'t ready or populated yet'); } $contact_id = Contact::getIdForURL($this->getArgument(0)); diff --git a/src/Core/Console/GlobalCommunitySilence.php b/src/Core/Console/GlobalCommunitySilence.php index 72d5a4f881..a70888e454 100644 --- a/src/Core/Console/GlobalCommunitySilence.php +++ b/src/Core/Console/GlobalCommunitySilence.php @@ -64,12 +64,8 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; - $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { - throw new \RuntimeException('Unable to connect to database'); + if ($a->mode == \Friendica\App::MODE_INSTALL) { + throw new \RuntimeException('Database isn\'t ready or populated yet'); } /** diff --git a/src/Core/Console/Maintenance.php b/src/Core/Console/Maintenance.php index 6638e4bfe1..68d33337ab 100644 --- a/src/Core/Console/Maintenance.php +++ b/src/Core/Console/Maintenance.php @@ -64,12 +64,8 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; - $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { - throw new \RuntimeException('Unable to connect to database'); + if ($a->mode == \Friendica\App::MODE_INSTALL) { + throw new \RuntimeException('Database isn\'t ready or populated yet'); } Core\Config::load(); diff --git a/src/Core/Console/NewPassword.php b/src/Core/Console/NewPassword.php index f5698ba716..e5f9349190 100644 --- a/src/Core/Console/NewPassword.php +++ b/src/Core/Console/NewPassword.php @@ -58,12 +58,8 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; - $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { - throw new \RuntimeException('Unable to connect to database'); + if ($a->mode == \Friendica\App::MODE_INSTALL) { + throw new \RuntimeException('Database isn\'t ready or populated yet'); } $nick = $this->getArgument(0);