Support nodelist archives with more than 1 file in it
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
use App\Models\File;
|
||||
@@ -19,39 +18,24 @@ trait Import
|
||||
* Count the lines in a file
|
||||
* Assumes $file is compressed with ZIP
|
||||
*/
|
||||
private function getFileLines(string $file): int
|
||||
private function getFileLines(mixed $f): int
|
||||
{
|
||||
$c = 0;
|
||||
|
||||
$f = NULL;
|
||||
$z = $this->openFile($file,$f);
|
||||
|
||||
while (! feof($f)) {
|
||||
fgets($f);
|
||||
$c++;
|
||||
}
|
||||
|
||||
fclose($f);
|
||||
|
||||
return $c;
|
||||
}
|
||||
|
||||
private function openFile(string $file,&$f): \ZipArchive
|
||||
private function openFile(string $file): \ZipArchive
|
||||
{
|
||||
$z = new \ZipArchive;
|
||||
|
||||
if ($z->open($file,\ZipArchive::RDONLY) === TRUE) {
|
||||
if ($z->count() !== 1)
|
||||
throw new \Exception(sprintf('%s:! File [%s] has more than 1 file (%d)', self::LOGKEY, $file, $z->count()));
|
||||
|
||||
$zipfile = $z->statIndex(0, \ZipArchive::FL_UNCHANGED);
|
||||
Log::debug(sprintf('%s:- Looking at [%s] in archive [%s]', self::LOGKEY,$zipfile['name'],$file));
|
||||
|
||||
$f = $z->getStream($zipfile['name']);
|
||||
if (! $f)
|
||||
throw new \Exception(sprintf('%s:! Failed getting ZipArchive::stream (%s)',self::LOGKEY,$z->getStatusString()));
|
||||
else
|
||||
return $z;
|
||||
return $z;
|
||||
|
||||
} else {
|
||||
throw new \Exception(sprintf('%s:! Failed opening ZipArchive [%s] (%s)',self::LOGKEY,$file,$z->getStatusString()));
|
||||
|
Reference in New Issue
Block a user