App\services\ImportService::execute PHP Method

execute() private method

private execute ( $source, $entityType, $file ) : array
$source
$entityType
$file
return array
    private function execute($source, $entityType, $file)
    {
        $results = [RESULT_SUCCESS => [], RESULT_FAILURE => []];
        // Convert the data
        $row_list = [];
        Excel::load($file, function ($reader) use($source, $entityType, &$row_list, &$results) {
            $this->checkData($entityType, count($reader->all()));
            $reader->each(function ($row) use($source, $entityType, &$row_list, &$results) {
                $data_index = $this->transformRow($source, $entityType, $row);
                if ($data_index !== false) {
                    if ($data_index !== true) {
                        // Wasn't merged with another row
                        $row_list[] = ['row' => $row, 'data_index' => $data_index];
                    }
                } else {
                    $results[RESULT_FAILURE][] = $row;
                }
            });
        });
        // Save the data
        foreach ($row_list as $row_data) {
            $result = $this->saveData($source, $entityType, $row_data['row'], $row_data['data_index']);
            if ($result) {
                $results[RESULT_SUCCESS][] = $result;
            } else {
                $results[RESULT_FAILURE][] = $row_data['row'];
            }
        }
        return $results;
    }