mirror of
https://github.com/nextcloud/tables.git
synced 2025-08-15 21:34:24 +00:00
enh: modify usergroup column backend
Signed-off-by: Cleopatra Enjeck M <patrathewhiz@gmail.com>
This commit is contained in:

committed by
Julius Härtl

parent
11aa7bca52
commit
62280240b1
@ -149,8 +149,8 @@ class Column extends Entity implements JsonSerializable {
|
||||
|
||||
public function getUsergroupDefaultArray():array {
|
||||
$default = $this->getUsergroupDefault();
|
||||
if ($default !== "" && $default !== null && $default !== 'null') {
|
||||
return \json_decode($default, true);
|
||||
if ($default !== "" && $default !== null) {
|
||||
return \json_decode($default, true) ?? [];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ use OCA\Tables\Db\ColumnTypes\NumberColumnQB;
|
||||
use OCA\Tables\Db\ColumnTypes\SelectionColumnQB;
|
||||
use OCA\Tables\Db\ColumnTypes\SuperColumnQB;
|
||||
use OCA\Tables\Db\ColumnTypes\TextColumnQB;
|
||||
use OCA\Tables\Db\ColumnTypes\UsergroupColumnQB;
|
||||
use OCA\Tables\Errors\InternalError;
|
||||
use OCA\Tables\Helper\UserHelper;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
@ -30,7 +29,6 @@ class LegacyRowMapper extends QBMapper {
|
||||
protected SelectionColumnQB $selectionColumnQB;
|
||||
protected NumberColumnQB $numberColumnQB;
|
||||
protected DatetimeColumnQB $datetimeColumnQB;
|
||||
protected UsergroupColumnQB $usergroupColumnQB;
|
||||
protected SuperColumnQB $genericColumnQB;
|
||||
protected ColumnMapper $columnMapper;
|
||||
protected LoggerInterface $logger;
|
||||
@ -46,7 +44,6 @@ class LegacyRowMapper extends QBMapper {
|
||||
SelectionColumnQB $selectionColumnQB,
|
||||
NumberColumnQB $numberColumnQB,
|
||||
DatetimeColumnQB $datetimeColumnQB,
|
||||
UsergroupColumnQB $usergroupColumnQB,
|
||||
SuperColumnQB $columnQB,
|
||||
ColumnMapper $columnMapper,
|
||||
UserHelper $userHelper,
|
||||
@ -57,7 +54,6 @@ class LegacyRowMapper extends QBMapper {
|
||||
$this->numberColumnQB = $numberColumnQB;
|
||||
$this->selectionColumnQB = $selectionColumnQB;
|
||||
$this->datetimeColumnQB = $datetimeColumnQB;
|
||||
$this->usergroupColumnQB = $usergroupColumnQB;
|
||||
$this->genericColumnQB = $columnQB;
|
||||
$this->columnMapper = $columnMapper;
|
||||
$this->userHelper = $userHelper;
|
||||
@ -78,7 +74,6 @@ class LegacyRowMapper extends QBMapper {
|
||||
$this->numberColumnQB->setPlatform($this->platform);
|
||||
$this->selectionColumnQB->setPlatform($this->platform);
|
||||
$this->datetimeColumnQB->setPlatform($this->platform);
|
||||
$this->usergroupColumnQB->setPlatform($this->platform);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,6 +10,7 @@ use OCA\Tables\Helper\UserHelper;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||
use OCP\AppFramework\Db\QBMapper;
|
||||
use OCP\AppFramework\Db\TTransactional;
|
||||
use OCP\DB\Exception;
|
||||
use OCP\DB\IResult;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
@ -21,6 +22,8 @@ use Psr\Log\LoggerInterface;
|
||||
use Throwable;
|
||||
|
||||
class Row2Mapper {
|
||||
use TTransactional;
|
||||
|
||||
private RowSleeveMapper $rowSleeveMapper;
|
||||
private ?string $userId = null;
|
||||
private IDBConnection $db;
|
||||
@ -524,7 +527,7 @@ class Row2Mapper {
|
||||
$value = $this->formatValue($this->columns[$rowData['column_id']], $rowData['value'], 'out', $rowData['value_type']);
|
||||
$compositeKey = (string)$rowData['row_id'] . ',' . (string)$rowData['column_id'];
|
||||
|
||||
if ($columnTypes[$rowData['column_id']] == 'usergroup') {
|
||||
if ($columnTypes[$rowData['column_id']] === Column::TYPE_USERGROUP) {
|
||||
if (array_key_exists($compositeKey, $rowValues)) {
|
||||
$rowValues[$compositeKey][] = $value;
|
||||
} else {
|
||||
@ -688,7 +691,7 @@ class Row2Mapper {
|
||||
|
||||
$v = $this->formatValue($this->columns[$columnId], $value, 'in');
|
||||
|
||||
if ($this->columns[$columnId]->getType() == 'usergroup') {
|
||||
if ($this->columns[$columnId]->getType() === Column::TYPE_USERGROUP) {
|
||||
foreach ($v as $val) {
|
||||
/** @var RowCellSuper $cell */
|
||||
$cell = new $cellClassName();
|
||||
@ -748,11 +751,12 @@ class Row2Mapper {
|
||||
$this->logger->error($e->getMessage(), ['exception' => $e]);
|
||||
throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage());
|
||||
}
|
||||
if ($columnType == 'usergroup') {
|
||||
if ($columnType === Column::TYPE_USERGROUP) {
|
||||
try {
|
||||
// TODO Maybe these should be a transaction?
|
||||
$this->atomic(function () use ($cellMapper, $rowId, $columnId, $value) {
|
||||
$cellMapper->deleteAllForRow($rowId);
|
||||
$this->insertCell($rowId, $columnId, $value);
|
||||
}, $this->db);
|
||||
} catch (Exception $e) {
|
||||
$this->logger->error($e->getMessage(), ['exception' => $e]);
|
||||
throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage());
|
||||
|
@ -86,21 +86,6 @@ class RowCellMapperSuper extends QBMapper {
|
||||
return $this->findEntity($qb);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @throws MultipleObjectsReturnedException
|
||||
// * @throws DoesNotExistException
|
||||
// * @throws Exception
|
||||
// */
|
||||
// public function findMultByRowAndColumn(int $rowId, int $columnId): array{
|
||||
// $qb = $this->db->getQueryBuilder();
|
||||
// $qb->select('*')
|
||||
// ->from($this->tableName)
|
||||
// ->where($qb->expr()->eq('row_id', $qb->createNamedParameter($rowId, IQueryBuilder::PARAM_INT)))
|
||||
// ->andWhere($qb->expr()->eq('column_id', $qb->createNamedParameter($columnId, IQueryBuilder::PARAM_INT)));
|
||||
// return $this->findEntities($qb);
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* @throws MultipleObjectsReturnedException
|
||||
* @throws DoesNotExistException
|
||||
|
@ -40,7 +40,6 @@ class UsergroupBusiness extends SuperBusiness implements IColumnTypeBusiness {
|
||||
}
|
||||
|
||||
foreach ($value as $v) {
|
||||
// TODO: maybe check if key exists first
|
||||
if((array_key_exists('id', $v) && !is_string($v['id'])) && (array_key_exists('type', $v) && !is_int($v['type']))) {
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user