]> git.agnieray.net Git - galette.git/commitdiff
Ensure language is changed when login from cron; closes #1769
authorJohan Cwiklinski <johan@x-tnd.be>
Tue, 23 Jan 2024 06:38:49 +0000 (07:38 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Tue, 23 Jan 2024 06:38:49 +0000 (07:38 +0100)
galette/lib/Galette/Core/Authentication.php
galette/lib/Galette/Core/Login.php

index 389450f54f1ed2b07c9910866c71cb33e343f464..bcee491c5608bf0e68d6c3732fdebc78cdb3dcb6 100644 (file)
@@ -129,22 +129,9 @@ abstract class Authentication
      * @param string      $name        Service name
      * @param Preferences $preferences Preferences instance
      *
-     * @return void
+     * @return bool
      */
-    public function logCron($name, Preferences $preferences)
-    {
-        //known cronable files
-        $ok = array('reminder');
-
-        if (in_array($name, $ok)) {
-            $this->logged = true;
-            $this->cron = true;
-            $this->login = 'cron';
-            $this->lang = $preferences->pref_lang;
-        } else {
-            trigger_error('Not authorized!', E_USER_ERROR);
-        }
-    }
+    abstract public function logCron(string $name, Preferences $preferences): bool;
 
     /**
      * Log out user and unset variables
index c9f8750d4ffc4b3037722f9d7ba5c5a38461fdd5..3141ee4be5dcf1ae7bac6f02cbaf69df0fd209d9 100644 (file)
@@ -92,6 +92,32 @@ class Login extends Authentication
         $this->impersonated = false;
     }
 
+    /**
+     * Authenticate from cron
+     *
+     * @param string      $name        Service name
+     * @param Preferences $preferences Preferences instance
+     *
+     * @return bool
+     */
+    public function logCron(string $name, Preferences $preferences): bool
+    {
+        //known cronable files
+        $ok = array('reminder');
+
+        if (in_array($name, $ok)) {
+            $this->logged = true;
+            $this->cron = true;
+            $this->login = 'cron';
+            $this->name = 'cron';
+            $this->lang = $preferences->pref_lang;
+            $this->i18n->changeLanguage($this->lang);
+            return true;
+        } else {
+            trigger_error('Not authorized!', E_USER_ERROR);
+        }
+    }
+
     /**
      * Log out user and unset variables
      *