Skip to content

Commit ab21bac

Browse files
Kocenjeck
authored andcommitted
Enhancement: Update rows via import (debug)
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
1 parent cebd055 commit ab21bac

4 files changed

Lines changed: 40 additions & 5 deletions

File tree

‎cypress/e2e/tables-import.cy.js‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,40 @@ describe('Import csv', () => {
6161
cy.get('[data-cy="importResultRowErrors"]').should('contain.text', '0')
6262
})
6363

64+
it('Import csv from device with updating of existent files', () => {
65+
cy.intercept({ method: 'GET', url: '**/apps/tables/row/table/*' }).as('rowsReq')
66+
67+
cy.loadTable('Welcome to Nextcloud Tables!')
68+
69+
cy.wait('@rowsReq').then(({ response }) => {
70+
const firstRow = response.body[0]
71+
const csv = [
72+
['id', 'What', 'How to do'],
73+
[firstRow.id, 'What (Updated)', 'How to do (Updated)'],
74+
]
75+
76+
cy.writeFile('cypress/fixtures/test-import-update.csv', csv.map(row => row.join(',')).join('\n'))
77+
})
78+
79+
cy.clickOnTableThreeDotMenu('Import')
80+
cy.get('.modal__content button').contains('Upload from device').click()
81+
cy.get('input[type="file"]').selectFile('cypress/fixtures/test-import-update.csv', { force: true })
82+
83+
cy.get('.modal__content button').contains('Preview').click()
84+
cy.get('.file_import__preview tbody tr', { timeout: 20000 }).should('have.length', 3)
85+
86+
cy.intercept({ method: 'POST', url: '**/apps/tables/importupload/table/*'}).as('importUploadReq')
87+
cy.get('.modal__content button').contains('Import').click()
88+
cy.wait('@importUploadReq')
89+
cy.get('[data-cy="importResultColumnsFound"]', { timeout: 20000 }).should('contain.text', '2')
90+
cy.get('[data-cy="importResultColumnsMatch"]').should('contain.text', '3')
91+
cy.get('[data-cy="importResultColumnsCreated"]').should('contain.text', '0')
92+
cy.get('[data-cy="importResultRowsInserted"]').should('contain.text', '0')
93+
cy.get('[data-cy="importResultRowsUpdated"]').should('contain.text', '1')
94+
cy.get('[data-cy="importResultParsingErrors"]').should('contain.text', '0')
95+
cy.get('[data-cy="importResultRowErrors"]').should('contain.text', '0')
96+
})
97+
6498
})
6599

66100
describe('Import csv from Files file action', () => {

‎lib/Service/ColumnService.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ public function findOrCreateColumnsByTitleForTableAsArray(?int $tableId, ?int $v
470470
$result[$i] = '';
471471
}
472472
// if column was not found
473-
if ($result[$i] === '' && $createUnknownColumns) {
473+
if ($result[$i] === '' && $createUnknownColumns && $dataTypes[$i]['type'] !== Column::TYPE_META_ID) {
474474
$description = $this->l->t('This column was automatically created by the import service.');
475475
$result[$i] = $this->create(
476476
$userId,

‎lib/Service/ImportService.php‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
use Psr\Container\ContainerExceptionInterface;
3434
use Psr\Container\NotFoundExceptionInterface;
3535
use Psr\Log\LoggerInterface;
36-
use Throwable;
3736
use TypeError;
3837
use function file_exists;
3938
use function is_string;
@@ -185,7 +184,7 @@ private function getPreviewData(Worksheet $worksheet): array {
185184
$colIndex = $cellIterator->getCurrentColumnIndex() - 1;
186185
$column = $this->columns[$colIndex];
187186

188-
if (!array_key_exists($colIndex, $this->columns)) {
187+
if (!array_key_exists($colIndex, $columns)) {
189188
continue;
190189
}
191190

@@ -421,7 +420,7 @@ private function upsertRow(Row $row): void {
421420
}
422421

423422
$columnKey = $i;
424-
if ($this->idColumnIndex !== null && $i > $this->idColumnIndex) {
423+
if ($this->columnsConfig && $this->idColumnIndex !== null && $i > $this->idColumnIndex) {
425424
// if we have an ID column, we need to adjust the index
426425
$columnKey = $i - 1;
427426
}
@@ -557,6 +556,8 @@ private function getColumns(Row $firstRow, Row $secondRow): void {
557556

558557
if (!$this->columnsConfig && mb_strtolower($title) === Column::META_ID_TITLE) {
559558
$this->idColumnIndex = $index;
559+
$titles[] = $title;
560+
$dataTypes[] = ['type' => Column::TYPE_META_ID];
560561
$secondRowCellIterator->next();
561562
$index++;
562563
continue;

‎tests/integration/features/APIv1.feature‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ Feature: APIv1
269269
| | new row | 100 |
270270
When user imports file "update-rows.csv" into last created table
271271
Then import results have the following data
272-
| found_columns_count | 2 |
272+
| found_columns_count | 3 |
273273
| matching_columns_count | 2 |
274274
| created_columns_count | 0 |
275275
| inserted_rows_count | 1 |

0 commit comments

Comments
 (0)