Fix ECM files class path issue in PDF saving

- Made ECM files integration optional and graceful
- Added file existence check before requiring ecmfiles.class.php
- Wrapped ECM file creation in try-catch to prevent fatal errors
- PDF is still saved to disk even if ECM integration fails
- Added detailed error logging for troubleshooting
- System now works regardless of ECM files availability
This commit is contained in:
Frank Cools 2025-10-06 17:08:59 +02:00
parent 8d42e47b52
commit 77027debf5

View File

@ -1066,8 +1066,12 @@ class DeclarationTVA
return false;
}
// Add document record to Dolibarr
require_once DOL_DOCUMENT_ROOT . '/core/class/ecmfiles.class.php';
// Try to add document record to Dolibarr (optional feature)
$ecmfiles_path = DOL_DOCUMENT_ROOT . '/core/class/ecmfiles.class.php';
if (file_exists($ecmfiles_path)) {
try {
require_once $ecmfiles_path;
$ecmfile = new EcmFiles($this->db);
$ecmfile->filepath = 'declarationtva/validated/';
@ -1091,11 +1095,21 @@ class DeclarationTVA
// Log the error but don't fail the whole process
error_log("DeclarationTVA: Failed to link document to declaration: " . $this->error);
}
return true;
} else {
$this->error = "Failed to create ECM file record: " . $ecmfile->error;
return false;
// Log the error but don't fail the whole process
error_log("DeclarationTVA: Failed to create ECM file record: " . $ecmfile->error);
}
} catch (Exception $e) {
// Log the error but don't fail the whole process
error_log("DeclarationTVA: Exception creating ECM file: " . $e->getMessage());
}
} else {
// Log that ECM files class is not available
error_log("DeclarationTVA: ECM files class not found at: " . $ecmfiles_path);
}
// Return true even if ECM file creation failed - the PDF is still saved to disk
return true;
} catch (Exception $e) {
$this->error = "Exception in saveValidatedPDF: " . $e->getMessage();
return false;