This repository has been archived on 2026-07-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
DataMigration/files/custom/Espo/Modules/DataMigration/Api/Import.php
T
chaim 6d6f5d571a feat: add admin UI for export/import data migration
- 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>
2026-03-29 19:45:20 +00:00

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(),
]);
}
}