diff --git a/VERSION b/VERSION index 5103369..293fbd1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.2.3 +v3.2.4 diff --git a/controllers/internals/ExpressionProvider.php b/controllers/internals/ExpressionProvider.php index 7ee1f9c..9d056ab 100644 --- a/controllers/internals/ExpressionProvider.php +++ b/controllers/internals/ExpressionProvider.php @@ -11,6 +11,7 @@ namespace controllers\internals; +use DateTime; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; @@ -37,15 +38,34 @@ class ExpressionProvider implements ExpressionFunctionProviderInterface return isset($var); }); + //Check if today is birthday given a birthdate as DateTime + $is_birthday = new ExpressionFunction('is_birthday', function ($birthdate) + { + return sprintf('isset(%1$s) && is_a(%1$s, \'DateTime\') && %1$s->format(\'m-d\') == (new \\DateTime())->format(\'m-d\')', $birthdate); + }, function ($arguments, DateTime $birthdate) + { + if (!($birthdate ?? false)) + { + return false; + } + + return $birthdate->format('m-d') == (new DateTime())->format('m-d'); + }); + return [ $neutralized_constant, $exists, + $is_birthday, ExpressionFunction::fromPhp('mb_strtolower', 'lower'), ExpressionFunction::fromPhp('mb_strtoupper', 'upper'), ExpressionFunction::fromPhp('mb_substr', 'substr'), ExpressionFunction::fromPhp('mb_strlen', 'strlen'), ExpressionFunction::fromPhp('abs', 'abs'), - ExpressionFunction::fromPhp('strtotime', 'date'), + ExpressionFunction::fromPhp('date_create', 'date'), + ExpressionFunction::fromPhp('date_create_from_format', 'date_from_format'), + ExpressionFunction::fromPhp('intval', 'intval'), + ExpressionFunction::fromPhp('boolval', 'boolval'), + ExpressionFunction::fromPhp('count', 'count'), ]; } } diff --git a/controllers/internals/Ruler.php b/controllers/internals/Ruler.php index 1682ef4..0dc3103 100644 --- a/controllers/internals/Ruler.php +++ b/controllers/internals/Ruler.php @@ -43,18 +43,15 @@ use Symfony\Component\ExpressionLanguage\ExpressionLanguage; { try { - $this->expression_language->parse($condition, array_keys($data)); + //Use @ to hide notices on non defined vars + @$this->expression_language->parse($condition, array_keys($data)); return true; } - catch (\Exception $e) + catch (\Throwable $t) //Catch both, exceptions and php error { return false; } - catch (\Throwable $t) - { - //Just ignore non critical php warning and notice - } } /** @@ -69,11 +66,12 @@ use Symfony\Component\ExpressionLanguage\ExpressionLanguage; { try { + //Use @ to hide notices on non defined vars @$result = $this->expression_language->evaluate($condition, $data); return (bool) $result; } - catch (\Exception $e) + catch (\Throwable $t) //Catch both, exceptions and php error { return null; } diff --git a/daemons/Phone.php b/daemons/Phone.php index 1be7856..a6c7ba9 100644 --- a/daemons/Phone.php +++ b/daemons/Phone.php @@ -20,6 +20,8 @@ use Monolog\Logger; class Phone extends AbstractDaemon { private $max_inactivity = 5 * 60; + private $read_delay = 20 / 0.5; + private $read_tick = 0; private $msg_queue; private $msg_queue_id; private $webhook_queue; @@ -56,13 +58,20 @@ class Phone extends AbstractDaemon { usleep(0.5 * 1000000); //Micro sleep for perfs + $this->read_tick += 1; + $this->bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8'); //Send smss in queue $this->send_smss(); - //Read received smss - $this->read_smss(); + //Read only every x ticks (x/2 seconds) to prevent too many call + if ($this->read_tick >= $this->read_delay) + { + //Read received smss + $this->read_smss(); + $this->read_tick = 0; + } //Stop after 5 minutes of inactivity to avoid useless daemon if ((microtime(true) - $this->last_message_at) > $this->max_inactivity)