diff --git a/module/VuFind/sql/migrations/pgsql/6.1/001-modify-user-columns.sql b/module/VuFind/sql/migrations/pgsql/6.1/001-modify-user-columns.sql index 347c60e01b15f4921ab2ecc492fc71d824ea5933..65d8f19f7a08e39e1666f60bdaba20515ca32944 100644 --- a/module/VuFind/sql/migrations/pgsql/6.1/001-modify-user-columns.sql +++ b/module/VuFind/sql/migrations/pgsql/6.1/001-modify-user-columns.sql @@ -7,3 +7,6 @@ ALTER TABLE "user" ALTER TABLE "user" ADD COLUMN user_provided_email boolean NOT NULL DEFAULT '0'; + +ALTER TABLE "user" + ADD COLUMN last_language varchar(30) NOT NULL DEFAULT ''; diff --git a/module/VuFind/sql/mysql.sql b/module/VuFind/sql/mysql.sql index 3b1e0285172eb5602e85bcc2a30789cafa4b9988..e26390cb63462eaff9a0f7ab5023cb7241536202 100644 --- a/module/VuFind/sql/mysql.sql +++ b/module/VuFind/sql/mysql.sql @@ -218,6 +218,7 @@ CREATE TABLE `user` ( `verify_hash` varchar(42) NOT NULL DEFAULT '', `last_login` datetime NOT NULL DEFAULT '2000-01-01 00:00:00', `auth_method` varchar(50) DEFAULT NULL, + `last_language` varchar(30) NOT NULL DEFAULT '', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`), UNIQUE KEY `cat_id` (`cat_id`) diff --git a/module/VuFind/sql/pgsql.sql b/module/VuFind/sql/pgsql.sql index 20f0a0f53c03dca6215e24adfafdcc4774ea1208..eb02493f63ded50ec30a76c9271e0a20cffdb357 100644 --- a/module/VuFind/sql/pgsql.sql +++ b/module/VuFind/sql/pgsql.sql @@ -144,6 +144,7 @@ created timestamp NOT NULL DEFAULT '1970-01-01 00:00:00', verify_hash varchar(42) NOT NULL DEFAULT '', last_login timestamp NOT NULL DEFAULT '1970-01-01 00:00:00', auth_method varchar(50) DEFAULT NULL, +last_language varchar(30) NOT NULL DEFAULT '', PRIMARY KEY (id), UNIQUE (username), UNIQUE (cat_id) diff --git a/module/VuFind/src/VuFind/Bootstrapper.php b/module/VuFind/src/VuFind/Bootstrapper.php index 09f9bf203fdd63c31f75b350610a11029254aba9..85c124bfef3e953c55bb9ac791cf6c2a802d7bba 100644 --- a/module/VuFind/src/VuFind/Bootstrapper.php +++ b/module/VuFind/src/VuFind/Bootstrapper.php @@ -354,6 +354,14 @@ class Bootstrapper ); } } + + // Store last selected language in user account, if applicable: + if (($user = $sm->get(\VuFind\Auth\Manager::class)->isLoggedIn()) + && $user->last_language != $language + ) { + $user->updateLastLanguage($language); + } + // Send key values to view: $viewModel = $sm->get('ViewManager')->getViewModel(); $viewModel->setVariable('userLang', $language); diff --git a/module/VuFind/src/VuFind/Db/Row/User.php b/module/VuFind/src/VuFind/Db/Row/User.php index 2c007ab088d0256fcba038e2f3ee02ce2045ea0a..bc83e50df036e060658d5930d0792503e0c43401 100644 --- a/module/VuFind/src/VuFind/Db/Row/User.php +++ b/module/VuFind/src/VuFind/Db/Row/User.php @@ -681,6 +681,19 @@ class User extends RowGateway implements \VuFind\Db\Table\DbTableAwareInterface, } /** + * Updated saved language + * + * @param string $language New language + * + * @return void + */ + public function updateLastLanguage($language) + { + $this->last_language = $language; + $this->save(); + } + + /* * Update the user's email address, if appropriate. Note that this does NOT * automatically save the row; it assumes a subsequent call will be made to * the save() method.