@@ -731,9 +731,11 @@ public function insert(Row2 $row): Row2 {
731731 }
732732
733733 // write all cells to its db-table
734+ $ cells = [];
734735 foreach ($ row ->getData () as $ cell ) {
735- $ this ->insertCell ($ rowSleeve ->getId (), $ cell ['columnId ' ], $ cell ['value ' ], $ rowSleeve ->getLastEditAt (), $ rowSleeve ->getLastEditBy ());
736+ $ cells [ $ cell [ ' columnId ' ]] = $ this ->insertCell ($ rowSleeve ->getId (), $ cell ['columnId ' ], $ cell ['value ' ], $ rowSleeve ->getLastEditAt (), $ rowSleeve ->getLastEditBy ());
736737 }
738+ $ rowSleeve ->setCells (json_encode ($ cells ));
737739
738740 return $ row ;
739741 }
@@ -750,9 +752,9 @@ public function update(Row2 $row): Row2 {
750752
751753 // update meta data for sleeve
752754 try {
753- $ sleeve = $ this ->rowSleeveMapper ->find ($ row ->getId ());
754- $ this ->updateMetaData ($ sleeve );
755- $ this ->rowSleeveMapper ->update ($ sleeve );
755+ $ rowSleeve = $ this ->rowSleeveMapper ->find ($ row ->getId ());
756+ $ this ->updateMetaData ($ rowSleeve );
757+ $ this ->rowSleeveMapper ->update ($ rowSleeve );
756758 } catch (DoesNotExistException |MultipleObjectsReturnedException |Exception $ e ) {
757759 $ this ->logger ->error ($ e ->getMessage (), ['exception ' => $ e ]);
758760 throw new InternalError (get_class ($ this ) . ' - ' . __FUNCTION__ . ': ' . $ e ->getMessage ());
@@ -761,9 +763,11 @@ public function update(Row2 $row): Row2 {
761763 $ this ->columnMapper ->preloadColumns (array_column ($ changedCells , 'columnId ' ));
762764
763765 // write all changed cells to its db-table
766+ $ cachedCells = $ rowSleeve ->getCachedCellsArray ();
764767 foreach ($ changedCells as $ cell ) {
765- $ this ->insertOrUpdateCell ($ sleeve ->getId (), $ cell ['columnId ' ], $ cell ['value ' ]);
768+ $ cachedCells [ $ cell [ ' columnId ' ]] = $ this ->insertOrUpdateCell ($ rowSleeve ->getId (), $ cell ['columnId ' ], $ cell ['value ' ]);
766769 }
770+ $ rowSleeve ->setCachedCells (json_encode ($ cachedCells ));
767771
768772 return $ row ;
769773 }
@@ -815,9 +819,11 @@ private function updateMetaData($entity, bool $setCreate = false, ?string $lastE
815819 /**
816820 * Insert a cell to its specific db-table
817821 *
822+ * @return array<string, mixed> normalized cell data
823+ *
818824 * @throws InternalError
819825 */
820- private function insertCell (int $ rowId , int $ columnId , $ value , ?string $ lastEditAt = null , ?string $ lastEditBy = null ): void {
826+ private function insertCell (int $ rowId , int $ columnId , $ value , ?string $ lastEditAt = null , ?string $ lastEditBy = null ): array {
821827 try {
822828 $ column = $ this ->columnMapper ->find ($ columnId );
823829 } catch (DoesNotExistException $ e ) {
@@ -827,7 +833,7 @@ private function insertCell(int $rowId, int $columnId, $value, ?string $lastEdit
827833
828834 // insert new cell
829835 $ cellMapper = $ this ->getCellMapper ($ column );
830-
836+ $ cachedCell = [];
831837 try {
832838 $ cellClassName = 'OCA\Tables\Db\RowCell ' . ucfirst ($ column ->getType ());
833839 if ($ cellMapper ->hasMultipleValues ()) {
@@ -839,6 +845,7 @@ private function insertCell(int $rowId, int $columnId, $value, ?string $lastEdit
839845 $ this ->updateMetaData ($ cell , false , $ lastEditAt , $ lastEditBy );
840846 $ cellMapper ->applyDataToEntity ($ column , $ cell , $ val );
841847 $ cellMapper ->insert ($ cell );
848+ $ cachedCell [] = $ cellMapper ->toArray ($ cell );
842849 }
843850 } else {
844851 /** @var RowCellSuper $cell */
@@ -848,50 +855,62 @@ private function insertCell(int $rowId, int $columnId, $value, ?string $lastEdit
848855 $ this ->updateMetaData ($ cell , false , $ lastEditAt , $ lastEditBy );
849856 $ cellMapper ->applyDataToEntity ($ column , $ cell , $ value );
850857 $ cellMapper ->insert ($ cell );
858+ $ cachedCell = $ cellMapper ->toArray ($ cell );
851859 }
852860 } catch (Exception $ e ) {
853861 $ this ->logger ->error ($ e ->getMessage (), ['exception ' => $ e ]);
854862 throw new InternalError ('Failed to insert column: ' . $ e ->getMessage (), 0 , $ e );
855863 }
864+
865+ return $ cachedCell ;
856866 }
857867
858868 /**
859869 * @param RowCellSuper $cell
860870 * @param RowCellMapperSuper $mapper
861871 * @param mixed $value the value should be parsed to the correct format within the row service
862872 * @param Column $column
873+ *
874+ * @return array<string, mixed> normalized cell data
863875 * @throws InternalError
864876 */
865- private function updateCell (RowCellSuper $ cell , RowCellMapperSuper $ mapper , $ value , Column $ column ): void {
866- $ this ->getCellMapper ($ column )->applyDataToEntity ($ column , $ cell , $ value );
877+ private function updateCell (RowCellSuper $ cell , RowCellMapperSuper $ mapper , $ value , Column $ column ): array {
878+ $ cellMapper = $ this ->getCellMapper ($ column );
879+ $ cellMapper ->applyDataToEntity ($ column , $ cell , $ value );
867880 $ this ->updateMetaData ($ cell );
868881 $ mapper ->updateWrapper ($ cell );
882+
883+ return $ cellMapper ->toArray ($ cell );
869884 }
870885
871886 /**
887+ * @return array<string, mixed> normalized cell data
872888 * @throws InternalError
873889 */
874- private function insertOrUpdateCell (int $ rowId , int $ columnId , $ value ): void {
890+ private function insertOrUpdateCell (int $ rowId , int $ columnId , $ value ): array {
875891 $ column = $ this ->columnMapper ->find ($ columnId );
876892 $ cellMapper = $ this ->getCellMapper ($ column );
893+ $ cachedCell = [];
877894 try {
878895 if ($ cellMapper ->hasMultipleValues ()) {
879- $ this ->atomic (function () use ($ cellMapper , $ rowId , $ columnId , $ value ) {
896+ $ this ->atomic (function () use ($ cellMapper , $ rowId , $ columnId , $ value, & $ cachedCell ) {
880897 // For a usergroup field with mutiple values, each is inserted as a new cell
881898 // we need to delete all previous cells for this row and column, otherwise we get duplicates
882899 $ cellMapper ->deleteAllForColumnAndRow ($ columnId , $ rowId );
883- $ this ->insertCell ($ rowId , $ columnId , $ value );
900+ $ cachedCell = $ this ->insertCell ($ rowId , $ columnId , $ value );
884901 }, $ this ->db );
885902 } else {
886903 $ cell = $ cellMapper ->findByRowAndColumn ($ rowId , $ columnId );
887- $ this ->updateCell ($ cell , $ cellMapper , $ value , $ column );
904+ $ cachedCell = $ this ->updateCell ($ cell , $ cellMapper , $ value , $ column );
888905 }
889906 } catch (DoesNotExistException ) {
890- $ this ->insertCell ($ rowId , $ columnId , $ value );
907+ $ cachedCell = $ this ->insertCell ($ rowId , $ columnId , $ value );
891908 } catch (MultipleObjectsReturnedException |Exception $ e ) {
892909 $ this ->logger ->error ($ e ->getMessage (), ['exception ' => $ e ]);
893- throw new InternalError (get_class ($ this ) . ' - ' . __FUNCTION__ . ': ' . $ e ->getMessage ());
910+ throw new InternalError (get_class ($ this ) . ' - ' . __FUNCTION__ . ': ' . $ e ->getMessage (), $ e -> getCode (), $ e );
894911 }
912+
913+ return $ cachedCell ;
895914 }
896915
897916 private function getCellMapper (Column $ column ): RowCellMapperSuper {
0 commit comments