1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Working on import

This commit is contained in:
Hillel Coren 2017-04-02 18:10:24 +03:00
parent 7a13d93082
commit 6e4d3536dc
3 changed files with 40 additions and 14 deletions

View File

@ -22,6 +22,10 @@ class ImportController extends BaseController
public function doImport(Request $request)
{
if (! Auth::user()->confirmed) {
return redirect('/settings/' . ACCOUNT_IMPORT_EXPORT)->withError(trans('texts.confirm_account_to_import'));
}
$source = Input::get('source');
$files = [];
$timestamp = time();

View File

@ -148,8 +148,9 @@ class ImportService
public function importJSON($file, $includeData, $includeSettings)
{
$this->initMaps();
$file = file_get_contents(storage_path() . '/import/' . $file);
$fileName = storage_path() . '/import/' . $file;
$this->checkForFile($fileName);
$file = file_get_contents($fileName);
$json = json_decode($file, true);
$json = $this->removeIdFields($json);
$transformer = new BaseTransformer($this->maps);
@ -166,7 +167,7 @@ class ImportService
$settings[$field] = $value;
}
}
//dd($settings);
$account = Auth::user()->account;
$account->fill($settings);
$account->save();
@ -228,6 +229,8 @@ class ImportService
}
}
unlink($fileName);
return $this->results;
}
@ -284,9 +287,10 @@ class ImportService
// Convert the data
$row_list = [];
$file = storage_path() . '/import/' . $file;
$fileName = storage_path() . '/import/' . $file;
$this->checkForFile($fileName);
Excel::load($file, function ($reader) use ($source, $entityType, &$row_list, &$results) {
Excel::load($fileName, function ($reader) use ($source, $entityType, &$row_list, &$results) {
$this->checkData($entityType, count($reader->all()));
$reader->each(function ($row) use ($source, $entityType, &$row_list, &$results) {
@ -317,6 +321,8 @@ class ImportService
}
}
unlink($fileName);
return $results;
}
@ -568,8 +574,6 @@ class ImportService
}
}
//Session::put("{$entityType}-data", $csv->data);
$data = [
'entityType' => $entityType,
'data' => $data,
@ -582,12 +586,16 @@ class ImportService
return $data;
}
private function getCsvData($filename)
private function getCsvData($fileName)
{
require_once app_path().'/Includes/parsecsv.lib.php';
$fileName = storage_path() . '/import/' . $fileName;
$this->checkForFile($fileName);
$csv = new parseCSV();
$csv->heading = false;
$csv->auto(storage_path() . '/import/' . $filename);
$csv->auto($fileName);
$data = $csv->data;
if (count($data) > 0) {
@ -678,9 +686,8 @@ class ImportService
];
$source = IMPORT_CSV;
//$data = Session::get("{$entityType}-data");
$filename = sprintf('%s_%s_%s.csv', Auth::user()->account_id, $timestamp, $entityType);
$data = $this->getCsvData($filename);
$fileName = sprintf('%s_%s_%s.csv', Auth::user()->account_id, $timestamp, $entityType);
$data = $this->getCsvData($fileName);
$this->checkData($entityType, count($data));
$this->initMaps();
@ -719,7 +726,7 @@ class ImportService
}
}
//Session::forget("{$entityType}-data");
unlink($fileName);
return $results;
}
@ -934,4 +941,19 @@ class ImportService
return $message;
}
private function checkForFile($fileName)
{
$counter = 0;
while (! file_exists($fileName)) {
$counter++;
if ($counter > 60) {
throw new Exception('File not found: ' . $fileName);
}
sleep(2);
}
return true;
}
}

View File

@ -2461,7 +2461,7 @@ $LANG = array(
'reply_to_email_help' => 'Specify the reply-to address for client emails.',
'bcc_email_help' => 'Privately include this address with client emails.',
'import_complete' => 'Your import has successfully completed.',
'confirm_account_to_import' => 'Please confirm your account to import data.',
);