Better error management

This commit is contained in:
Laurent Destailleur
2025-10-29 20:41:25 +01:00
parent 440c2d238a
commit ebdf77bbde
2 changed files with 15 additions and 2 deletions

View File

@@ -1298,7 +1298,11 @@ if ($mode == 'marketplace') {
print '</td>';
print '<td class="center">';
if (!getDolGlobalString('MAIN_DISABLE_EXTERNALMODULES_COMMUNITY') && getDolGlobalInt('MAIN_ENABLE_EXTERNALMODULES_COMMUNITY')) {
$messagetoadd = '<br><br><span class="small">Content of the repository index file '.$remotestore->file_source_url.' is in the local cache file '.$remotestore->cache_file.' (Date: '.dol_print_date(dol_filemtime($remotestore->cache_file), 'dayhour', 'tzuserrel').')</span>';
$messagetoadd = '<br><br><span class="small">Content of the repository index file '.$remotestore->file_source_url.' should be in the local cache file '.$remotestore->cache_file;
$messagetoadd .= ' (Date: '.dol_print_date(dol_filemtime($remotestore->cache_file), 'dayhour', 'tzuserrel').')</span>';
if ($remotestore->githubFileError) {
$messagetoadd .= '<br><span class="error small">'.$remotestore->githubFileError.'</span>';
}
print $remotestore->libStatus($remotestore->githubFileStatus, 2, $messagetoadd);
}
print '</td>';

View File

@@ -100,6 +100,11 @@ class ExternalModules
*/
public $githubFileStatus;
/**
* @var string
*/
public $githubFileError;
/**
* @var int // number of online providers
*/
@@ -169,6 +174,7 @@ class ExternalModules
$this->getRemoteYamlFile($this->file_source_url, $cachedelayforgithubrepo);
$this->githubFileError = $this->error;
$this->githubFileStatus = dol_is_file($this->cache_file) ? 1 : 0;
}
@@ -891,7 +897,10 @@ class ExternalModules
$result = getURLContent($file_source_url, 'GET', '', 1, $addheaders); // TODO Force timeout to 5 s on both connect and response.
if (!empty($result) && $result['http_code'] == 200) {
$yaml = $result['content'];
file_put_contents($cache_file, $yaml);
$result = file_put_contents($cache_file, $yaml);
if ($result === false) {
$this->error = 'Failed to create cache file: ' . $cache_file;
}
}
} else {
$yaml = file_get_contents($cache_file);