Clean code for #19639
This commit is contained in:
parent
ee3246bf65
commit
626cd24305
@ -110,6 +110,8 @@ class DolibarrApi
|
|||||||
unset($object->ismultientitymanaged);
|
unset($object->ismultientitymanaged);
|
||||||
unset($object->restrictiononfksoc);
|
unset($object->restrictiononfksoc);
|
||||||
unset($object->table_rowid);
|
unset($object->table_rowid);
|
||||||
|
unset($object->pass);
|
||||||
|
unset($object->pass_indatabase);
|
||||||
|
|
||||||
// Remove linkedObjects. We should already have linkedObjectsIds that avoid huge responses
|
// Remove linkedObjects. We should already have linkedObjectsIds that avoid huge responses
|
||||||
unset($object->linkedObjects);
|
unset($object->linkedObjects);
|
||||||
|
|||||||
@ -343,14 +343,32 @@ if (!empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' &&
|
|||||||
//exit;
|
//exit;
|
||||||
|
|
||||||
// We do not want that restler outputs data if we use native compression (default behaviour) but we want to have it returned into a string.
|
// We do not want that restler outputs data if we use native compression (default behaviour) but we want to have it returned into a string.
|
||||||
Luracast\Restler\Defaults::$returnResponse = (empty($conf->global->API_DISABLE_COMPRESSION) && !empty($_SERVER['HTTP_ACCEPT_ENCODING']));
|
// If API_DISABLE_COMPRESSION is set, returnResponse is false => It use default handling so output result directly.
|
||||||
|
$usecompression = (empty($conf->global->API_DISABLE_COMPRESSION) && !empty($_SERVER['HTTP_ACCEPT_ENCODING']));
|
||||||
|
$foundonealgorithm = 0;
|
||||||
|
if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'br') !== false && is_callable('brotli_compress')) {
|
||||||
|
$foundonealgorithm++;
|
||||||
|
}
|
||||||
|
if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'bz') !== false && is_callable('bzcompress')) {
|
||||||
|
$foundonealgorithm++;
|
||||||
|
}
|
||||||
|
if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false && is_callable('gzencode')) {
|
||||||
|
$foundonealgorithm++;
|
||||||
|
}
|
||||||
|
if (!$foundonealgorithm) {
|
||||||
|
$usecompression = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//dol_syslog('We found some compression algoithm: '.$foundonealgorithm.' -> usecompression='.$usecompression, LOG_DEBUG);
|
||||||
|
|
||||||
|
Luracast\Restler\Defaults::$returnResponse = $usecompression;
|
||||||
|
|
||||||
// Call API (we suppose we found it).
|
// Call API (we suppose we found it).
|
||||||
// The handle will use the file api/temp/routes.php to get data to run the API. If the file exists and the entry for API is not found, it will return 404.
|
// The handle will use the file api/temp/routes.php to get data to run the API. If the file exists and the entry for API is not found, it will return 404.
|
||||||
$result = $api->r->handle();
|
$result = $api->r->handle();
|
||||||
|
|
||||||
if (Luracast\Restler\Defaults::$returnResponse) {
|
if (Luracast\Restler\Defaults::$returnResponse) {
|
||||||
// We try to compress data
|
// We try to compress the data received data
|
||||||
if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'br') !== false && is_callable('brotli_compress')) {
|
if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'br') !== false && is_callable('brotli_compress')) {
|
||||||
header('Content-Encoding: br');
|
header('Content-Encoding: br');
|
||||||
$result = brotli_compress($result, 11, BROTLI_TEXT);
|
$result = brotli_compress($result, 11, BROTLI_TEXT);
|
||||||
@ -360,6 +378,10 @@ if (Luracast\Restler\Defaults::$returnResponse) {
|
|||||||
} elseif (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false && is_callable('gzencode')) {
|
} elseif (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false && is_callable('gzencode')) {
|
||||||
header('Content-Encoding: gzip');
|
header('Content-Encoding: gzip');
|
||||||
$result = gzencode($result, 9);
|
$result = gzencode($result, 9);
|
||||||
|
} else {
|
||||||
|
header('Content-Encoding: text/html');
|
||||||
|
print "No compression method found. Try to disable compression by adding API_DISABLE_COMPRESSION=1";
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restler did not output data yet, we return it now
|
// Restler did not output data yet, we return it now
|
||||||
|
|||||||
@ -57,10 +57,10 @@ class FormOther
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return HTML code for scanner tool.
|
* Return the HTML code for scanner tool.
|
||||||
* This must be called into an existing <form>
|
* This must be called into an existing <form>
|
||||||
*
|
*
|
||||||
* @param string $jstoexecuteonadd Name of javascript function to call
|
* @param string $jstoexecuteonadd Name of javascript function to call once the barcode scanning session is complete and user has click on "Add".
|
||||||
* @param string $mode 'all' (both product and lot barcode) or 'product' (product barcode only) or 'lot' (lot number only)
|
* @param string $mode 'all' (both product and lot barcode) or 'product' (product barcode only) or 'lot' (lot number only)
|
||||||
* @return string HTML component
|
* @return string HTML component
|
||||||
*/
|
*/
|
||||||
@ -72,7 +72,7 @@ class FormOther
|
|||||||
|
|
||||||
$out .= '<!-- Popup for mass barcode scanning -->'."\n";
|
$out .= '<!-- Popup for mass barcode scanning -->'."\n";
|
||||||
$out .= '<div class="div-for-modal-topright" style="padding: 15px">';
|
$out .= '<div class="div-for-modal-topright" style="padding: 15px">';
|
||||||
$out .= '<center><strong>Barcode scanner tool...</strong></center><br>';
|
$out .= '<center>'.img_picto('', 'barcode', 'class="pictofixedwidth"').'<strong>Barcode scanner tool...</strong></center><br>';
|
||||||
|
|
||||||
if ($mode == 'product') {
|
if ($mode == 'product') {
|
||||||
$out .= '<input type="hidden" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct">';
|
$out .= '<input type="hidden" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct">';
|
||||||
|
|||||||
@ -606,12 +606,14 @@ if ($object->id > 0) {
|
|||||||
// Popup for mass barcode scanning
|
// Popup for mass barcode scanning
|
||||||
if ($action == 'updatebyscaning') {
|
if ($action == 'updatebyscaning') {
|
||||||
if ($permissiontoadd) {
|
if ($permissiontoadd) {
|
||||||
|
// Output the javascript to manage the scanner tool.
|
||||||
print '<script>';
|
print '<script>';
|
||||||
|
|
||||||
print '
|
print '
|
||||||
var errortab1 = [];
|
var errortab1 = [];
|
||||||
var errortab2 = [];
|
var errortab2 = [];
|
||||||
var errortab3 = [];
|
var errortab3 = [];
|
||||||
|
var errortab4 = [];
|
||||||
|
|
||||||
function barcodescannerjs(){
|
function barcodescannerjs(){
|
||||||
console.log("We catch inputs in scanner box");
|
console.log("We catch inputs in scanner box");
|
||||||
@ -626,6 +628,7 @@ if ($object->id > 0) {
|
|||||||
errortab1 = [];
|
errortab1 = [];
|
||||||
errortab2 = [];
|
errortab2 = [];
|
||||||
errortab3 = [];
|
errortab3 = [];
|
||||||
|
errortab4 = [];
|
||||||
|
|
||||||
if(textarray[0] != ""){
|
if(textarray[0] != ""){
|
||||||
$(".expectedqty").each(function(){
|
$(".expectedqty").each(function(){
|
||||||
@ -734,6 +737,13 @@ if ($object->id > 0) {
|
|||||||
});
|
});
|
||||||
stringerror = stringerror.slice(0, -2); /* Remove last ", " */
|
stringerror = stringerror.slice(0, -2); /* Remove last ", " */
|
||||||
}
|
}
|
||||||
|
if (Object.keys(errortab4).length > 0) {
|
||||||
|
stringerror += "<br>'.$langs->transnoentities('ErrorBarcodeNotFoundForProductWarehouse').': ";
|
||||||
|
errortab4.forEach(element => {
|
||||||
|
stringerror += (element + ", ")
|
||||||
|
});
|
||||||
|
stringerror = stringerror.slice(0, -2); /* Remove last ", " */
|
||||||
|
}
|
||||||
|
|
||||||
jQuery("#scantoolmessage").text("'.$langs->trans("ErrorOnElementsInventory").'\n" + stringerror);
|
jQuery("#scantoolmessage").text("'.$langs->trans("ErrorOnElementsInventory").'\n" + stringerror);
|
||||||
//alert("'.$langs->trans("ErrorOnElementsInventory").' :\n" + stringerror);
|
//alert("'.$langs->trans("ErrorOnElementsInventory").' :\n" + stringerror);
|
||||||
@ -742,6 +752,7 @@ if ($object->id > 0) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This methode is called by parent barcodescannerjs() */
|
||||||
function barcodeserialforproduct(tabproduct,index,element,barcodeproductqty,selectaddorreplace,mode,autodetect=false){
|
function barcodeserialforproduct(tabproduct,index,element,barcodeproductqty,selectaddorreplace,mode,autodetect=false){
|
||||||
BarcodeIsInProduct=0;
|
BarcodeIsInProduct=0;
|
||||||
newproductrow=0
|
newproductrow=0
|
||||||
@ -759,8 +770,8 @@ if ($object->id > 0) {
|
|||||||
newproductrow = response.object;
|
newproductrow = response.object;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if (mode!="lotserial" && autodetect==false && !errortab.includes(element)){
|
if (mode!="lotserial" && autodetect==false && !errortab4.includes(element)){
|
||||||
errortab.push(element);
|
errortab4.push(element);
|
||||||
console.error(response.message);
|
console.error(response.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user