dashboard alert box for new system upgrade

This commit is contained in:
Čarodej
2022-03-30 18:12:41 +02:00
parent dff804153e
commit 3f8fc1c9ce
19 changed files with 299 additions and 198 deletions

View File

@@ -1,5 +1,4 @@
<?php
namespace App\Console\Commands;
use App\Users\Models\User;
@@ -880,15 +879,15 @@ class SetupDevEnvironment extends Command
// Create file record
File::create([
'parent_id' => $teamGallery->id,
'user_id' => $user->id,
'parent_id' => $teamGallery->id,
'user_id' => $user->id,
'creator_id' => $author->id,
'name' => $thumbnail['name'],
'basename' => $thumbnail['basename'],
'type' => 'image',
'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
'name' => $thumbnail['name'],
'basename' => $thumbnail['basename'],
'type' => 'image',
'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
]);
});
@@ -903,15 +902,15 @@ class SetupDevEnvironment extends Command
// Create file record
File::create([
'parent_id' => $presentationMaterial->id,
'user_id' => $user->id,
'parent_id' => $presentationMaterial->id,
'user_id' => $user->id,
'creator_id' => $author->id,
'name' => $thumbnail['name'],
'basename' => $thumbnail['basename'],
'type' => 'image',
'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
'name' => $thumbnail['name'],
'basename' => $thumbnail['basename'],
'type' => 'image',
'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
]);
});
@@ -951,15 +950,15 @@ class SetupDevEnvironment extends Command
// Create file record
File::create([
'parent_id' => $financeDocumentsFolder->id,
'user_id' => $user->id,
'parent_id' => $financeDocumentsFolder->id,
'user_id' => $user->id,
'creator_id' => $author->id,
'name' => $thumbnail['name'],
'basename' => $thumbnail['basename'],
'type' => 'image',
'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
'name' => $thumbnail['name'],
'basename' => $thumbnail['basename'],
'type' => 'image',
'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
]);
});
@@ -974,15 +973,15 @@ class SetupDevEnvironment extends Command
// Create file record
File::create([
'parent_id' => $reserves->id,
'user_id' => $user->id,
'parent_id' => $reserves->id,
'user_id' => $user->id,
'creator_id' => $author->id,
'name' => $thumbnail['name'],
'basename' => $thumbnail['basename'],
'type' => 'image',
'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
'name' => $thumbnail['name'],
'basename' => $thumbnail['basename'],
'type' => 'image',
'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
]);
});
@@ -1025,15 +1024,15 @@ class SetupDevEnvironment extends Command
// Create file record
File::create([
'parent_id' => $folder->id,
'user_id' => $user->id,
'parent_id' => $folder->id,
'user_id' => $user->id,
'creator_id' => $author->id,
'name' => $file['name'],
'basename' => $basename,
'type' => 'file',
'mimetype' => $file['mimetype'],
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
'name' => $file['name'],
'basename' => $basename,
'type' => 'file',
'mimetype' => $file['mimetype'],
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
]);
});
@@ -1067,15 +1066,15 @@ class SetupDevEnvironment extends Command
// Create file record
File::create([
'parent_id' => $destinationGallery->id,
'user_id' => $user->id,
'parent_id' => $destinationGallery->id,
'user_id' => $user->id,
'creator_id' => $author->id,
'name' => $thumbnail['name'],
'basename' => $thumbnail['basename'],
'type' => 'image',
'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
'name' => $thumbnail['name'],
'basename' => $thumbnail['basename'],
'type' => 'image',
'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
]);
});
@@ -1107,15 +1106,15 @@ class SetupDevEnvironment extends Command
// Create file record
File::create([
'parent_id' => $holiday2022Folder->id,
'user_id' => $user->id,
'parent_id' => $holiday2022Folder->id,
'user_id' => $user->id,
'creator_id' => $author->id,
'name' => $file['name'],
'basename' => $basename,
'type' => 'file',
'mimetype' => $file['mimetype'],
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
'name' => $file['name'],
'basename' => $basename,
'type' => 'file',
'mimetype' => $file['mimetype'],
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
]);
});
@@ -1135,7 +1134,7 @@ class SetupDevEnvironment extends Command
collect([$members[0]->id, $members[1]->id, $members[5]->id])
->each(
fn($id) => DB::table('team_folder_members')
fn ($id) => DB::table('team_folder_members')
->insert([
'parent_id' => $companyProjectFolder->id,
'user_id' => $id,
@@ -1145,7 +1144,7 @@ class SetupDevEnvironment extends Command
collect([$members[3]->id, $members[2]->id])
->each(
fn($id) => DB::table('team_folder_members')
fn ($id) => DB::table('team_folder_members')
->insert([
'parent_id' => $financeDocumentsFolder->id,
'user_id' => $id,
@@ -1155,7 +1154,7 @@ class SetupDevEnvironment extends Command
collect([$members[2]->id, $members[3]->id, $members[5]->id, $members[0]->id])
->each(
fn($id) => DB::table('team_folder_members')
fn ($id) => DB::table('team_folder_members')
->insert([
'parent_id' => $holiday2022Folder->id,
'user_id' => $id,
@@ -1166,7 +1165,7 @@ class SetupDevEnvironment extends Command
// Create invitations
collect([$members[4], $members[5]])
->each(
fn($user) => TeamFolderInvitation::factory()
fn ($user) => TeamFolderInvitation::factory()
->create([
'email' => $user->email,
'parent_id' => $companyProjectFolder->id,
@@ -1247,15 +1246,15 @@ class SetupDevEnvironment extends Command
// Create file record
File::create([
'parent_id' => $videos->id,
'user_id' => $owner->id,
'parent_id' => $videos->id,
'user_id' => $owner->id,
'creator_id' => $author->id,
'name' => $file,
'basename' => $basename,
'type' => 'video',
'mimetype' => 'mp4',
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
'name' => $file,
'basename' => $basename,
'type' => 'video',
'mimetype' => 'mp4',
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
]);
});
@@ -1276,15 +1275,15 @@ class SetupDevEnvironment extends Command
// Create file record
File::create([
'parent_id' => $folder->id,
'user_id' => $owner->id,
'parent_id' => $folder->id,
'user_id' => $owner->id,
'creator_id' => $author->id,
'name' => $file['name'],
'basename' => $basename,
'type' => 'file',
'mimetype' => $file['mimetype'],
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
'name' => $file['name'],
'basename' => $basename,
'type' => 'file',
'mimetype' => $file['mimetype'],
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
]);
});
@@ -1318,15 +1317,15 @@ class SetupDevEnvironment extends Command
// Create file record
File::create([
'parent_id' => $folder->id,
'user_id' => $owner->id,
'parent_id' => $folder->id,
'user_id' => $owner->id,
'creator_id' => $johan->id,
'name' => $thumbnail['name'],
'basename' => $thumbnail['basename'],
'type' => 'image',
'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
'name' => $thumbnail['name'],
'basename' => $thumbnail['basename'],
'type' => 'image',
'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
]);
});
@@ -1339,15 +1338,15 @@ class SetupDevEnvironment extends Command
// Create file record
File::create([
'parent_id' => $hug->id,
'user_id' => $owner->id,
'parent_id' => $hug->id,
'user_id' => $owner->id,
'creator_id' => $member->id,
'name' => $thumbnail['name'],
'basename' => $thumbnail['basename'],
'type' => 'image',
'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
'name' => $thumbnail['name'],
'basename' => $thumbnail['basename'],
'type' => 'image',
'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000),
'created_at' => now()->subMinutes(rand(1, 5)),
]);
});
}
@@ -1568,7 +1567,7 @@ class SetupDevEnvironment extends Command
foreach (range(0, 45) as $day) {
$user
->each(
fn($user) => DB::table('traffic')
fn ($user) => DB::table('traffic')
->insert([
'id' => Str::uuid(),
'user_id' => $user->id,
@@ -1664,7 +1663,7 @@ class SetupDevEnvironment extends Command
// Create thumbnail only if image is larger than predefined image sizes
if ($intervention->getWidth() > $size['size']) {
// Generate thumbnail
$intervention->resize($size['size'], null, fn($constraint) => $constraint->aspectRatio())->stream();
$intervention->resize($size['size'], null, fn ($constraint) => $constraint->aspectRatio())->stream();
// Store thumbnail to disk
Storage::put("files/$user->id/{$size['name']}-{$file_name}", $intervention);

View File

@@ -1,11 +1,13 @@
<?php
namespace Domain\Admin\Controllers\Dashboard;
use Schema;
use ByteUnits\Metric;
use App\Users\Models\User;
use Illuminate\Http\Response;
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;
@@ -14,6 +16,10 @@ class GetDashboardDataController extends Controller
{
public function __invoke(): Application|ResponseFactory|Response
{
// Get app update data
$shouldUpgrade = $this->getUpgradeData();
// Get translations data
list($originalTranslations, $activeTranslations) = $this->countTranslations();
// Get bandwidth data
@@ -42,6 +48,7 @@ class GetDashboardDataController extends Controller
],
],
'app' => [
'shouldUpgrade' => count($shouldUpgrade) > 0,
'shouldUpgradeTranslations' => $activeTranslations !== $originalTranslations,
'isRunningCron' => isRunningCron(),
'license' => get_settings('license'),
@@ -105,9 +112,6 @@ class GetDashboardDataController extends Controller
return [$upload, $download, $uploadTotal, $downloadTotal, $storageUsage];
}
/**
* @return array
*/
private function countTranslations(): array
{
$default_translations = [
@@ -130,4 +134,17 @@ class GetDashboardDataController extends Controller
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);
}
}

View File

@@ -88,13 +88,13 @@ class UploadFileAction
// Create new file
$item = UserFile::create([
'mimetype' => get_file_type_from_mimetype($fileMimetype),
'type' => get_file_type($fileMimetype),
'parent_id' => ($this->getFileParentId)($request, $user->id),
'name' => $request->input('filename'),
'basename' => $fileName,
'filesize' => $fileSize,
'user_id' => $user->id,
'mimetype' => get_file_type_from_mimetype($fileMimetype),
'type' => get_file_type($fileMimetype),
'parent_id' => ($this->getFileParentId)($request, $user->id),
'name' => $request->input('filename'),
'basename' => $fileName,
'filesize' => $fileSize,
'user_id' => $user->id,
'creator_id' => auth()->id(),
]);

View File

@@ -2,7 +2,6 @@
namespace Domain\Files\Models;
use App\Users\Models\User;
use Domain\Traffic\Actions\RecordUploadAction;
use Illuminate\Support\Str;
use Laravel\Scout\Searchable;
use Domain\Sharing\Models\Share;
@@ -13,6 +12,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use TeamTNT\TNTSearch\Indexer\TNTIndexer;
use \Illuminate\Database\Eloquent\SoftDeletes;
use Domain\Traffic\Actions\RecordUploadAction;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;

View File

@@ -3,7 +3,6 @@ namespace Domain\Folders\Actions;
use Domain\Sharing\Models\Share;
use Domain\Folders\Models\Folder;
use Illuminate\Support\Facades\Auth;
use Domain\Folders\Requests\CreateFolderRequest;
use App\Users\Exceptions\InvalidUserActionException;
@@ -42,7 +41,7 @@ class CreateFolderAction
'user_id' => $user->id,
'team_folder' => $isFilledParentId
? Folder::find($parentId)->getLatestParent()->team_folder
: false
: false,
]);
}
}

View File

@@ -1,15 +1,17 @@
<?php
namespace Domain\Maintenance\Controllers;
use App\Http\Controllers\Controller;
use DB;
use Domain\Files\Models\File;
use Domain\Folders\Models\Folder;
use Domain\Maintenance\Actions\UpgradeDatabaseAction;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Schema;
use Storage;
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;
ini_set('max_execution_time', -1);
@@ -17,26 +19,33 @@ class UpgradeSystemController extends Controller
{
public function __construct(
public UpgradeDatabaseAction $upgradeDatabase,
) {}
) {
}
public function __invoke(Request $request)
public function __invoke(Request $request): Response
{
// Get already updated versions
// TODO: get from database
$alreadyUpdated = ['2_0_8', '2_0_7'];
$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);
}
}
@@ -48,11 +57,11 @@ class UpgradeSystemController extends Controller
{
($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)
@@ -91,7 +100,7 @@ class UpgradeSystemController extends Controller
// Update file permission
File::find($file->id)->update([
'user_id' => $teamFolder->user_id,
'user_id' => $teamFolder->user_id,
'creator_id' => $teamFolder->user_id !== $file->user_id ? $file->user_id : null,
]);
});
@@ -102,4 +111,4 @@ class UpgradeSystemController extends Controller
->update(['user_id' => $teamFolder->user_id]);
});
}
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Domain\Maintenance\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int id
* @property string version
*/
class AppUpdate extends Model
{
public $guarded = [
'id',
];
}

View File

@@ -2,6 +2,7 @@
namespace Domain\Settings\Actions;
use Domain\Settings\Models\Setting;
use Domain\Maintenance\Models\AppUpdate;
class SeedDefaultSettingsAction
{
@@ -11,6 +12,7 @@ class SeedDefaultSettingsAction
public function __invoke(
string $license
): void {
// Set default settings
collect(
config('content.content.' . strtolower($license))
)->each(fn ($content) => Setting::updateOrCreate([
@@ -18,5 +20,9 @@ class SeedDefaultSettingsAction
], [
'value' => $content['value'],
]));
// Set update records
collect(config('vuefilemanager.updates'))
->each(fn ($version) => AppUpdate::create(['version' => $version]));
}
}

View File

@@ -4,10 +4,10 @@ namespace Domain\Teams\Controllers;
use Gate;
use Illuminate\Http\Response;
use Domain\Folders\Models\Folder;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Support\Facades\DB;
class LeaveTeamFolderController extends Controller
{