6d6f5d571a
- Admin panel page at #Admin/dataMigration with two-column layout - Export: filter by case status, skip attachments option, progress + log - Import: select backup, preserve IDs / skip duplicates, dry run support - List/delete existing backups with full manifest details - 5 API endpoints (status, export, import, listBackups, deleteBackup) - BufferedIO adapter to capture CLI output for API responses - Admin-only access on all endpoints - i18n: English + Hebrew (fa_IR) translations Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
68 lines
1.8 KiB
PHP
68 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Espo\Modules\DataMigration\Api;
|
|
|
|
use Espo\Core\Api\Action;
|
|
use Espo\Core\Api\Request;
|
|
use Espo\Core\Api\Response;
|
|
use Espo\Core\Api\ResponseComposer;
|
|
use Espo\Core\Exceptions\BadRequest;
|
|
use Espo\Core\Exceptions\Forbidden;
|
|
use Espo\Entities\User;
|
|
use Espo\Modules\DataMigration\Services\ImportService;
|
|
use Espo\Modules\DataMigration\Services\BufferedIO;
|
|
|
|
class Import implements Action
|
|
{
|
|
public function __construct(
|
|
private ImportService $importService,
|
|
private User $user
|
|
) {}
|
|
|
|
public function process(Request $request): Response
|
|
{
|
|
if (!$this->user->isAdmin()) {
|
|
throw new Forbidden();
|
|
}
|
|
|
|
$body = $request->getParsedBody();
|
|
|
|
$backupName = $body->backupName ?? null;
|
|
|
|
if (!$backupName) {
|
|
throw new BadRequest('backupName is required.');
|
|
}
|
|
|
|
$inputDir = 'data/backups/' . basename($backupName);
|
|
|
|
if (!is_dir($inputDir)) {
|
|
throw new BadRequest("Backup not found: {$backupName}");
|
|
}
|
|
|
|
if (!file_exists($inputDir . '/manifest.json')) {
|
|
throw new BadRequest("Invalid backup: no manifest.json found.");
|
|
}
|
|
|
|
$preserveIds = $body->preserveIds ?? true;
|
|
$skipDuplicates = $body->skipDuplicates ?? true;
|
|
$dryRun = $body->dryRun ?? false;
|
|
|
|
$io = new BufferedIO();
|
|
|
|
$this->importService->import($inputDir, [
|
|
'batchSize' => 500,
|
|
'preserveIds' => $preserveIds,
|
|
'skipDuplicates' => $skipDuplicates,
|
|
'dryRun' => $dryRun,
|
|
'verbose' => true,
|
|
], $io);
|
|
|
|
return ResponseComposer::json([
|
|
'success' => true,
|
|
'backupName' => $backupName,
|
|
'dryRun' => $dryRun,
|
|
'log' => $io->getLines(),
|
|
]);
|
|
}
|
|
}
|