fix: resolve report template from WebDAV when not found locally

DirectAccessReportGenerator now downloads the template from NetworkStorage
(WebDAV) if it's not found in data/document-templates/. This means template
updates via WebDAV are picked up automatically without manual file copy.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-09 13:41:26 +00:00
parent 3992384d96
commit 015586a9df
2 changed files with 53 additions and 2 deletions
@@ -83,6 +83,11 @@ class DirectAccessReportGenerator
$content = file_get_contents($outputPath);
@unlink($outputPath);
// Clean up temp template if downloaded from storage
if (str_starts_with($templatePath, self::TEMP_DIR)) {
@unlink($templatePath);
}
// Create Attachment
$attachment = $this->entityManager->getNewEntity('Attachment');
$attachment->set([
@@ -248,6 +253,12 @@ class DirectAccessReportGenerator
if (file_exists($resolved)) {
return $resolved;
}
// Download from NetworkStorage (WebDAV)
$downloaded = $this->downloadTemplateFromStorage($templatePath);
if ($downloaded) {
return $downloaded;
}
}
}
@@ -266,6 +277,46 @@ class DirectAccessReportGenerator
throw new Error("Template '" . self::TEMPLATE_NAME . "' not found.");
}
private function downloadTemplateFromStorage(string $templatePath): ?string
{
try {
$nds = $this->injectableFactory->create(
\Espo\Modules\NetworkStorageIntegration\Services\NetworkDocumentService::class
);
$client = $nds->getClient();
// Try Templates/{templatePath} on the storage
$integration = $this->entityManager->getEntityById('Integration', 'NetworkStorage');
$templatesFolderPath = 'Templates';
if ($integration && $integration->get('enabled')) {
$data = (array) ($integration->get('data') ?? []);
$templatesFolderPath = $data['templatesFolderPath'] ?? 'Templates';
}
$storagePath = $templatesFolderPath . '/' . $templatePath;
if (!$client->exists($storagePath)) {
$this->log->debug("LegalAssistance: Template not found on storage: {$storagePath}");
return null;
}
$content = $client->downloadFile($storagePath);
// Save locally for this request
if (!is_dir(self::TEMP_DIR)) {
mkdir(self::TEMP_DIR, 0775, true);
}
$localPath = self::TEMP_DIR . 'template_' . uniqid() . '.docx';
file_put_contents($localPath, $content);
$this->log->debug("LegalAssistance: Template downloaded from storage: {$storagePath}{$localPath}");
return $localPath;
} catch (\Exception $e) {
$this->log->warning("LegalAssistance: Failed to download template from storage: " . $e->getMessage());
return null;
}
}
private function processTemplate(string $inputPath, string $outputPath, array $data): void
{
// Ensure PHPWord autoloader is registered
+2 -2
View File
@@ -1,9 +1,9 @@
{
"name": "LegalAssistance",
"version": "2.0.1",
"version": "2.0.2",
"acceptableVersions": [">=8.0.0"],
"php": [">=8.1"],
"releaseDate": "2026-04-07",
"releaseDate": "2026-04-09",
"author": "Marcus-Law",
"description": "סיוע משפטי — יצירת דוח גישה ישירה (JSON ישירות ל-DOCX), אינטגרציה עם שירה",
"scripts": {