Browse Source

Clean code for #19639

Laurent Destailleur 3 years ago
parent
commit
626cd24305

+ 2 - 0
htdocs/api/class/api.class.php

@@ -110,6 +110,8 @@ class DolibarrApi
 		unset($object->ismultientitymanaged);
 		unset($object->restrictiononfksoc);
 		unset($object->table_rowid);
+		unset($object->pass);
+		unset($object->pass_indatabase);
 
 		// Remove linkedObjects. We should already have linkedObjectsIds that avoid huge responses
 		unset($object->linkedObjects);

+ 24 - 2
htdocs/api/index.php

@@ -343,14 +343,32 @@ if (!empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' &&
 //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.
-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).
 // 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();
 
 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')) {
 		header('Content-Encoding: br');
 		$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')) {
 		header('Content-Encoding: gzip');
 		$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

+ 3 - 3
htdocs/core/class/html.formother.class.php

@@ -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>
 	 *
-	 * @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)
 	 * @return	string						HTML component
 	 */
@@ -72,7 +72,7 @@ class FormOther
 
 		$out .= '<!-- Popup for mass barcode scanning -->'."\n";
 		$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') {
 			$out .= '<input type="hidden" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct">';

+ 14 - 3
htdocs/product/inventory/inventory.php

@@ -606,12 +606,14 @@ if ($object->id > 0) {
 	// Popup for mass barcode scanning
 	if ($action == 'updatebyscaning') {
 		if ($permissiontoadd) {
+			// Output the javascript to manage the scanner tool.
 			print '<script>';
 
 			print '
 			var errortab1 = [];
 			var errortab2 = [];
 			var errortab3 = [];
+			var errortab4 = [];
 
 			function barcodescannerjs(){
 				console.log("We catch inputs in scanner box");
@@ -626,6 +628,7 @@ if ($object->id > 0) {
 				errortab1 = [];
 				errortab2 = [];
 				errortab3 = [];
+				errortab4 = [];
 
 				if(textarray[0] != ""){
 					$(".expectedqty").each(function(){
@@ -734,6 +737,13 @@ if ($object->id > 0) {
 							});
 							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);
 						//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){
 				BarcodeIsInProduct=0;
 				newproductrow=0
@@ -753,14 +764,14 @@ if ($object->id > 0) {
 						async: false,
 						success: function(response) {
 							response = JSON.parse(response);
-							if(response.status == "success"){
+							if (response.status == "success"){
 								console.log(response.message);
 								if(!newproductrow){
 									newproductrow = response.object;
 								}
 							}else{
-								if (mode!="lotserial" && autodetect==false && !errortab.includes(element)){
-									errortab.push(element);
+								if (mode!="lotserial" && autodetect==false && !errortab4.includes(element)){
+									errortab4.push(element);
 									console.error(response.message);
 								}
 							}