1010use DateTime ;
1111use DateTimeImmutable ;
1212use OCA \Tables \Constants \UsergroupType ;
13+ use OCA \Tables \Dto \RelationLookupSettings ;
1314use OCA \Tables \Errors \InternalError ;
1415use OCA \Tables \Errors \NotFoundError ;
1516use OCA \Tables \Helper \ColumnsHelper ;
@@ -60,6 +61,9 @@ public function delete(Row2 $row): Row2 {
6061 $ this ->db ->beginTransaction ();
6162 try {
6263 foreach ($ this ->columnsHelper ->columns as $ columnType ) {
64+ if ($ this ->isVirtualColumn ($ columnType )) {
65+ continue ;
66+ }
6367 $ this ->getCellMapperFromType ($ columnType )->deleteAllForRow ($ row ->getId ());
6468 }
6569 $ this ->rowSleeveMapper ->deleteById ($ row ->getId ());
@@ -219,6 +223,8 @@ private function getRows(array $rowIds, array $columnIds): array {
219223 private function getRowsChunk (array $ rowIds , array $ columnIds ): array {
220224 $ qb = $ this ->db ->getQueryBuilder ();
221225
226+ $ columnIds = $ this ->addRelationColumnIdsForLookupColumns ($ columnIds );
227+
222228 $ qbSqlForColumnTypes = null ;
223229 foreach ($ this ->columnsHelper ->columns as $ columnType ) {
224230 $ qbTmp = $ this ->db ->getQueryBuilder ();
@@ -234,6 +240,9 @@ private function getRowsChunk(array $rowIds, array $columnIds): array {
234240 $ qbTmp ->selectAlias ($ qbTmp ->createFunction ('NULL ' ), 'value_type ' );
235241 }
236242
243+ if ($ this ->isVirtualColumn ($ columnType )) {
244+ continue ;
245+ }
237246 $ qbTmp
238247 ->from ('tables_row_cells_ ' . $ columnType )
239248 ->where ($ qb ->expr ()->in ('column_id ' , $ qb ->createNamedParameter ($ columnIds , IQueryBuilder::PARAM_INT_ARRAY , ':columnIds ' )))
@@ -839,6 +848,10 @@ private function insertCell(int $rowId, int $columnId, $value, ?string $lastEdit
839848 throw new InternalError (get_class ($ this ) . ' - ' . __FUNCTION__ . ': ' . $ e ->getMessage ());
840849 }
841850
851+ if ($ this ->isVirtualColumn ($ column ->getType ())) {
852+ return ;
853+ }
854+
842855 // insert new cell
843856 $ cellMapper = $ this ->getCellMapper ($ column );
844857
@@ -877,6 +890,10 @@ private function insertCell(int $rowId, int $columnId, $value, ?string $lastEdit
877890 * @throws InternalError
878891 */
879892 private function updateCell (RowCellSuper $ cell , RowCellMapperSuper $ mapper , $ value , Column $ column ): void {
893+ if ($ this ->isVirtualColumn ($ column ->getType ())) {
894+ return ;
895+ }
896+
880897 $ this ->getCellMapper ($ column )->applyDataToEntity ($ column , $ cell , $ value );
881898 $ this ->updateMetaData ($ cell );
882899 $ mapper ->updateWrapper ($ cell );
@@ -887,6 +904,9 @@ private function updateCell(RowCellSuper $cell, RowCellMapperSuper $mapper, $val
887904 */
888905 private function insertOrUpdateCell (int $ rowId , int $ columnId , $ value ): void {
889906 $ column = $ this ->columnMapper ->find ($ columnId );
907+ if ($ this ->isVirtualColumn ($ column ->getType ())) {
908+ return ;
909+ }
890910 $ cellMapper = $ this ->getCellMapper ($ column );
891911 try {
892912 if ($ cellMapper ->hasMultipleValues ()) {
@@ -913,6 +933,9 @@ private function getCellMapper(Column $column): RowCellMapperSuper {
913933 }
914934
915935 private function getCellMapperFromType (string $ columnType ): RowCellMapperSuper {
936+ if ($ this ->isVirtualColumn ($ columnType )) {
937+ throw new InternalError ('Virtual columns do not have cell mappers ' );
938+ }
916939 $ cellMapperClassName = 'OCA\Tables\Db\RowCell ' . ucfirst ($ columnType ) . 'Mapper ' ;
917940 /** @var RowCellMapperSuper $cellMapper */
918941 try {
@@ -934,6 +957,9 @@ private function getColumnDbParamType(Column $column): int {
934957 * @throws InternalError
935958 */
936959 public function deleteDataForColumn (Column $ column ): void {
960+ if ($ this ->isVirtualColumn ($ column ->getType ())) {
961+ return ;
962+ }
937963 try {
938964 $ this ->getCellMapper ($ column )->deleteAllForColumn ($ column ->getId ());
939965 } catch (Exception $ e ) {
@@ -1002,6 +1028,9 @@ private function getFormattedDefaultValue(Column $column) {
10021028 case Column::TYPE_USERGROUP :
10031029 $ defaultValue = $ this ->getCellMapper ($ column )->filterValueToQueryParam ($ column , $ column ->getUsergroupDefault ());
10041030 break ;
1031+ case Column::TYPE_RELATION_LOOKUP :
1032+ $ defaultValue = null ;
1033+ break ;
10051034 }
10061035 return $ defaultValue ;
10071036 }
@@ -1029,4 +1058,26 @@ private function sortRowsByIds(array $rows, array $wantedRowIds): array {
10291058
10301059 return $ sortedRows ;
10311060 }
1061+
1062+ public function isVirtualColumn (string $ columnType ): bool {
1063+ return $ columnType === Column::TYPE_RELATION_LOOKUP ;
1064+ }
1065+
1066+ /**
1067+ * @param int[] $columnIds
1068+ * @return int[]
1069+ */
1070+ public function addRelationColumnIdsForLookupColumns (array $ columnIds ): array {
1071+ $ allColumns = $ this ->columnMapper ->findAll ($ columnIds );
1072+ foreach ($ allColumns as $ column ) {
1073+ if ($ column ->getType () !== Column::TYPE_RELATION_LOOKUP ) {
1074+ continue ;
1075+ }
1076+
1077+ $ settings = $ column ->getCustomSettingsObject (RelationLookupSettings::class);
1078+ $ columnIds [] = $ settings ->relationColumnId ;
1079+ }
1080+ return array_values (array_unique (array_filter ($ columnIds )));
1081+ }
1082+
10321083}
0 commit comments