From bf759f9dd71d1ec201e1aac853fd4e68dc8436b8 Mon Sep 17 00:00:00 2001 From: ghost Date: Thu, 14 Sep 2023 20:38:42 +0300 Subject: [PATCH] move connections to the bootstrap --- src/config/bootstrap.php | 26 +++++++++++++++++++++++++- src/crontab/export/feed.php | 3 --- src/crontab/import/feed.php | 3 --- src/crontab/scrape.php | 12 ------------ src/crontab/sitemap.php | 12 ------------ src/public/action.php | 12 ------------ src/public/download.php | 12 ------------ src/public/edit.php | 12 ------------ src/public/faq.php | 12 ------------ src/public/index.php | 24 ------------------------ src/public/magnet.php | 24 ------------------------ src/public/node.php | 12 ------------ src/public/welcome.php | 12 ------------ 13 files changed, 25 insertions(+), 151 deletions(-) diff --git a/src/config/bootstrap.php b/src/config/bootstrap.php index bf091c7..ee63d61 100644 --- a/src/config/bootstrap.php +++ b/src/config/bootstrap.php @@ -41,4 +41,28 @@ require_once __DIR__ . '/../library/scrapeer.php'; require_once __DIR__ . '/../library/time.php'; // Vendors autoload -require_once __DIR__ . '/../../vendor/autoload.php'; \ No newline at end of file +require_once __DIR__ . '/../../vendor/autoload.php'; + +// Connect database +try { + + $db = new Database(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); + +} catch (Exception $e) { + + var_dump($e); + + exit; +} + +// Connect Sphinx +try { + + $sphinx = new Sphinx(SPHINX_HOST, SPHINX_PORT); + +} catch(Exception $e) { + + var_dump($e); + + exit; +} \ No newline at end of file diff --git a/src/crontab/export/feed.php b/src/crontab/export/feed.php index 165b4a2..8482a93 100644 --- a/src/crontab/export/feed.php +++ b/src/crontab/export/feed.php @@ -29,9 +29,6 @@ $public = [ // Begin export try { - // Connect DB - $db = new Database(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); - // Init API folder if not exists @mkdir(__DIR__ . '/../public/api'); diff --git a/src/crontab/import/feed.php b/src/crontab/import/feed.php index 3682c93..fc9359b 100644 --- a/src/crontab/import/feed.php +++ b/src/crontab/import/feed.php @@ -28,9 +28,6 @@ $debug = // Begin export try { - // Connect DB - $db = new Database(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); - // Transaction begin $db->beginTransaction(); diff --git a/src/crontab/scrape.php b/src/crontab/scrape.php index 9a3f21d..45185a4 100644 --- a/src/crontab/scrape.php +++ b/src/crontab/scrape.php @@ -19,18 +19,6 @@ $debug = [ ], ]; -// Connect DB -try { - - $db = new Database(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); - -} catch(Exception $e) { - - var_dump($e); - - exit; -} - // Init Scraper try { diff --git a/src/crontab/sitemap.php b/src/crontab/sitemap.php index b49a51d..94f6953 100644 --- a/src/crontab/sitemap.php +++ b/src/crontab/sitemap.php @@ -19,18 +19,6 @@ $debug = [ ], ]; -// Connect DB -try { - - $db = new Database(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); - -} catch(Exception $e) { - - var_dump($e); - - exit; -} - // Begin try { diff --git a/src/public/action.php b/src/public/action.php index ebfbda5..599b047 100644 --- a/src/public/action.php +++ b/src/public/action.php @@ -3,18 +3,6 @@ // Bootstrap require_once __DIR__ . '/../config/bootstrap.php'; -// Connect database -try { - - $db = new Database(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); - -} catch (Exception $e) { - - var_dump($e); - - exit; -} - // Define response $response = (object) [ diff --git a/src/public/download.php b/src/public/download.php index 1718172..7eda422 100644 --- a/src/public/download.php +++ b/src/public/download.php @@ -3,18 +3,6 @@ // Bootstrap require_once __DIR__ . '/../config/bootstrap.php'; -// Connect database -try { - - $db = new Database(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); - -} catch (Exception $e) { - - var_dump($e); - - exit; -} - // Define response $response = (object) [ diff --git a/src/public/edit.php b/src/public/edit.php index 07cadc1..aac7208 100644 --- a/src/public/edit.php +++ b/src/public/edit.php @@ -3,18 +3,6 @@ // Bootstrap require_once __DIR__ . '/../config/bootstrap.php'; -// Connect database -try { - - $db = new Database(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); - -} catch (Exception $e) { - - var_dump($e); - - exit; -} - // Define variables $response = (object) [ diff --git a/src/public/faq.php b/src/public/faq.php index f9a0434..1011563 100644 --- a/src/public/faq.php +++ b/src/public/faq.php @@ -4,18 +4,6 @@ // Bootstrap require_once __DIR__ . '/../config/bootstrap.php'; -// Connect database -try { - - $db = new Database(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); - -} catch (Exception $e) { - - var_dump($e); - - exit; -} - // Define response $response = (object) [ diff --git a/src/public/index.php b/src/public/index.php index a29a40c..540ca49 100644 --- a/src/public/index.php +++ b/src/public/index.php @@ -3,30 +3,6 @@ // Bootstrap dependencies require_once __DIR__ . '/../config/bootstrap.php'; -// Connect Sphinx -try { - - $sphinx = new Sphinx(SPHINX_HOST, SPHINX_PORT); - -} catch(Exception $e) { - - var_dump($e); - - exit; -} - -// Connect database -try { - - $db = new Database(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); - -} catch (Exception $e) { - - var_dump($e); - - exit; -} - // Define variables $request = (object) [ diff --git a/src/public/magnet.php b/src/public/magnet.php index 5e9adb6..4e9f627 100644 --- a/src/public/magnet.php +++ b/src/public/magnet.php @@ -3,30 +3,6 @@ // Bootstrap require_once __DIR__ . '/../config/bootstrap.php'; -// Connect Sphinx -try { - - $sphinx = new Sphinx(SPHINX_HOST, SPHINX_PORT); - -} catch(Exception $e) { - - var_dump($e); - - exit; -} - -// Connect database -try { - - $db = new Database(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); - -} catch (Exception $e) { - - var_dump($e); - - exit; -} - // Define response $response = (object) [ diff --git a/src/public/node.php b/src/public/node.php index ff61f68..36af237 100644 --- a/src/public/node.php +++ b/src/public/node.php @@ -4,18 +4,6 @@ // Bootstrap require_once __DIR__ . '/../config/bootstrap.php'; -// Connect database -try { - - $db = new Database(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); - -} catch (Exception $e) { - - var_dump($e); - - exit; -} - // Define response $response = (object) [ diff --git a/src/public/welcome.php b/src/public/welcome.php index 33eb8a3..c7a44b6 100644 --- a/src/public/welcome.php +++ b/src/public/welcome.php @@ -4,18 +4,6 @@ // Bootstrap require_once __DIR__ . '/../config/bootstrap.php'; -// Connect database -try { - - $db = new Database(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); - -} catch (Exception $e) { - - var_dump($e); - - exit; -} - // Define response $response = (object) [