Skip to content

Commit

Permalink
enh: modify usergroup column backend
Browse files Browse the repository at this point in the history
Signed-off-by: Cleopatra Enjeck M <patrathewhiz@gmail.com>
  • Loading branch information
enjeck committed Jul 2, 2024
1 parent b2092af commit f8f0355
Show file tree
Hide file tree
Showing 7 changed files with 661 additions and 1,118 deletions.
4 changes: 2 additions & 2 deletions lib/Db/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ public function __construct() {

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 [];
}
Expand Down
5 changes: 0 additions & 5 deletions lib/Db/LegacyRowMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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;
Expand All @@ -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;
Expand All @@ -46,7 +44,6 @@ public function __construct(
SelectionColumnQB $selectionColumnQB,
NumberColumnQB $numberColumnQB,
DatetimeColumnQB $datetimeColumnQB,
UsergroupColumnQB $usergroupColumnQB,
SuperColumnQB $columnQB,
ColumnMapper $columnMapper,
UserHelper $userHelper,
Expand All @@ -57,7 +54,6 @@ public function __construct(
$this->numberColumnQB = $numberColumnQB;
$this->selectionColumnQB = $selectionColumnQB;
$this->datetimeColumnQB = $datetimeColumnQB;
$this->usergroupColumnQB = $usergroupColumnQB;
$this->genericColumnQB = $columnQB;
$this->columnMapper = $columnMapper;
$this->userHelper = $userHelper;
Expand All @@ -78,7 +74,6 @@ private function setPlatform() {
$this->numberColumnQB->setPlatform($this->platform);
$this->selectionColumnQB->setPlatform($this->platform);
$this->datetimeColumnQB->setPlatform($this->platform);
$this->usergroupColumnQB->setPlatform($this->platform);
}

/**
Expand Down
16 changes: 10 additions & 6 deletions lib/Db/Row2Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand All @@ -21,6 +22,8 @@
use Throwable;

class Row2Mapper {
use TTransactional;

private RowSleeveMapper $rowSleeveMapper;
private ?string $userId = null;
private IDBConnection $db;
Expand Down Expand Up @@ -524,7 +527,7 @@ private function parseEntities(IResult $result, array $sleeves, array $columnTyp
$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 {
Expand Down Expand Up @@ -688,7 +691,7 @@ private function insertCell(int $rowId, int $columnId, $value, ?string $lastEdit

$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();
Expand Down Expand Up @@ -748,11 +751,12 @@ private function insertOrUpdateCell(int $rowId, int $columnId, $value): void {
$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?
$cellMapper->deleteAllForRow($rowId);
$this->insertCell($rowId, $columnId, $value);
$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());
Expand Down
15 changes: 0 additions & 15 deletions lib/Db/RowCellMapperSuper.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,6 @@ public function findByRowAndColumn(int $rowId, int $columnId): RowCellSuper {
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
Expand Down
1 change: 0 additions & 1 deletion lib/Service/ColumnTypes/UsergroupBusiness.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public function canBeParsed($value, ?Column $column = null): bool {
}

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;
}
Expand Down
Loading

0 comments on commit f8f0355

Please sign in to comment.