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:
parent
96dc421177
commit
f10f402073
@ -1535,17 +1535,18 @@ class DeclarationTVA_PDF
|
||||
);
|
||||
|
||||
try {
|
||||
// Use local manifest file instead of fetching from Gitea
|
||||
// Try to fetch manifest from Gitea, fallback to local if not accessible
|
||||
$manifest_content = @file_get_contents($this->manifest_url);
|
||||
if ($manifest_content === false) {
|
||||
// Fallback to local manifest file
|
||||
$local_manifest = DOL_DOCUMENT_ROOT.'/custom/declarationtva/templates/manifest.json';
|
||||
if (!file_exists($local_manifest)) {
|
||||
$update_info['error'] = 'Local manifest file not found';
|
||||
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_content = file_get_contents($local_manifest);
|
||||
if ($manifest_content === false) {
|
||||
$update_info['error'] = 'Failed to read local manifest file';
|
||||
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
|
||||
// Try to download template from Gitea, fallback to local if not accessible
|
||||
$template_content = @file_get_contents($download_url);
|
||||
if ($template_content === false) {
|
||||
// Fallback to local template file
|
||||
$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';
|
||||
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;
|
||||
}
|
||||
|
||||
$template_content = file_get_contents($local_template);
|
||||
if ($template_content === false) {
|
||||
$this->error = 'Failed to read local template file';
|
||||
return false;
|
||||
}
|
||||
|
||||
// Save as official template
|
||||
|
||||
Loading…
Reference in New Issue
Block a user