@@ -733,9 +733,11 @@ public function insert(Row2 $row): Row2 {
733733 }
734734
735735 // write all cells to its db-table
736+ $ cells = [];
736737 foreach ($ row ->getData () as $ cell ) {
737- $ this ->insertCell ($ rowSleeve ->getId (), $ cell ['columnId ' ], $ cell ['value ' ], $ rowSleeve ->getLastEditAt (), $ rowSleeve ->getLastEditBy ());
738+ $ cells [ $ cell [ ' columnId ' ]] = $ this ->insertCell ($ rowSleeve ->getId (), $ cell ['columnId ' ], $ cell ['value ' ], $ rowSleeve ->getLastEditAt (), $ rowSleeve ->getLastEditBy ());
738739 }
740+ $ rowSleeve ->setCells (json_encode ($ cells ));
739741
740742 return $ row ;
741743 }
@@ -752,9 +754,9 @@ public function update(Row2 $row): Row2 {
752754
753755 // update meta data for sleeve
754756 try {
755- $ sleeve = $ this ->rowSleeveMapper ->find ($ row ->getId ());
756- $ this ->updateMetaData ($ sleeve );
757- $ this ->rowSleeveMapper ->update ($ sleeve );
757+ $ rowSleeve = $ this ->rowSleeveMapper ->find ($ row ->getId ());
758+ $ this ->updateMetaData ($ rowSleeve );
759+ $ this ->rowSleeveMapper ->update ($ rowSleeve );
758760 } catch (DoesNotExistException |MultipleObjectsReturnedException |Exception $ e ) {
759761 $ this ->logger ->error ($ e ->getMessage (), ['exception ' => $ e ]);
760762 throw new InternalError (get_class ($ this ) . ' - ' . __FUNCTION__ . ': ' . $ e ->getMessage ());
@@ -763,9 +765,11 @@ public function update(Row2 $row): Row2 {
763765 $ this ->columnMapper ->preloadColumns (array_column ($ changedCells , 'columnId ' ));
764766
765767 // write all changed cells to its db-table
768+ $ cachedCells = $ rowSleeve ->getCachedCellsArray ();
766769 foreach ($ changedCells as $ cell ) {
767- $ this ->insertOrUpdateCell ($ sleeve ->getId (), $ cell ['columnId ' ], $ cell ['value ' ]);
770+ $ cachedCells [ $ cell [ ' columnId ' ]] = $ this ->insertOrUpdateCell ($ rowSleeve ->getId (), $ cell ['columnId ' ], $ cell ['value ' ]);
768771 }
772+ $ rowSleeve ->setCachedCells (json_encode ($ cachedCells ));
769773
770774 return $ row ;
771775 }
@@ -817,9 +821,11 @@ private function updateMetaData($entity, bool $setCreate = false, ?string $lastE
817821 /**
818822 * Insert a cell to its specific db-table
819823 *
824+ * @return array<string, mixed> normalized cell data
825+ *
820826 * @throws InternalError
821827 */
822- private function insertCell (int $ rowId , int $ columnId , $ value , ?string $ lastEditAt = null , ?string $ lastEditBy = null ): void {
828+ private function insertCell (int $ rowId , int $ columnId , $ value , ?string $ lastEditAt = null , ?string $ lastEditBy = null ): array {
823829 try {
824830 $ column = $ this ->columnMapper ->find ($ columnId );
825831 } catch (DoesNotExistException $ e ) {
@@ -829,7 +835,7 @@ private function insertCell(int $rowId, int $columnId, $value, ?string $lastEdit
829835
830836 // insert new cell
831837 $ cellMapper = $ this ->getCellMapper ($ column );
832-
838+ $ cachedCell = [];
833839 try {
834840 $ cellClassName = 'OCA\Tables\Db\RowCell ' . ucfirst ($ column ->getType ());
835841 if ($ cellMapper ->hasMultipleValues ()) {
@@ -841,6 +847,7 @@ private function insertCell(int $rowId, int $columnId, $value, ?string $lastEdit
841847 $ this ->updateMetaData ($ cell , false , $ lastEditAt , $ lastEditBy );
842848 $ cellMapper ->applyDataToEntity ($ column , $ cell , $ val );
843849 $ cellMapper ->insert ($ cell );
850+ $ cachedCell [] = $ cellMapper ->toArray ($ cell );
844851 }
845852 } else {
846853 /** @var RowCellSuper $cell */
@@ -850,50 +857,62 @@ private function insertCell(int $rowId, int $columnId, $value, ?string $lastEdit
850857 $ this ->updateMetaData ($ cell , false , $ lastEditAt , $ lastEditBy );
851858 $ cellMapper ->applyDataToEntity ($ column , $ cell , $ value );
852859 $ cellMapper ->insert ($ cell );
860+ $ cachedCell = $ cellMapper ->toArray ($ cell );
853861 }
854862 } catch (Exception $ e ) {
855863 $ this ->logger ->error ($ e ->getMessage (), ['exception ' => $ e ]);
856864 throw new InternalError ('Failed to insert column: ' . $ e ->getMessage (), 0 , $ e );
857865 }
866+
867+ return $ cachedCell ;
858868 }
859869
860870 /**
861871 * @param RowCellSuper $cell
862872 * @param RowCellMapperSuper $mapper
863873 * @param mixed $value the value should be parsed to the correct format within the row service
864874 * @param Column $column
875+ *
876+ * @return array<string, mixed> normalized cell data
865877 * @throws InternalError
866878 */
867- private function updateCell (RowCellSuper $ cell , RowCellMapperSuper $ mapper , $ value , Column $ column ): void {
868- $ this ->getCellMapper ($ column )->applyDataToEntity ($ column , $ cell , $ value );
879+ private function updateCell (RowCellSuper $ cell , RowCellMapperSuper $ mapper , $ value , Column $ column ): array {
880+ $ cellMapper = $ this ->getCellMapper ($ column );
881+ $ cellMapper ->applyDataToEntity ($ column , $ cell , $ value );
869882 $ this ->updateMetaData ($ cell );
870883 $ mapper ->updateWrapper ($ cell );
884+
885+ return $ cellMapper ->toArray ($ cell );
871886 }
872887
873888 /**
889+ * @return array<string, mixed> normalized cell data
874890 * @throws InternalError
875891 */
876- private function insertOrUpdateCell (int $ rowId , int $ columnId , $ value ): void {
892+ private function insertOrUpdateCell (int $ rowId , int $ columnId , $ value ): array {
877893 $ column = $ this ->columnMapper ->find ($ columnId );
878894 $ cellMapper = $ this ->getCellMapper ($ column );
895+ $ cachedCell = [];
879896 try {
880897 if ($ cellMapper ->hasMultipleValues ()) {
881- $ this ->atomic (function () use ($ cellMapper , $ rowId , $ columnId , $ value ) {
898+ $ this ->atomic (function () use ($ cellMapper , $ rowId , $ columnId , $ value, & $ cachedCell ) {
882899 // For a usergroup field with mutiple values, each is inserted as a new cell
883900 // we need to delete all previous cells for this row and column, otherwise we get duplicates
884901 $ cellMapper ->deleteAllForColumnAndRow ($ columnId , $ rowId );
885- $ this ->insertCell ($ rowId , $ columnId , $ value );
902+ $ cachedCell = $ this ->insertCell ($ rowId , $ columnId , $ value );
886903 }, $ this ->db );
887904 } else {
888905 $ cell = $ cellMapper ->findByRowAndColumn ($ rowId , $ columnId );
889- $ this ->updateCell ($ cell , $ cellMapper , $ value , $ column );
906+ $ cachedCell = $ this ->updateCell ($ cell , $ cellMapper , $ value , $ column );
890907 }
891908 } catch (DoesNotExistException ) {
892- $ this ->insertCell ($ rowId , $ columnId , $ value );
909+ $ cachedCell = $ this ->insertCell ($ rowId , $ columnId , $ value );
893910 } catch (MultipleObjectsReturnedException |Exception $ e ) {
894911 $ this ->logger ->error ($ e ->getMessage (), ['exception ' => $ e ]);
895- throw new InternalError (get_class ($ this ) . ' - ' . __FUNCTION__ . ': ' . $ e ->getMessage ());
912+ throw new InternalError (get_class ($ this ) . ' - ' . __FUNCTION__ . ': ' . $ e ->getMessage (), $ e -> getCode (), $ e );
896913 }
914+
915+ return $ cachedCell ;
897916 }
898917
899918 private function getCellMapper (Column $ column ): RowCellMapperSuper {
0 commit comments