From 1c7a84def09a3d40cdc6039fe2ed432eddae07e1 Mon Sep 17 00:00:00 2001 From: osaajani <> Date: Tue, 31 Jan 2023 23:11:25 +0100 Subject: [PATCH] Only start daemons for phones of active users --- VERSION | 2 +- composer.json | 2 +- controllers/internals/Phone.php | 12 ++++++++++++ daemons/Launcher.php | 2 +- models/Phone.php | 25 +++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index 34bbc96..8bcc8b3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.5.4 +v3.5.5 diff --git a/composer.json b/composer.json index 7522544..935f689 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "twilio/sdk": "^6.1", "symfony/yaml": "^5.0", "phpmailer/phpmailer": "^6.1", - "ralouphie/mimey": "^2.1", + "xantios/mimey": ">=2.1", "kreait/firebase-php": "^5.14" }, "require-dev": { diff --git a/controllers/internals/Phone.php b/controllers/internals/Phone.php index 8cef65e..0cf8354 100644 --- a/controllers/internals/Phone.php +++ b/controllers/internals/Phone.php @@ -19,6 +19,18 @@ namespace controllers\internals; protected $model; + /** + * Return all phones for active users. + * + * @param int $id_user : user id + * + * @return array + */ + public function get_all_for_active_users() + { + return $this->get_model()->get_all_for_active_users(); + } + /** * Return all phones of a user. * diff --git a/daemons/Launcher.php b/daemons/Launcher.php index 63b29c2..cf3bb69 100644 --- a/daemons/Launcher.php +++ b/daemons/Launcher.php @@ -53,7 +53,7 @@ class Launcher extends AbstractDaemon $this->start_mailer_daemon(); - $phones = $this->internal_phone->get_all(); + $phones = $this->internal_phone->get_all_for_active_users(); $this->start_phones_daemons($phones); sleep(1); diff --git a/models/Phone.php b/models/Phone.php index a75a03c..14447f4 100644 --- a/models/Phone.php +++ b/models/Phone.php @@ -13,6 +13,31 @@ namespace models; class Phone extends StandardModel { + + /** + * Return all hones that belongs to active users + * + * @return array + */ + public function get_all_for_active_users() + { + $query = ' + SELECT phone.* + FROM phone + LEFT JOIN user + ON phone.id_user = user.id + WHERE user.status = :status + '; + + $params = [ + 'status' => \models\User::STATUS_ACTIVE, + ]; + + $result = $this->_run_query($query, $params); + + return $result; + } + /** * Return a phone by his name and user. *