mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-28 02:50:39 +00:00
updates automatically handled on the background
This commit is contained in:
@@ -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,161 +0,0 @@
|
||||
<?php
|
||||
namespace Domain\Maintenance\Controllers;
|
||||
|
||||
use DB;
|
||||
use Domain\Localization\Actions\DeleteLanguageStringsAction;
|
||||
use Domain\Localization\Actions\UpdateLanguageStringsAction;
|
||||
use Schema;
|
||||
use Storage;
|
||||
use Artisan;
|
||||
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;
|
||||
|
||||
class UpgradeSystemController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
public UpgradeDatabaseAction $upgradeDatabase,
|
||||
public DeleteLanguageStringsAction $deleteLanguageStrings,
|
||||
public UpdateLanguageStringsAction $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
|
||||
{
|
||||
($this->upgradeDatabase)();
|
||||
|
||||
// Upgrade team folder content ownership
|
||||
Folder::where('parent_id', null)
|
||||
->where('team_folder', true)
|
||||
->cursor()
|
||||
->each(function ($teamFolder) {
|
||||
// Get all inherited folder from team folder
|
||||
$childrenFolderIds = Folder::with('folders:id,parent_id')
|
||||
->where('id', $teamFolder->id)
|
||||
->get('id');
|
||||
|
||||
$teamFolderIds = Arr::flatten(filter_folders_ids($childrenFolderIds));
|
||||
|
||||
// Replace user content ownership for author of team folder
|
||||
DB::table('files')
|
||||
->whereIn('parent_id', $teamFolderIds)
|
||||
->cursor()
|
||||
->each(function ($file) use ($teamFolder) {
|
||||
// Move image thumbnails
|
||||
if ($file->type === 'image') {
|
||||
// Get image thumbnail list
|
||||
$thumbnailList = getThumbnailFileList($file->basename);
|
||||
|
||||
// move thumbnails to the new location
|
||||
$thumbnailList->each(function ($basename) use ($file, $teamFolder) {
|
||||
$oldPath = "files/$file->user_id/$basename";
|
||||
$newPath = "files/$teamFolder->user_id/$basename";
|
||||
|
||||
if (Storage::exists($oldPath)) {
|
||||
Storage::move($oldPath, $newPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Get single file path
|
||||
$filePath = "files/$file->user_id/$file->basename";
|
||||
|
||||
// Move single file
|
||||
if (Storage::exists($filePath)) {
|
||||
Storage::move($filePath, "files/$teamFolder->user_id/$file->basename");
|
||||
}
|
||||
|
||||
// Update file permission
|
||||
File::find($file->id)->update([
|
||||
'user_id' => $teamFolder->user_id,
|
||||
'creator_id' => $teamFolder->user_id !== $file->user_id ? $file->user_id : null,
|
||||
]);
|
||||
});
|
||||
|
||||
// Update folder ownership
|
||||
DB::table('folders')
|
||||
->whereIn('parent_id', $teamFolderIds)
|
||||
->update(['user_id' => $teamFolder->user_id]);
|
||||
});
|
||||
|
||||
// Upgrade dwg files
|
||||
File::withTrashed()
|
||||
->where('mimetype', 'vnd.dwg')
|
||||
->cursor()
|
||||
->each(fn ($file) => $file->update([
|
||||
'mimetype' => 'dwg',
|
||||
'type' => 'file',
|
||||
]));
|
||||
}
|
||||
|
||||
private function upgrade_to_2_0_13(): void
|
||||
{
|
||||
// Force plan synchronization
|
||||
if (get_settings('license') === 'extended' && Plan::count() !== 0) {
|
||||
Artisan::call('subscription:synchronize-plans');
|
||||
}
|
||||
}
|
||||
|
||||
private function upgrade_to_2_0_14(): void
|
||||
{
|
||||
($this->upgradeDatabase)();
|
||||
|
||||
User::whereNotNull('two_factor_secret')
|
||||
->cursor()
|
||||
->each(fn ($user) => $user->forceFill(['two_factor_confirmed_at' => now()])->save());
|
||||
|
||||
($this->deleteLanguageStrings)([
|
||||
'popup_2fa.disappear_qr'
|
||||
]);
|
||||
|
||||
($this->updateLanguageStrings)([
|
||||
'require_email_verification' => 'Require Verify Email Address',
|
||||
'require_email_verification_note' => 'Turn on, if you want to verify user email address after registration.',
|
||||
]);
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user