Skip to content

Commit

Permalink
fix: Psalm complaints after rebase and incomplete migrations after up…
Browse files Browse the repository at this point in the history
…grade

Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Jul 25, 2024
1 parent 6e86b9e commit 14fa4b0
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 33 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Share your tables and views with users and groups within your cloud.
Have a good time and manage whatever you want.
]]></description>
<version>0.8.0-dev.0</version>
<version>0.8.0-dev.1</version>
<licence>agpl</licence>
<author mail="[email protected]">Florian Steffens</author>
<namespace>Tables</namespace>
Expand Down
7 changes: 7 additions & 0 deletions lib/Controller/ApiTablesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ public function createFromScheme(string $title, string $emoji, string $descripti
$column['selectionDefault'],

$column['datetimeDefault'],

$column['usergroupDefault'],
$column['usergroupMultipleItems'],
$column['usergroupSelectUsers'],
$column['usergroupSelectGroups'],
$column['showUserStatus'],

[],
);
};
Expand Down
4 changes: 2 additions & 2 deletions lib/Migration/Version000700Date20230916000000.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Version000700Date20230916000000 extends SimpleMigrationStep {
* because it might cause problems on auto web updates
* (class might not be loaded if it gets replaced during the runtime)
*/
private array $columns = [
public static array $columns = [
[
'name' => 'text',
'db_type' => Types::TEXT,
Expand Down Expand Up @@ -57,7 +57,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt

$this->createRowSleevesTable($schema);

$rowTypeSchema = $this->columns;
$rowTypeSchema = self::$columns;

foreach ($rowTypeSchema as $colType) {
$this->createRowValueTable($schema, $colType['name'], $colType['db_type']);
Expand Down
86 changes: 57 additions & 29 deletions lib/Migration/Version000800Date20240712000000.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,76 @@
<?php

/** @noinspection PhpUnused */

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Tables\Migration;

use Closure;
use OCP\DB\Exception;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version000800Date20240712000000 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
* @throws Exception
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$this->createRowValueTable($schema, 'usergroup', Types::TEXT);

$hasChanges = $this->createRowValueTable($schema, 'usergroup', Types::TEXT);
$hasChanges = $this->haveValueTypeColumn($schema) ?? $hasChanges;
$hasChanges = $this->haveUserGroupColumnDefinitionFields($schema) ?? $hasChanges;

return $hasChanges;
}

/**
* Add new value_type column to all existing tables_row_cells_ tables for cell data
*/
private function haveValueTypeColumn(ISchemaWrapper $schema): ?ISchemaWrapper {
$existingTypes = Version000700Date20230916000000::$columns;
$hasChanges = null;
foreach ($existingTypes as $type) {
$tableName = 'tables_row_cells_' . $type['name'];
if ($schema->hasTable($tableName)) {
$table = $schema->getTable($tableName);
if (!$table->hasColumn('value_type')) {
$table->addColumn('value_type', Types::INTEGER, ['notnull' => false]);
$hasChanges = $schema;
}
}
}
return $hasChanges;
}

private function createRowValueTable(ISchemaWrapper $schema, string $name, string $type): ?ISchemaWrapper {
if (!$schema->hasTable('tables_row_cells_'.$name)) {
$table = $schema->createTable('tables_row_cells_'.$name);
$table->addColumn('id', Types::INTEGER, [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('column_id', Types::INTEGER, ['notnull' => true]);
$table->addColumn('row_id', Types::INTEGER, ['notnull' => true]);
$table->addColumn('value', $type, ['notnull' => false]);
$table->addColumn('value_type', Types::INTEGER, ['notnull' => false]);
$table->addColumn('last_edit_at', Types::DATETIME, ['notnull' => true]);
$table->addColumn('last_edit_by', Types::STRING, ['notnull' => true, 'length' => 64]);
$table->addIndex(['column_id', 'row_id']);
$table->setPrimaryKey(['id']);
return $schema;
}

return null;
}

/**
* Add column schema options for usergroup type to the tables_columns table
*/
private function haveUserGroupColumnDefinitionFields(ISchemaWrapper $schema) {
if ($schema->hasTable('tables_columns')) {
$table = $schema->getTable('tables_columns');
if (!$table->hasColumn('usergroup_default')) {
Expand Down Expand Up @@ -59,24 +104,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
}
return $schema;
}
return null;
}

private function createRowValueTable(ISchemaWrapper $schema, string $name, string $type) {
if (!$schema->hasTable('tables_row_cells_'.$name)) {
$table = $schema->createTable('tables_row_cells_'.$name);
$table->addColumn('id', Types::INTEGER, [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('column_id', Types::INTEGER, ['notnull' => true]);
$table->addColumn('row_id', Types::INTEGER, ['notnull' => true]);
$table->addColumn('value', $type, ['notnull' => false]);
$table->addColumn('value_type', Types::INTEGER, ['notnull' => false]);
$table->addColumn('last_edit_at', Types::DATETIME, ['notnull' => true]);
$table->addColumn('last_edit_by', Types::STRING, ['notnull' => true, 'length' => 64]);
$table->addIndex(['column_id', 'row_id']);
$table->setPrimaryKey(['id']);
}
return null;
}
}
6 changes: 5 additions & 1 deletion lib/Service/ColumnTypes/UsergroupBusiness.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function parseValue($value, ?Column $column = null): string {
}

/**
* @param string $value json encoded array{id: string, type: int}
* @param mixed $value parsable is json encoded array{id: string, type: int}
* @param Column|null $column
* @return bool
*/
Expand All @@ -39,6 +39,10 @@ public function canBeParsed($value, ?Column $column = null): bool {
return true;
}

if (!is_string($value)) {
return false;
}

foreach (json_decode($value, true) as $v) {
if((array_key_exists('id', $v) && !is_string($v['id'])) && (array_key_exists('type', $v) && !is_int($v['type']))) {
return false;
Expand Down
5 changes: 5 additions & 0 deletions lib/Service/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ private function getColumns(Row $firstRow, Row $secondRow): void {
$this->columnsConfig[$index]['selectionOptions'] ?? '',
$this->columnsConfig[$index]['selectionDefault'] ?? '',
$this->columnsConfig[$index]['datetimeDefault'] ?? '',
$this->columnsConfig[$index]['usergroupDefault'] ?? null,
$this->columnsConfig[$index]['usergroupMultipleItems'] ?? null,
$this->columnsConfig[$index]['usergroupSelectUsers'] ?? null,
$this->columnsConfig[$index]['usergroupSelectGroups'] ?? null,
$this->columnsConfig[$index]['showUserStatus'] ?? null,
$this->columnsConfig[$index]['selectedViewIds'] ?? []
);
$title = $column->getTitle();
Expand Down

0 comments on commit 14fa4b0

Please sign in to comment.