Fix template management with online/offline fallback

- Try to fetch manifest from Gitea first, fallback to local if not accessible
- Try to download templates from Gitea first, fallback to local if not accessible
- Support both online template updates and offline functionality
- Enable other installations to check for template updates when online
- Provide reliable fallback for offline installations
This commit is contained in:
Frank Cools 2025-10-07 20:21:47 +02:00
parent 96dc421177
commit f10f402073

View File

@ -1535,17 +1535,18 @@ class DeclarationTVA_PDF
);
try {
// Use local manifest file instead of fetching from Gitea
$local_manifest = DOL_DOCUMENT_ROOT.'/custom/declarationtva/templates/manifest.json';
if (!file_exists($local_manifest)) {
$update_info['error'] = 'Local manifest file not found';
return $update_info;
}
$manifest_content = file_get_contents($local_manifest);
// Try to fetch manifest from Gitea, fallback to local if not accessible
$manifest_content = @file_get_contents($this->manifest_url);
if ($manifest_content === false) {
$update_info['error'] = 'Failed to read local manifest file';
return $update_info;
// Fallback to local manifest file
$local_manifest = DOL_DOCUMENT_ROOT.'/custom/declarationtva/templates/manifest.json';
if (file_exists($local_manifest)) {
$manifest_content = file_get_contents($local_manifest);
}
if ($manifest_content === false) {
$update_info['error'] = 'Failed to fetch manifest from Gitea and local file not found';
return $update_info;
}
}
$manifest = json_decode($manifest_content, true);
@ -1592,17 +1593,18 @@ class DeclarationTVA_PDF
dol_mkdir($this->template_path);
}
// Use local template file instead of downloading from Gitea
$local_template = DOL_DOCUMENT_ROOT.'/custom/declarationtva/templates/declarationtva/ca3_official_template.pdf';
if (!file_exists($local_template)) {
$this->error = 'Local template file not found';
return false;
}
$template_content = file_get_contents($local_template);
// Try to download template from Gitea, fallback to local if not accessible
$template_content = @file_get_contents($download_url);
if ($template_content === false) {
$this->error = 'Failed to read local template file';
return false;
// Fallback to local template file
$local_template = DOL_DOCUMENT_ROOT.'/custom/declarationtva/templates/declarationtva/ca3_official_template.pdf';
if (file_exists($local_template)) {
$template_content = file_get_contents($local_template);
}
if ($template_content === false) {
$this->error = 'Failed to download template from Gitea and local file not found';
return false;
}
}
// Save as official template