mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-29 03:10:51 +00:00
updates automatically handled on the background
This commit is contained in:
@@ -5,13 +5,14 @@ use Illuminate\Console\Scheduling\Schedule;
|
||||
use App\Console\Commands\SetupDevEnvironment;
|
||||
use App\Console\Commands\SetupProdEnvironment;
|
||||
use Support\Scheduler\Actions\ReportUsageAction;
|
||||
use Support\Demo\Actions\DeleteAllSharedLinksAction;
|
||||
use Support\Demo\Actions\DeleteAllDemoSharedLinksAction;
|
||||
use Support\Scheduler\Actions\DeleteFailedFilesAction;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
use Support\Scheduler\Actions\DeleteUnverifiedUsersAction;
|
||||
use Support\Scheduler\Actions\DeleteExpiredShareLinksAction;
|
||||
use App\Console\Commands\GenerateDemoSubscriptionContentCommand;
|
||||
use Support\Scheduler\Actions\ExpireUnfilledUploadRequestAction;
|
||||
use Support\Upgrading\Actions\UpdateSystemAction;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
@@ -42,7 +43,7 @@ class Kernel extends ConsoleKernel
|
||||
|
||||
if (is_demo()) {
|
||||
$schedule->call(
|
||||
fn () => resolve(DeleteAllSharedLinksAction::class)()
|
||||
fn () => resolve(DeleteAllDemoSharedLinksAction::class)()
|
||||
)->daily()->at('00:00');
|
||||
}
|
||||
|
||||
@@ -54,6 +55,10 @@ class Kernel extends ConsoleKernel
|
||||
fn () => resolve(ExpireUnfilledUploadRequestAction::class)()
|
||||
)->hourly();
|
||||
|
||||
$schedule->call(
|
||||
fn () => resolve(UpdateSystemAction::class)()
|
||||
)->everyMinute();
|
||||
|
||||
$schedule->call(
|
||||
fn () => resolve(DeleteUnverifiedUsersAction::class)()
|
||||
)->daily()->at('00:05');
|
||||
|
||||
@@ -36,9 +36,9 @@ class UserResource extends JsonResource
|
||||
'avatar' => $this->settings->avatar,
|
||||
'email' => is_demo() ? obfuscate_email($this->email) : $this->email,
|
||||
'role' => $this->role,
|
||||
'two_factor_authentication' => (bool)$this->two_factor_secret,
|
||||
'two_factor_authentication' => (bool) $this->two_factor_secret,
|
||||
'two_factor_confirmed_at' => $this->two_factor_confirmed_at,
|
||||
'socialite_account' => !(bool)$this->password,
|
||||
'socialite_account' => ! (bool) $this->password,
|
||||
'storage' => $this->storage,
|
||||
'created_at' => format_date($this->created_at, 'd. M. Y'),
|
||||
'updated_at' => format_date($this->updated_at, 'd. M. Y'),
|
||||
|
||||
@@ -1,27 +1,17 @@
|
||||
<?php
|
||||
namespace Domain\Admin\Controllers\Dashboard;
|
||||
|
||||
use Schema;
|
||||
use ByteUnits\Metric;
|
||||
use App\Users\Models\User;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Domain\Maintenance\Models\AppUpdate;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use VueFileManager\Subscription\Domain\Subscriptions\Models\Subscription;
|
||||
|
||||
class GetDashboardDataController extends Controller
|
||||
{
|
||||
public function __invoke(): Application|ResponseFactory|Response
|
||||
public function __invoke(): JsonResponse
|
||||
{
|
||||
// Get app update data
|
||||
$shouldUpgrade = $this->getUpgradeData();
|
||||
|
||||
// Get translations data
|
||||
list($originalTranslations, $activeTranslations) = $this->countTranslations();
|
||||
|
||||
// Get bandwidth data
|
||||
list($upload, $download, $uploadTotal, $downloadTotal, $storageUsage) = $this->getDiskData();
|
||||
|
||||
@@ -31,7 +21,7 @@ class GetDashboardDataController extends Controller
|
||||
->where('type', 'charge')
|
||||
->sum('amount');
|
||||
|
||||
return response([
|
||||
return response()->json([
|
||||
'users' => [
|
||||
'total' => User::count(),
|
||||
'usersPremiumTotal' => Subscription::count(),
|
||||
@@ -48,8 +38,6 @@ class GetDashboardDataController extends Controller
|
||||
],
|
||||
],
|
||||
'app' => [
|
||||
'shouldUpgrade' => count($shouldUpgrade) > 0,
|
||||
'shouldUpgradeTranslations' => $activeTranslations !== $originalTranslations,
|
||||
'isRunningCron' => isRunningCron(),
|
||||
'license' => get_settings('license'),
|
||||
'version' => config('vuefilemanager.version'),
|
||||
@@ -111,40 +99,4 @@ class GetDashboardDataController extends Controller
|
||||
|
||||
return [$upload, $download, $uploadTotal, $downloadTotal, $storageUsage];
|
||||
}
|
||||
|
||||
private function countTranslations(): array
|
||||
{
|
||||
$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(),
|
||||
];
|
||||
|
||||
$originalTranslationCount = count($default_translations[get_settings('license')]);
|
||||
|
||||
$activeTranslationsCount = DB::table('language_translations')
|
||||
->where('lang', 'en')
|
||||
->count();
|
||||
|
||||
return [$originalTranslationCount, $activeTranslationsCount];
|
||||
}
|
||||
|
||||
private function getUpgradeData(): array
|
||||
{
|
||||
// Get already updated versions
|
||||
$alreadyUpdated = Schema::hasTable('app_updates')
|
||||
? AppUpdate::all()
|
||||
->pluck('version')
|
||||
->toArray()
|
||||
: [];
|
||||
|
||||
// Get versions which has to be upgraded
|
||||
return array_diff(config('vuefilemanager.updates'), $alreadyUpdated);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -1,10 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Domain\Localization\Actions;
|
||||
|
||||
use DB;
|
||||
|
||||
class DeleteLanguageStringsAction
|
||||
class DeleteLanguageTranslationsAction
|
||||
{
|
||||
public function __invoke(array $list): void
|
||||
{
|
||||
@@ -12,4 +11,4 @@ class DeleteLanguageStringsAction
|
||||
->whereIn('key', $list)
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Domain\Localization\Actions;
|
||||
|
||||
use DB;
|
||||
|
||||
class UpdateLanguageStringsAction
|
||||
{
|
||||
public function __invoke(array $list): void
|
||||
{
|
||||
collect($list)
|
||||
->each(fn(...$item) => DB::table('language_translations')
|
||||
->where('lang', 'en')
|
||||
->where('key', $item[1])
|
||||
->update(['value' => $item[0]])
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Domain\Localization\Actions;
|
||||
|
||||
use DB;
|
||||
|
||||
class UpdateLanguageTranslationsAction
|
||||
{
|
||||
public function __invoke(array $list): void
|
||||
{
|
||||
collect($list)
|
||||
->each(
|
||||
fn (...$item) => DB::table('language_translations')
|
||||
->where('lang', 'en')
|
||||
->where('key', $item[1])
|
||||
->update(['value' => $item[0]])
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,12 @@
|
||||
<?php
|
||||
namespace Domain\Maintenance\Actions;
|
||||
|
||||
use Gate;
|
||||
use Artisan;
|
||||
|
||||
class UpgradeDatabaseAction
|
||||
{
|
||||
public function __invoke(): bool
|
||||
{
|
||||
// Check admin permission
|
||||
Gate::authorize('maintenance');
|
||||
|
||||
return Artisan::call('migrate', [
|
||||
'--force' => true,
|
||||
]);
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
namespace Domain\Maintenance\Controllers;
|
||||
|
||||
use Gate;
|
||||
use Illuminate\Http\Response;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Domain\Localization\Actions\UpgradeLanguageTranslationsAction;
|
||||
|
||||
class UpgradeTranslationsController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
public UpgradeLanguageTranslationsAction $upgradeLanguageTranslations,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get new language translations from default translations
|
||||
* and insert it into database
|
||||
*/
|
||||
public function __invoke(): Response
|
||||
{
|
||||
// Check admin permission
|
||||
Gate::authorize('maintenance');
|
||||
|
||||
($this->upgradeLanguageTranslations)();
|
||||
|
||||
return response('Done.', 201);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace Domain\Settings\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
namespace Support\Demo\Actions;
|
||||
|
||||
use App\Users\Models\User;
|
||||
use DB;
|
||||
use App\Users\Models\User;
|
||||
|
||||
class DeleteAllSharedLinksAction
|
||||
class DeleteAllDemoSharedLinksAction
|
||||
{
|
||||
public function __invoke()
|
||||
{
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace Support\Upgrading\Actions;
|
||||
|
||||
use DB;
|
||||
use Schema;
|
||||
use Artisan;
|
||||
use Domain\Maintenance\Models\AppUpdate;
|
||||
use Support\Upgrading\Controllers\UpgradingVersionsController;
|
||||
use Domain\Localization\Actions\UpgradeLanguageTranslationsAction;
|
||||
|
||||
class UpdateSystemAction extends UpgradingVersionsController
|
||||
{
|
||||
public function __invoke(): void
|
||||
{
|
||||
ini_set('max_execution_time', -1);
|
||||
|
||||
// Upgrade the language translations
|
||||
if ($this->shouldUpdateTranslations()) {
|
||||
resolve(UpgradeLanguageTranslationsAction::class)();
|
||||
}
|
||||
|
||||
// Check if there are some version to upgrade
|
||||
$shouldUpgradeSystem = $this->shouldUpgradeSystem();
|
||||
|
||||
// Upgrade the app
|
||||
if (! empty($shouldUpgradeSystem)) {
|
||||
foreach ($shouldUpgradeSystem as $version) {
|
||||
// Get method name
|
||||
$method = "upgrade_to_$version";
|
||||
|
||||
if (method_exists($this, $method)) {
|
||||
// Run update
|
||||
$this->{$method}();
|
||||
|
||||
// Store update record
|
||||
AppUpdate::create(['version' => $version]);
|
||||
}
|
||||
}
|
||||
|
||||
// Clear config
|
||||
Artisan::call('config:clear');
|
||||
}
|
||||
}
|
||||
|
||||
private function shouldUpgradeSystem(): array
|
||||
{
|
||||
// Get already updated versions
|
||||
$alreadyUpdated = Schema::hasTable('app_updates')
|
||||
? AppUpdate::all()
|
||||
->pluck('version')
|
||||
->toArray()
|
||||
: [];
|
||||
|
||||
// Get versions which has to be upgraded
|
||||
return array_diff(config('vuefilemanager.updates'), $alreadyUpdated);
|
||||
}
|
||||
|
||||
private function shouldUpdateTranslations(): bool
|
||||
{
|
||||
$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(),
|
||||
];
|
||||
|
||||
$originalTranslationCount = count($default_translations[get_settings('license')]);
|
||||
|
||||
$activeTranslationsCount = DB::table('language_translations')
|
||||
->where('lang', 'en')
|
||||
->count();
|
||||
|
||||
return $activeTranslationsCount !== $originalTranslationCount;
|
||||
}
|
||||
}
|
||||
+11
-52
@@ -1,69 +1,28 @@
|
||||
<?php
|
||||
namespace Domain\Maintenance\Controllers;
|
||||
namespace Support\Upgrading\Controllers;
|
||||
|
||||
use DB;
|
||||
use Domain\Localization\Actions\DeleteLanguageStringsAction;
|
||||
use Domain\Localization\Actions\UpdateLanguageStringsAction;
|
||||
use Schema;
|
||||
use Storage;
|
||||
use Artisan;
|
||||
use Storage;
|
||||
use App\Users\Models\User;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Http\Request;
|
||||
use Domain\Files\Models\File;
|
||||
use Illuminate\Http\Response;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Domain\Maintenance\Models\AppUpdate;
|
||||
use Domain\Maintenance\Actions\UpgradeDatabaseAction;
|
||||
use VueFileManager\Subscription\Domain\Plans\Models\Plan;
|
||||
use Domain\Localization\Actions\DeleteLanguageTranslationsAction;
|
||||
use Domain\Localization\Actions\UpdateLanguageTranslationsAction;
|
||||
|
||||
class UpgradeSystemController extends Controller
|
||||
class UpgradingVersionsController
|
||||
{
|
||||
public function __construct(
|
||||
public UpgradeDatabaseAction $upgradeDatabase,
|
||||
public DeleteLanguageStringsAction $deleteLanguageStrings,
|
||||
public UpdateLanguageStringsAction $updateLanguageStrings,
|
||||
public DeleteLanguageTranslationsAction $deleteLanguageStrings,
|
||||
public UpdateLanguageTranslationsAction $updateLanguageStrings,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Request $request): Response
|
||||
{
|
||||
ini_set('max_execution_time', -1);
|
||||
|
||||
// Clear config
|
||||
Artisan::call('config:clear');
|
||||
|
||||
// Get already updated versions
|
||||
$alreadyUpdated = Schema::hasTable('app_updates')
|
||||
? AppUpdate::all()
|
||||
->pluck('version')
|
||||
->toArray()
|
||||
: [];
|
||||
|
||||
// Get versions which has to be upgraded
|
||||
$needToUpgrade = array_diff(config('vuefilemanager.updates'), $alreadyUpdated);
|
||||
|
||||
// Iterate and upgrade
|
||||
foreach ($needToUpgrade as $version) {
|
||||
// Get method name
|
||||
$method = "upgrade_to_$version";
|
||||
|
||||
if (method_exists($this, $method)) {
|
||||
// Run update
|
||||
$this->{$method}($request);
|
||||
|
||||
// Store update record
|
||||
AppUpdate::create(['version' => $version]);
|
||||
|
||||
return response('Done', 201);
|
||||
}
|
||||
}
|
||||
|
||||
return response('Whooops, something went wrong!', 500);
|
||||
}
|
||||
|
||||
private function upgrade_to_2_0_10(): void
|
||||
public function upgrade_to_2_0_10(): void
|
||||
{
|
||||
($this->upgradeDatabase)();
|
||||
|
||||
@@ -131,7 +90,7 @@ class UpgradeSystemController extends Controller
|
||||
]));
|
||||
}
|
||||
|
||||
private function upgrade_to_2_0_13(): void
|
||||
public function upgrade_to_2_0_13(): void
|
||||
{
|
||||
// Force plan synchronization
|
||||
if (get_settings('license') === 'extended' && Plan::count() !== 0) {
|
||||
@@ -139,7 +98,7 @@ class UpgradeSystemController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
private function upgrade_to_2_0_14(): void
|
||||
public function upgrade_to_2_0_14(): void
|
||||
{
|
||||
($this->upgradeDatabase)();
|
||||
|
||||
@@ -148,7 +107,7 @@ class UpgradeSystemController extends Controller
|
||||
->each(fn ($user) => $user->forceFill(['two_factor_confirmed_at' => now()])->save());
|
||||
|
||||
($this->deleteLanguageStrings)([
|
||||
'popup_2fa.disappear_qr'
|
||||
'popup_2fa.disappear_qr',
|
||||
]);
|
||||
|
||||
($this->updateLanguageStrings)([
|
||||
Reference in New Issue
Block a user