cobwebch / external_import

Other
20 stars 16 forks source link

Import 2 different CSV in one Table #345

Open marexx opened 1 month ago

marexx commented 1 month ago

HI, I need to import 2 different CSVs in 1 Table. My setting is to import it, in 2 different Steps.

Step1: From the FILE1 I import 2 Values Field1 and Field2

Step2: In FILE2 i have 2 Values Field1 and title

No i need to import the title from File2 to the entry with the value of Field1 (is unique).

fsuter commented 1 month ago

Hi. You need to have 2 configurations, one for each file and set priorities to that the second file is handled after the first one. Also, you need to disable "insert" and "delete" operations in the second configuration, because all it should do is update existing records with the title field.

marexx commented 1 month ago

yes, i thought, this is, what i did with the above config. But how do i make sure that the title is set in the correct entry?

fsuter commented 1 month ago

Ah yes, I see the two configurations now. It was hard to read, because the code was not formatted. From what I see, it looks ok, but without seeing the whole configuration (i.e. including columns) and without knowing how the data is structured in each of the files, it is impossible to say what is going wrong.

marexx commented 1 month ago
<?php
defined('TYPO3') or die();
// Add the external information to the ctrl section
$GLOBALS['TCA']['tx_arzneimittelsuche_domain_model_arzneimittel']['external']['general'] = [
    0 => [
        'connector' => 'csv',
        'parameters' => [
            'filename' => 'fileadmin/user_upload/arzneimittelsuche/import_small.csv',
            //'filename' => 'fileadmin/Kundenstamm1.csv',
            'delimiter' => ";",
            'text_qualifier' => '"',
            'skip_rows' => 1,
            'encoding' => 'latin1'
        ],
        'customSteps' => [
            [
                'class' => \Securvita\Arzneimittelsuche\Step\FilterWebsiteProducts::class,
                'position' => 'after:' . \Cobweb\ExternalImport\Step\ReadDataStep::class
            ]
        ],
        'enforcePid' => true,
        'data' => 'array',
        'referenceUid' => 'pzn',
        'priority' => 10,
        //'clearCache' => 5,28,29,
        'pid' => 534,
        'group' => 'arzneimittelsuche',
        'description' => 'Importiere Medikamente'
    ],
    1 => [
        'connector' => 'csv',
        'parameters' => [
            'filename' => 'fileadmin/user_upload/arzneimittelsuche/import_name.csv',
            'delimiter' => ";",
            'text_qualifier' => '"',
            'skip_rows' => 1,
            'encoding' => 'latin1'
        ],
        'enforcePid' => true,
        'data' => 'array',
        'referenceUid' => 'atccodewho',
        'priority' => 20,
        //'clearCache' => 5,28,29,
        'pid' => 534,
        'group' => 'arzneimittelsuche',
        'disabledOperations' => 'insert,delete',

        'description' => 'Importiere Medikamentennamen'
    ]
];

$GLOBALS['TCA']['tx_arzneimittelsuche_domain_model_arzneimittel']['columns']['atccodewho']['external'] = [
    0 => [
        'field' => 'ATCCodeADV',
    ]
];

$GLOBALS['TCA']['tx_arzneimittelsuche_domain_model_arzneimittel']['columns']['pzn']['external'] = [
    0 => [
        'field' => 'PZN',
    ]
];

$GLOBALS['TCA']['tx_arzneimittelsuche_domain_model_arzneimittel']['columns']['title']['external'] = [
    1 => [
        'field' => 'Bezeichnung',
    ]
];
marexx commented 1 month ago

the import_name.csv looks like this:

`AtcCode;ParentAtcCode;Bezeichnung
A;;Alimentäres System und Stoffwechsel
A01;A;Stomatologika`
marexx commented 1 month ago

import_small.csv has more columns but as you see i import just a few. Thats already working. i'm just missing the step to add the title

fsuter commented 1 month ago

Much clearer now, thanks.

What you are missing is importing the "AtcCode" in the second configuration. The field designated in the "referenceUid" property must be imported, otherwise it is not available to be matched.

marexx commented 1 month ago

thanx, that was the solution.!!

One more Question, the complete file has about 100MB, is it possible, to loop over this file, to split the import steps?

fsuter commented 1 month ago

No, this is not possible. It has been sometimes requested in the past, but it is a huge conceptual change.