mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 17:24:10 +00:00
Relocate all 14 files from the catch-all app/Space namespace into proper locations: data providers to Support/Formatters, installation utilities to Services/Installation, PDF utils to Services/Pdf, module/update classes to Services/Module and Services/Update, SiteApi trait to Traits, and helpers to Support. Extract ~1,400 lines of business logic from 8 fat models (Invoice, Payment, Estimate, RecurringInvoice, Company, Customer, Expense, User) into 9 new service classes with constructor injection. Controllers now depend on services instead of calling static model methods. Shared item/tax creation logic consolidated into DocumentItemService.
103 lines
2.3 KiB
PHP
103 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\V1\Admin\Update;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Setting;
|
|
use App\Services\Update\Updater;
|
|
use Illuminate\Http\Request;
|
|
|
|
class UpdateController extends Controller
|
|
{
|
|
public function download(Request $request)
|
|
{
|
|
$this->authorize('manage update app');
|
|
|
|
$request->validate([
|
|
'version' => 'required',
|
|
]);
|
|
|
|
$path = Updater::download($request->version);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'path' => $path,
|
|
]);
|
|
}
|
|
|
|
public function unzip(Request $request)
|
|
{
|
|
$this->authorize('manage update app');
|
|
|
|
$request->validate([
|
|
'path' => 'required',
|
|
]);
|
|
|
|
try {
|
|
$path = Updater::unzip($request->path);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'path' => $path,
|
|
]);
|
|
} catch (\Exception $e) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'error' => $e->getMessage(),
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
public function copyFiles(Request $request)
|
|
{
|
|
$this->authorize('manage update app');
|
|
|
|
$request->validate([
|
|
'path' => 'required',
|
|
]);
|
|
|
|
$path = Updater::copyFiles($request->path);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'path' => $path,
|
|
]);
|
|
}
|
|
|
|
public function migrate(Request $request)
|
|
{
|
|
$this->authorize('manage update app');
|
|
|
|
Updater::migrateUpdate();
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
]);
|
|
}
|
|
|
|
public function finishUpdate(Request $request)
|
|
{
|
|
$this->authorize('manage update app');
|
|
|
|
$request->validate([
|
|
'installed' => 'required',
|
|
'version' => 'required',
|
|
]);
|
|
|
|
$json = Updater::finishUpdate($request->installed, $request->version);
|
|
|
|
return response()->json($json);
|
|
}
|
|
|
|
public function checkLatestVersion(Request $request)
|
|
{
|
|
$this->authorize('manage update app');
|
|
|
|
set_time_limit(600); // 10 minutes
|
|
|
|
$json = Updater::checkForUpdate(Setting::getSetting('version'));
|
|
|
|
return response()->json($json);
|
|
}
|
|
}
|