Debug module scanner

This commit is contained in:
ldestailleur 2025-03-04 22:42:40 +01:00
parent 91811b8335
commit f7cf9225c4
2 changed files with 35 additions and 27 deletions

View file

@ -1286,14 +1286,16 @@ if ($mode == 'marketplace') {
if (!getDolGlobalString('MAIN_DISABLE_DOLISTORE_SEARCH') && getDolGlobalInt('MAIN_ENABLE_DOLISTORE')) {
$messagetoadd = '';
if ($remotestore->dolistoreApiStatus <= 0) {
$messagetoadd = '<br>'.$remotestore->dolistoreApiError.'<br>Failed to login to: '.$remotestore->dolistore_api_url;
$messagetoadd .= '<br>using API public key: '.$remotestore->dolistore_api_key;
// Add basic auth if needed
$basicAuthLogin = getDolGlobalString('MAIN_MODULE_DOLISTORE_BASIC_LOGIN');
$basicAuthPassword = getDolGlobalString('MAIN_MODULE_DOLISTORE_BASIC_PASSWORD');
if ($basicAuthLogin) {
$messagetoadd .= '<br>using basic auth login: base64('.$basicAuthLogin.':'.$basicAuthPassword.')';
}
$messagetoadd = '<br>'.$remotestore->dolistoreApiError.'<br>Failed to get answer of remote API server<br>';
}
$messagetoadd .= '<br>Using Remote API URL MAIN_MODULE_DOLISTORE_API_URL: '.$remotestore->dolistore_api_url;
$messagetoadd .= '<br>Using API public key MAIN_MODULE_DOLISTORE_API_KEY = '.$remotestore->dolistore_api_key;
// Add basic auth if needed
$basicAuthLogin = getDolGlobalString('MAIN_MODULE_DOLISTORE_BASIC_LOGIN');
$basicAuthPassword = getDolGlobalString('MAIN_MODULE_DOLISTORE_BASIC_PASSWORD');
if ($basicAuthLogin) {
$messagetoadd .= '<br>Using basic auth login: base64('.$basicAuthLogin.':'.$basicAuthPassword.')';
}
print $remotestore->libStatus($remotestore->dolistoreApiStatus, 2, $messagetoadd);
}
@ -1334,19 +1336,21 @@ if ($mode == 'marketplace') {
print '<span class="opacitymedium">'.$langs->trans('DOLISTOREdescriptionLong').'</span><br><br>';
//$previouslink = $remotestore->get_previous_link();
//$nextlink = $remotestore->get_next_link();
$categories_tree = $remotestore->getCategories(); // Call API to get the categories
$categories_tree = $remotestore->getCategories();
$products_list = $remotestore->getProducts($options);
$previouslink = $remotestore->get_previous_link();
$nextlink = $remotestore->get_next_link();
print '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
print '<form method="POST" class="centpercent" id="searchFormList" action="'.$remotestore->url.'">'; ?>
<input type="hidden" name="token" value="<?php echo newToken(); ?>">
<input type="hidden" name="mode" value="marketplace">
<input type="hidden" name="page_y" value="">
<div class="divsearchfield">
<input name="search_keyword" placeholder="<?php echo $langs->trans('Keyword') ?>" id="search_keyword" type="text" class="minwidth200" value="<?php echo dol_escape_htmltag($options['search']) ?>">
<!-- Add a check box to filter by source -->
@ -1369,8 +1373,8 @@ if ($mode == 'marketplace') {
</div>
<div class="divsearchfield">
<input class="button buttongen" value="<?php echo $langs->trans('Rechercher') ?>" type="submit">
<a class="buttonreset" href="<?php echo $_SERVER["PHP_SELF"].'?mode=marketplace'; ?>"><?php echo $langs->trans('Reset') ?></a>
<input class="button buttongen reposition" value="<?php echo $langs->trans('Rechercher') ?>" type="submit">
<a class="buttonreset reposition" href="<?php echo $_SERVER["PHP_SELF"].'?mode=marketplace'; ?>"><?php echo $langs->trans('Reset') ?></a>
&nbsp;
</div>

View file

@ -120,14 +120,13 @@ class ExternalModules
{
global $langs;
$this->dolistore_api_url = getDolGlobalString('MAIN_MODULE_DOLISTORE_API_SRV');
$this->dolistore_api_key = getDolGlobalString('MAIN_MODULE_DOLISTORE_API_KEY');
$this->url = DOL_URL_ROOT.'/admin/modules.php?mode=marketplace';
$this->shop_url = 'https://www.dolistore.com/product.php?id=';
$this->dolistore_api_url = getDolGlobalString('MAIN_MODULE_DOLISTORE_API_SRV', 'https://admin2.dolibarr.org/api/index.php/marketplace');
$this->dolistore_api_key = getDolGlobalString('MAIN_MODULE_DOLISTORE_API_KEY', 'dolistorepublicapi');
$this->shop_url = getDolGlobalString('MAIN_MODULE_DOLISTORE_SHOP_URL', 'https://www.dolistore.com');
$this->debug_api = $debug;
$this->url = DOL_URL_ROOT.'/admin/modules.php?mode=marketplace';
$this->file_source_url = "https://raw.githubusercontent.com/Dolibarr/dolibarr-community-modules/refs/heads/main/index.yaml";
$this->cache_file = DOL_DATA_ROOT.'/admin/temp/remote_github_modules_file.yaml';
@ -190,13 +189,16 @@ class ExternalModules
if ($options) {
$url .= '?' . http_build_query($options);
}
$response = getURLContent($url, 'POST', '', 1, $httpheader);
$body = $response['content'];
$body = json_decode($body, true);
$url .= (preg_match('/\?/', $url) ? '&' : '?').'apikey='.$this->dolistore_api_key;
$response = getURLContent($url, 'GET', '', 1, $httpheader);
$status_code = $response['http_code'];
$body = 'Error';
if ($status_code == 200) {
$body = $response['content'];
$body = json_decode($body, true);
}
return array('status_code' => $status_code, 'response' => $body);
}
@ -300,6 +302,7 @@ class ExternalModules
$dolistoreProducts = array();
if ($this->dolistoreApiStatus > 0 && $options['search_source_dolistore'] == 1) {
$getDolistoreProducts = $this->callApi('products', $data);
if (!isset($getDolistoreProducts['response']) || !is_array($getDolistoreProducts['response']) || ($getDolistoreProducts['status_code'] != 200 && $getDolistoreProducts['status_code'] != 201)) {
$dolistoreProducts = array();
} else {
@ -311,7 +314,9 @@ class ExternalModules
$fileProducts = array();
if (!empty($this->githubFileStatus) && $options['search_source_github'] == 1) {
$fileProducts = $this->fetchModulesFromFile($data); // Return an array with all modules from the cache filecontent in $data
$fileProducts = $this->adaptData($fileProducts, 'githubcommunity');
$fileProducts = $this->applyFilters($fileProducts, $data);
}
@ -359,7 +364,7 @@ class ExternalModules
// free or pay ?
if ($product["price_ttc"] > 0) {
$price = '<h3>'.price(price2num($product["price_ttc"], 'MT'), 0, $langs, 1, -1, -1, 'EUR').' '.$langs->trans("TTC").'</h3>';
$download_link = '<a target="_blank" href="'.$this->shop_url.urlencode($product['id']).'"><img width="32" src="'.DOL_URL_ROOT.'/admin/remotestore/img/follow.png" /></a>';
$download_link = '<a target="_blank" href="'.$this->shop_url.'/product.php?id='.((int) $product['id']).'"><img width="32" src="'.DOL_URL_ROOT.'/admin/remotestore/img/follow.png" /></a>';
} else {
$download_link = '#';
$price = '<h3>'.$langs->trans('Free').'</h3>';
@ -377,7 +382,7 @@ class ExternalModules
}
if ($product['source'] === 'dolistore') {
$download_link = '<a class="paddingleft paddingright" target="_blank" href="'.$this->shop_url.urlencode($product["id"]).'"><img width="32" src="'.DOL_URL_ROOT.'/admin/remotestore/img/follow.png" /></a>';
$download_link = '<a class="paddingleft paddingright" target="_blank" href="'.$this->shop_url.'/product.php?id='.((int) $product["id"]).'"><img width="32" src="'.DOL_URL_ROOT.'/admin/remotestore/img/follow.png" /></a>';
if (!empty($product['direct-download']) && $product['direct-download'] == 'yes') {
$download_link .= '<a class="paddingleft paddingright" target="_blank" href="'.$product["download_link"].'" rel="noopener noreferrer"><img width="32" src="'.DOL_URL_ROOT.'/admin/remotestore/img/Download-128.png" /></a>';
}
@ -747,7 +752,6 @@ class ExternalModules
public function adaptData($data, $source)
{
$adaptedData = [];
$urldolibarrmodules = 'https://www.dolistore.com';
if (!is_array($data) || empty($data) || empty($source)) {
return $adaptedData;
@ -825,7 +829,7 @@ class ExternalModules
'phpmin' => $package['phpmin'],
'phpmax' => $package['phpmax'],
'module_version' => $package['module_version'],
'cover_photo_url' => $urldolibarrmodules.$package['cover_photo_url'],
'cover_photo_url' => $this->shop_url.$package['cover_photo_url'],
'source' => 'dolistore'
];