mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-13 16:55:01 +00:00
Merge remote-tracking branch 'origin/master' into oasis
# Conflicts: # public/js/main.js # public/mix-manifest.json
This commit is contained in:
@@ -3,17 +3,34 @@
|
||||
namespace App\Http\Controllers\App;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Language;
|
||||
use App\Models\LanguageTranslation;
|
||||
use App\Services\LanguageService;
|
||||
use Artisan;
|
||||
use DB;
|
||||
use Gate;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Schema;
|
||||
|
||||
class Maintenance extends Controller
|
||||
{
|
||||
/**
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Check admin permission
|
||||
Gate::authorize('maintenance');
|
||||
}
|
||||
|
||||
/**
|
||||
* Start maintenance mode
|
||||
*/
|
||||
public function up() {
|
||||
public function up()
|
||||
{
|
||||
$command = Artisan::call('up');
|
||||
|
||||
if ($command === 0) {
|
||||
@@ -24,7 +41,8 @@ class Maintenance extends Controller
|
||||
/**
|
||||
* End maintenance mode
|
||||
*/
|
||||
public function down() {
|
||||
public function down()
|
||||
{
|
||||
$command = Artisan::call('down');
|
||||
|
||||
if ($command === 0) {
|
||||
@@ -33,17 +51,23 @@ class Maintenance extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade database
|
||||
* Get new language translations from default translations
|
||||
* and insert it into database
|
||||
*
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function upgrade()
|
||||
public function upgrade_translations()
|
||||
{
|
||||
$this->upgrade_database();
|
||||
resolve(LanguageService::class)
|
||||
->upgrade_language_translations();
|
||||
|
||||
return response('Done.', 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|mixed
|
||||
*/
|
||||
private function upgrade_database()
|
||||
public function upgrade_database()
|
||||
{
|
||||
$command = Artisan::call('migrate', [
|
||||
'--force' => true
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\HelperService;
|
||||
use App\Services\LanguageService;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -41,7 +41,7 @@ class Language extends Model
|
||||
static::creating(function ($language) {
|
||||
$language->id = Str::uuid();
|
||||
|
||||
resolve(HelperService::class)
|
||||
resolve(LanguageService::class)
|
||||
->create_default_language_translations(
|
||||
get_setting('license') ?? 'extended', $language->locale
|
||||
);
|
||||
|
||||
@@ -4,6 +4,9 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static whereLang(string $string)
|
||||
*/
|
||||
class LanguageTranslation extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
@@ -26,8 +26,8 @@ class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
$this->registerPolicies();
|
||||
|
||||
// Define admin settings gate
|
||||
Gate::define('admin-settings', function ($user) {
|
||||
// Define admin maintenance gate
|
||||
Gate::define('maintenance', function ($user) {
|
||||
return $user->role === 'admin';
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ use App\Models\Share;
|
||||
use Aws\Exception\MultipartUploadException;
|
||||
use Aws\S3\MultipartUploader;
|
||||
use DB;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -323,35 +322,4 @@ class HelperService
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $license
|
||||
* @param $locale
|
||||
*/
|
||||
function create_default_language_translations($license, $locale)
|
||||
{
|
||||
$translations = [
|
||||
'extended' => collect([
|
||||
config("language-translations.extended"),
|
||||
config("language-translations.regular"),
|
||||
config("custom-language-translations")
|
||||
])->collapse(),
|
||||
'regular' => collect([
|
||||
config("language-translations.regular"),
|
||||
config("custom-language-translations")
|
||||
])->collapse(),
|
||||
];
|
||||
|
||||
$translations = $translations[strtolower($license)]
|
||||
->map(function ($value, $key) use ($locale) {
|
||||
return [
|
||||
'lang' => $locale,
|
||||
'value' => $value,
|
||||
'key' => $key,
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
DB::table('language_translations')
|
||||
->insert($translations);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use App\Models\Language;
|
||||
use App\Models\LanguageTranslation;
|
||||
use DB;
|
||||
|
||||
class LanguageService
|
||||
{
|
||||
/**
|
||||
* @param $license
|
||||
* @param $locale
|
||||
*/
|
||||
function create_default_language_translations($license, $locale)
|
||||
{
|
||||
$translations = [
|
||||
'extended' => collect([
|
||||
config("language-translations.extended"),
|
||||
config("language-translations.regular"),
|
||||
config("custom-language-translations")
|
||||
])->collapse(),
|
||||
'regular' => collect([
|
||||
config("language-translations.regular"),
|
||||
config("custom-language-translations")
|
||||
])->collapse(),
|
||||
];
|
||||
|
||||
$translations = $translations[strtolower($license)]
|
||||
->map(function ($value, $key) use ($locale) {
|
||||
return [
|
||||
'lang' => $locale,
|
||||
'value' => $value,
|
||||
'key' => $key,
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
DB::table('language_translations')
|
||||
->insert($translations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find newly added translations in default language
|
||||
* translations file and insert it into database
|
||||
*/
|
||||
function upgrade_language_translations()
|
||||
{
|
||||
// Get all app locales
|
||||
$locales = Language::all()
|
||||
->pluck('locale');
|
||||
|
||||
// Get default translations
|
||||
$translations = LanguageTranslation::whereLang('en')
|
||||
->get();
|
||||
|
||||
$default_translations = [
|
||||
'extended' => collect([
|
||||
config("language-translations.extended"),
|
||||
config("language-translations.regular"),
|
||||
config("custom-language-translations")
|
||||
])->collapse(),
|
||||
'regular' => collect([
|
||||
config("language-translations.regular"),
|
||||
config("custom-language-translations")
|
||||
])->collapse(),
|
||||
];
|
||||
|
||||
$license = strtolower(get_setting('license'));
|
||||
|
||||
// Find new translations in default translations
|
||||
$newbies = $default_translations[$license]
|
||||
->diff(map_language_translations($translations));
|
||||
|
||||
// Store new translations for every language
|
||||
$locales->each(function ($locale) use ($newbies) {
|
||||
|
||||
$translations = $newbies
|
||||
->map(function ($value, $key) use ($locale) {
|
||||
return [
|
||||
'lang' => $locale,
|
||||
'value' => $value,
|
||||
'key' => $key,
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
// Store translations into database
|
||||
DB::table('language_translations')
|
||||
->insert($translations);
|
||||
});
|
||||
}
|
||||
}
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+12
@@ -774,6 +774,17 @@ const routesIndex = [
|
||||
},
|
||||
},
|
||||
]
|
||||
const routesOthers = [
|
||||
{
|
||||
name: 'NotFound',
|
||||
path: '*',
|
||||
component: () =>
|
||||
import(/* webpackChunkName: "chunks/not-found-shared" */ './views/Shared/NotFoundShared'),
|
||||
meta: {
|
||||
requiresAuth: false
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
const router = new Router({
|
||||
mode: 'history',
|
||||
@@ -785,6 +796,7 @@ const router = new Router({
|
||||
...routesIndex,
|
||||
...routesAuth,
|
||||
...routesUser,
|
||||
...routesOthers,
|
||||
],
|
||||
scrollBehavior(to, from, savedPosition) {
|
||||
if (savedPosition) {
|
||||
|
||||
+11
-3
@@ -2,6 +2,14 @@
|
||||
|
||||
use App\Http\Controllers\App\Maintenance;
|
||||
|
||||
Route::post('/upgrade', [Maintenance::class, 'upgrade']);
|
||||
Route::get('/down', [Maintenance::class, 'down']);
|
||||
Route::get('/up', [Maintenance::class, 'up']);
|
||||
Route::group(['middleware' => ['auth:sanctum']], function () {
|
||||
|
||||
Route::get('/down', [Maintenance::class, 'down']);
|
||||
Route::get('/up', [Maintenance::class, 'up']);
|
||||
|
||||
Route::group(['prefix' => 'upgrade'], function () {
|
||||
Route::get('/translations', [Maintenance::class, 'upgrade_translations']);
|
||||
Route::get('/database', [Maintenance::class, 'upgrade_database']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\App;
|
||||
|
||||
use App\Models\User;
|
||||
use DB;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AppUpgradeTest extends TestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_upgrade_default_language_translations()
|
||||
{
|
||||
$user = User::factory(User::class)
|
||||
->create(['role' => 'admin']);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
DB::table('settings')
|
||||
->insert([
|
||||
[
|
||||
'name' => 'language',
|
||||
'value' => 'en',
|
||||
],
|
||||
[
|
||||
'name' => 'license',
|
||||
'value' => 'Extended',
|
||||
]
|
||||
]);
|
||||
|
||||
collect(['en', 'sk'])
|
||||
->map(function ($locale) {
|
||||
|
||||
DB::table('languages')
|
||||
->insert([
|
||||
'id' => Str::uuid(),
|
||||
'name' => 'English',
|
||||
'locale' => $locale
|
||||
]);
|
||||
|
||||
DB::table('language_translations')
|
||||
->insert([
|
||||
[
|
||||
'key' => 'activation.stripe.button',
|
||||
'value' => 'Set up your Stripe account',
|
||||
'lang' => $locale
|
||||
], [
|
||||
'key' => 'activation.stripe.description',
|
||||
'value' => 'To charge your users, please set up your Stripe account credentials.',
|
||||
'lang' => $locale
|
||||
]
|
||||
]);
|
||||
});
|
||||
|
||||
$this->get('/upgrade/translations')
|
||||
->assertStatus(201);
|
||||
|
||||
collect(['en', 'sk'])
|
||||
->map(function ($locale) {
|
||||
|
||||
$this->assertDatabaseHas('language_translations', [
|
||||
'key' => 'activation.stripe.title',
|
||||
'value' => 'Your Stripe account is not set',
|
||||
'lang' => $locale,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user