Browse Source

Rename functions and options from 'csv' to 'file'

pull/92/head
James Cole 4 years ago
parent
commit
4d48f14fb4
No known key found for this signature in database GPG Key ID: B49A324B7EAD6D80
  1. 2
      app/Console/AutoImports.php
  2. 2
      app/Console/Commands/Import.php
  3. 2
      app/Http/Controllers/Import/CSV/RoleController.php
  4. 6
      app/Http/Controllers/Import/ConversionController.php
  5. 10
      app/Http/Controllers/Import/MapController.php
  6. 8
      app/Http/Controllers/Import/UploadController.php
  7. 24
      app/Http/Middleware/IsReadyForStep.php
  8. 2
      app/Http/Request/ConfigurationPostRequest.php
  9. 20
      app/Services/Shared/Configuration/Configuration.php

2
app/Console/AutoImports.php

@ -185,7 +185,7 @@ trait AutoImports
$configuration = Configuration::fromArray(json_decode(file_get_contents($jsonFile), true));
// sanity check. If the csvFile is a .json file and it parses as valid json, don't import it:
if ('csv' === $configuration->getFlow() && str_ends_with(strtolower($csvFile), '.json') && $this->verifyJSON($csvFile)) {
if ('file' === $configuration->getFlow() && str_ends_with(strtolower($csvFile), '.json') && $this->verifyJSON($csvFile)) {
app('log')->warning('Almost tried to import a JSON file as CSV lol. Skip it.');
return;
}

2
app/Console/Commands/Import.php

@ -108,7 +108,7 @@ class Import extends Command
return 1;
}
$configuration = Configuration::fromArray(json_decode(file_get_contents($config), true));
if ('csv' === $configuration->getFlow() && (!file_exists($file) || (file_exists($file) && !is_file($file)))) {
if ('file' === $configuration->getFlow() && (!file_exists($file) || (file_exists($file) && !is_file($file)))) {
$message = sprintf('The importer can\'t import: CSV file "%s" does not exist or could not be read.', $file);
$this->error($message);
app('log')->error($message);

2
app/Http/Controllers/Import/CSV/RoleController.php

@ -74,7 +74,7 @@ class RoleController extends Controller
{
app('log')->debug('Now in role controller');
$flow = $request->cookie(Constants::FLOW_COOKIE);
if ('csv' !== $flow) {
if ('file' !== $flow) {
die('redirect or something');
}
$mainTitle = 'Role definition';

6
app/Http/Controllers/Import/ConversionController.php

@ -74,7 +74,7 @@ class ConversionController extends Controller
app('log')->debug('Will now verify configuration content.');
$jobBackUrl = route('back.mapping');
if (empty($configuration->getDoMapping()) && 'csv' === $configuration->getFlow()) {
if (empty($configuration->getDoMapping()) && 'file' === $configuration->getFlow()) {
// no mapping, back to roles
app('log')->debug('Pressing "back" will send you to roles.');
$jobBackUrl = route('back.roles');
@ -100,7 +100,7 @@ class ConversionController extends Controller
throw new ImporterErrorException(sprintf('Not a supported flow: "%s"', $flow));
}
/** @var RoutineManagerInterface $routine */
if ('csv' === $flow) {
if ('file' === $flow) {
app('log')->debug('Create CSV routine manager.');
$routine = new CSVRoutineManager($identifier);
}
@ -147,7 +147,7 @@ class ConversionController extends Controller
throw new ImporterErrorException(sprintf('Not a supported flow: "%s"', $flow));
}
/** @var RoutineManagerInterface $routine */
if ('csv' === $flow) {
if ('file' === $flow) {
$routine = new CSVRoutineManager($identifier);
}
if ('nordigen' === $flow) {

10
app/Http/Controllers/Import/MapController.php

@ -78,14 +78,14 @@ class MapController extends Controller
$data = [];
$roles = [];
if ('csv' === $configuration->getFlow()) {
if ('file' === $configuration->getFlow()) {
app('log')->debug('Get mapping data for CSV');
$roles = $configuration->getRoles();
$data = $this->getCSVMapInformation();
}
// nordigen, spectre and others:
if ('csv' !== $configuration->getFlow()) {
if ('file' !== $configuration->getFlow()) {
app('log')->debug('Get mapping data for nordigen and spectre');
$roles = [];
$data = $this->getImporterMapInformation();
@ -96,9 +96,9 @@ class MapController extends Controller
// set map config as complete.
session()->put(Constants::MAPPING_COMPLETE_INDICATOR, true);
// if CSV, now ready for conversion
if ('csv' === $configuration->getFlow()) {
app('log')->debug('Its CSV, also set ready for conversion.');
// if file, now ready for conversion
if ('file' === $configuration->getFlow()) {
app('log')->debug('Its a file, also set ready for conversion.');
session()->put(Constants::READY_FOR_CONVERSION, true);
}
return redirect()->route('007-convert.index');

8
app/Http/Controllers/Import/UploadController.php

@ -138,14 +138,14 @@ class UploadController extends Controller
*/
private function processCsvFile(string $flow, MessageBag $errors, UploadedFile|null $file): MessageBag
{
if (null === $file && 'csv' === $flow) {
$errors->add('csv_file', 'No file was uploaded.');
if (null === $file && 'file' === $flow) {
$errors->add('importable_file', 'No file was uploaded.');
return $errors;
}
if ('csv' === $flow) {
if ('file' === $flow) {
$errorNumber = $file->getError();
if (0 !== $errorNumber) {
$errors->add('csv_file', $this->getError($errorNumber));
$errors->add('importable_file', $this->getError($errorNumber));
}

24
app/Http/Middleware/IsReadyForStep.php

@ -73,9 +73,9 @@ trait IsReadyForStep
app('log')->debug('isReadyForStep returns true because $flow is null');
return true;
}
if ('csv' === $flow) {
$result = $this->isReadyForCSVStep();
app('log')->debug(sprintf('isReadyForCSVStep: Return %s', var_export($result, true)));
if ('file' === $flow) {
$result = $this->isReadyForFileStep();
app('log')->debug(sprintf('isReadyForFileStep: Return %s', var_export($result, true)));
return $result;
}
if ('nordigen' === $flow) {
@ -97,12 +97,12 @@ trait IsReadyForStep
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
private function isReadyForCSVStep(): bool
private function isReadyForFileStep(): bool
{
app('log')->debug(sprintf('isReadyForCSVStep("%s")', self::STEP));
app('log')->debug(sprintf('isReadyForFileStep("%s")', self::STEP));
switch (self::STEP) {
default:
throw new ImporterErrorException(sprintf('isReadyForCSVStep: Cannot handle CSV step "%s"', self::STEP));
throw new ImporterErrorException(sprintf('isReadyForFileStep: Cannot handle file step "%s"', self::STEP));
case 'service-validation':
return true;
case 'upload-files':
@ -111,7 +111,7 @@ trait IsReadyForStep
}
return true;
case 'authenticate':
// for CSV this is always false.
// for files this is always false.
return false;
case 'define-roles':
if (session()->has(Constants::ROLES_COMPLETE_INDICATOR) && true === session()->get(Constants::ROLES_COMPLETE_INDICATOR)) {
@ -325,8 +325,8 @@ trait IsReadyForStep
app('log')->debug('redirectToCorrectStep returns true because $flow is null');
return null;
}
if ('csv' === $flow) {
return $this->redirectToCorrectCSVStep();
if ('file' === $flow) {
return $this->redirectToCorrectFileStep();
}
if ('nordigen' === $flow) {
return $this->redirectToCorrectNordigenStep();
@ -341,12 +341,12 @@ trait IsReadyForStep
* @return RedirectResponse
* @throws ImporterErrorException
*/
private function redirectToCorrectCSVStep(): RedirectResponse
private function redirectToCorrectFileStep(): RedirectResponse
{
app('log')->debug(sprintf('redirectToCorrectCSVStep("%s")', self::STEP));
app('log')->debug(sprintf('redirectToCorrectFileStep("%s")', self::STEP));
switch (self::STEP) {
default:
throw new ImporterErrorException(sprintf('redirectToCorrectCSVStep: Cannot handle CSV step "%s"', self::STEP));
throw new ImporterErrorException(sprintf('redirectToCorrectFileStep: Cannot handle file step "%s"', self::STEP));
case 'upload-files':
$route = route('004-configure.index');
app('log')->debug(sprintf('Return redirect to "%s"', $route));

2
app/Http/Request/ConfigurationPostRequest.php

@ -143,7 +143,7 @@ class ConfigurationPostRequest extends Request
$flow = request()->cookie(Constants::FLOW_COOKIE);
$data = $validator->getData();
$doImport = $data['do_import'] ?? [];
if (0 === count($doImport) && 'csv' !== $flow) {
if (0 === count($doImport) && 'file' !== $flow) {
$validator->errors()->add('do_import', 'You must select at least one account to import from.');
}
}

20
app/Services/Shared/Configuration/Configuration.php

@ -104,7 +104,7 @@ class Configuration
$this->roles = [];
$this->mapping = [];
$this->doMapping = [];
$this->flow = 'csv';
$this->flow = 'file';
// date range settings
$this->dateRange = 'all';
@ -219,7 +219,7 @@ class Configuration
$object->conversion = $array['conversion'] ?? false;
// flow
$object->flow = $array['flow'] ?? 'csv';
$object->flow = $array['flow'] ?? 'file';
// overrule a setting:
if ('none' === $object->duplicateDetectionMethod) {
@ -232,6 +232,9 @@ class Configuration
$object->specifics[] = $key;
}
}
if('csv' === $object->flow) {
$object->flow = 'file';
}
return $object;
}
@ -279,7 +282,7 @@ class Configuration
$object->delimiter = $delimiters[$data['delimiter']] ?? 'comma';
$object->defaultAccount = $data['import-account'] ?? $object->defaultAccount;
$object->rules = $data['apply-rules'] ?? true;
$object->flow = $data['flow'] ?? 'csv';
$object->flow = $data['flow'] ?? 'file';
// other settings (are not in v1 anyway)
$object->dateRange = $data['date_range'] ?? 'all';
@ -367,6 +370,10 @@ class Configuration
// set version to latest version and return.
$object->version = self::VERSION;
if('csv' === $object->flow) {
$object->flow = 'file';
}
return $object;
}
@ -400,7 +407,7 @@ class Configuration
$object->mapping = $array['mapping'] ?? [];
$object->doMapping = $array['do_mapping'] ?? [];
$object->version = self::VERSION;
$object->flow = $array['flow'] ?? 'csv';
$object->flow = $array['flow'] ?? 'file';
// sort
ksort($object->doMapping);
@ -456,6 +463,10 @@ class Configuration
// utf8
$object->conversion = $array['conversion'] ?? false;
if('csv' === $object->flow) {
$object->flow = 'file';
}
return $object;
}
@ -561,7 +572,6 @@ class Configuration
'mapping' => $this->mapping,
'duplicate_detection_method' => $this->duplicateDetectionMethod,
'ignore_duplicate_lines' => $this->ignoreDuplicateLines,
'ignore_duplicate_transactions' => $this->ignoreDuplicateTransactions,
'unique_column_index' => $this->uniqueColumnIndex,
'unique_column_type' => $this->uniqueColumnType,
'flow' => $this->flow,

Loading…
Cancel
Save