1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Fixes for string delimiters

This commit is contained in:
David Bomba 2023-07-26 14:44:39 +10:00
parent 67c34f80a9
commit 84885837ab
2 changed files with 13 additions and 5 deletions

View File

@ -170,7 +170,13 @@ class ImportController extends Controller
return $data; return $data;
} }
public function detectDelimiter($csvfile) /**
* Returns the best delimiter
*
* @param string $csvfile
* @return string
*/
public function detectDelimiter($csvfile): string
{ {
$delimiters = [',', '.', ';']; $delimiters = [',', '.', ';'];
$bestDelimiter = ' '; $bestDelimiter = ' ';
@ -179,11 +185,12 @@ class ImportController extends Controller
foreach ($delimiters as $delimiter) { foreach ($delimiters as $delimiter) {
if (substr_count(strstr($csvfile, "\n", true), $delimiter) >= $count) { if (substr_count(strstr($csvfile, "\n", true), $delimiter) >= $count) {
$count = substr_count($csvfile, $delimiter); $count = substr_count(strstr($csvfile, "\n", true), $delimiter);
$bestDelimiter = $delimiter; $bestDelimiter = $delimiter;
} }
} }
return $bestDelimiter; return $bestDelimiter;
} }
} }

View File

@ -28,9 +28,10 @@ class PreImportRequest extends Request
public function rules() public function rules()
{ {
return [ return [
'files.*' => 'file|mimes:csv,txt', 'files.*' => 'file|mimetypes:text/csv,text/plain,application/octet-stream',
'files' => 'required|array|min:1|max:6', 'files' => 'required|array|min:1|max:6',
'import_type' => 'required', 'import_type' => 'required',
]; ];
} }
} }