Skip to content

Commit bea50fd

Browse files
committed
add ltm_user_locales ui_settings for react, fix user_id index to unique.
1 parent ef0daa9 commit bea50fd

File tree

4 files changed

+72
-8
lines changed

4 files changed

+72
-8
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
6+
class AddUiSettingsToLtmUserLocales extends Migration
7+
{
8+
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
$prefix = \Config::get('laravel-translation-manager::config.table_prefix', '');
17+
Schema::table($prefix . 'ltm_user_locales', function (Blueprint $table) use ($prefix) {
18+
$table->dropIndex('ix_ltm_user_locales_user_id');
19+
20+
$table->unique('user_id', 'ixk_user_id_users_id');
21+
$table->text('ui_settings')->nullable();
22+
});
23+
}
24+
25+
/**
26+
* Reverse the migrations.
27+
*
28+
* @return void
29+
*/
30+
public function down()
31+
{
32+
$prefix = \Config::get('laravel-translation-manager::config.table_prefix', '');
33+
Schema::table($prefix . 'ltm_user_locales', function (Blueprint $table) use ($prefix) {
34+
$table->dropColumn('ui_settings');
35+
36+
$table->dropUnique('ixk_user_id_users_id');
37+
$table->index(['user_id'], 'ix_ltm_user_locales_user_id');
38+
});
39+
}
40+
41+
}

src/Controller.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Illuminate\Support\Facades\Request;
1111
use Illuminate\Support\Facades\Response;
1212
use Illuminate\Support\Facades\Route;
13-
use Illuminate\Support\Facades\Session;
1413
use Illuminate\Support\Facades\View;
1514
use Symfony\Component\HttpFoundation\ParameterBag;
1615
use Vsch\TranslationManager\Events\TranslationsPublished;
@@ -111,7 +110,18 @@ private function loadCookieData()
111110
$this->displayLocales = $displayLocales;
112111

113112
// $this->webUIState = json_decode(Cookie::get($this->cookieName(self::COOKIE_WEB_UI_STATE), "{}"), true);
114-
$this->webUIState = Session::get($this->manager->config(Manager::PERSISTENT_PREFIX_KEY) . Manager::WEB_UI_SETTINGS_PERSISTENT_SUFFIX, null);
113+
// $this->webUIState = Session::get($this->manager->config(Manager::PERSISTENT_PREFIX_KEY) . Manager::WEB_UI_SETTINGS_PERSISTENT_SUFFIX, null);
114+
$this->webUIState = null;
115+
$userId = Auth::id();
116+
if ($userId !== null) {
117+
$userLocalesModel = new UserLocales();
118+
$userLocalesModel->setConnection($connectionName);
119+
$userLocalesResult = $userLocalesModel->query()->where('user_id', $userId)->first();
120+
if ($userLocalesResult && $userLocalesResult->ui_settings) {
121+
$this->webUIState = json_decode($userLocalesResult->ui_settings, true);
122+
}
123+
}
124+
115125
if (!$this->webUIState) {
116126
// put defaults in it
117127
$this->webUIState = [];
@@ -170,7 +180,7 @@ private function normalizeLocaleDataRaw()
170180
$userLocalesModel = new UserLocales();
171181
$userLocalesModel->setConnection($connectionName);
172182
$userLocalesResult = $userLocalesModel->query()->where('user_id', $userId)->first();
173-
if ($userLocalesResult && trim($userLocalesResult->locales)) {
183+
if ($userLocalesResult && $userLocalesResult->locales && trim($userLocalesResult->locales)) {
174184
$userLocales = explode(',', $userLocalesResult->locales);
175185
}
176186
}
@@ -694,10 +704,18 @@ private function processUISettings($json)
694704
}
695705
}
696706

697-
if ($hadWebUIState) {
698-
Session::put($this->manager->config(Manager::PERSISTENT_PREFIX_KEY) . Manager::WEB_UI_SETTINGS_PERSISTENT_SUFFIX, $this->webUIState);
699-
} else {
700-
Session::remove($this->manager->config(Manager::PERSISTENT_PREFIX_KEY) . Manager::WEB_UI_SETTINGS_PERSISTENT_SUFFIX);
707+
$userId = Auth::id();
708+
if ($userId !== null) {
709+
if ($hadWebUIState) {
710+
$userLocalesModel = new UserLocales();
711+
$userLocalesModel->setConnection($this->getConnectionName());
712+
$userLocalesResult = $userLocalesModel->query()->where('user_id', $userId)->firstOrNew([]);
713+
$json_encode = json_encode($this->webUIState, JSON_PRETTY_PRINT);
714+
$userLocalesResult->ui_settings = $json_encode;
715+
$userLocalesResult->user_id = $userLocalesResult->user_id ?: $userId;
716+
$userLocalesResult->locales = $userLocalesResult->locales ?: '';
717+
$userLocalesResult->save();
718+
}
701719
}
702720

703721
// do all the init processing so the returned results are adjusted for display locales and the rest

src/Manager.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class Manager
4040
const EXCLUDE_GROUPS_KEY = 'exclude_groups';
4141
const MISSING_KEYS_LOTTERY_KEY = 'missing_keys_lottery';
4242
const LOTTERY_PERSISTENT_SUFFIX = 'lottery';
43-
const WEB_UI_SETTINGS_PERSISTENT_SUFFIX = 'web_ui_settings';
4443
const LOG_KEY_USAGE_INFO_KEY = 'log_key_usage_info';
4544
const ADDITIONAL_LOCALES_KEY = 'locales';
4645
const SHOW_LOCALES_KEY = 'show_locales';

versioninfo.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
The 1.x.x versions are for Laravel 4.2, 2.1.x versions are for Laravel 5.1+, 2.3.x for Laravel
44
5.3, 2.4.x for Laravel 5.4, 2.5.x for Laravel 5.5 and 2.6.x for Laravel 5.6 compatibility.
55

6+
#### Next: 2.6.8
7+
8+
* Add: ui_settings to ltm_user_locales to store the user's react ui app settings for
9+
persistence. Sessions are too short and too much data for one cookie and splitting is a pain.
10+
* Fix: change ltm_user_locales index on user_id to unique
11+
612
#### Next: 2.6.6
713

814
* Fix: Pass x-edit popup title translations to JS

0 commit comments

Comments
 (0)