mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 13:54:34 -04:00
Fixes for string delimiters
This commit is contained in:
parent
67c34f80a9
commit
84885837ab
@ -170,20 +170,27 @@ 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 = ' ';
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user