2929namespace OCA \MediaDC \Service ;
3030
3131use DOMDocument ;
32+ use OCA \Files_Sharing \SharedStorage ;
3233use OCP \Files \File ;
3334use OCP \Files \Node ;
3435use OCP \Files \Folder ;
@@ -768,7 +769,7 @@ public function deleteTaskDetailFile($taskId, $groupId, $fileid, $removeIfOneLef
768769 } catch (NotPermittedException | NotFoundException $ e ) {
769770 return [
770771 'success ' => false ,
771- 'not_permited ' => $ e instanceof NotPermittedException,
772+ 'not_permitted ' => $ e instanceof NotPermittedException,
772773 'not_found ' => $ e instanceof NotFoundException,
773774 ];
774775 }
@@ -780,7 +781,7 @@ public function deleteTaskDetailFile($taskId, $groupId, $fileid, $removeIfOneLef
780781 }
781782
782783 /**
783- * Remove ColectorTaskDetail groups with deleting coresponding files
784+ * Remove CollectorTaskDetail groups with deleting corresponding files
784785 *
785786 * @param int $taskId
786787 * @param array $groupIds
@@ -801,7 +802,45 @@ public function removeTaskDetailGroups(int $taskId, array $groupIds) {
801802 }
802803
803804 /**
804- * Delete ColectorTaskDetail groups with deleting coresponding files
805+ * Delete all CollectorTaskDetail group files except one largest
806+ *
807+ * @param int $taskId
808+ * @param array $groupIds
809+ *
810+ * @return array
811+ */
812+ public function deleteTaskDetailGroupsFiles (int $ taskId , array $ groupIds ) {
813+ $ result = [];
814+ foreach ($ groupIds as $ groupId ) {
815+ $ groupFiles = $ this ->tasksDetailsMapper ->findAllByGroupIdSize ($ taskId , $ groupId );
816+ $ largestFileId = array_splice ($ groupFiles , 0 , 1 )[0 ];
817+ $ this ->tasksDetailsMapper ->deleteGroupFiles ($ taskId , $ groupId , [$ largestFileId ]);
818+ $ this ->markResolvedPhoto ($ largestFileId , true );
819+ $ this ->markResolvedVideo ($ largestFileId , true );
820+ $ collectorTask = null ;
821+ foreach ($ groupFiles as $ fileId ) {
822+ $ deleteFileResult = $ this ->deleteTaskDetailFile ($ taskId , $ groupId , $ fileId , false );
823+ if ($ deleteFileResult ['success ' ]) {
824+ $ collectorTask = $ deleteFileResult ['task ' ];
825+ $ fileIdIndex = array_search ($ fileId , $ groupFiles );
826+ if ($ fileIdIndex !== false ) {
827+ array_splice ($ groupFiles , $ fileIdIndex , 1 )[0 ];
828+ }
829+ }
830+ }
831+ if (count ($ groupFiles ) === 0 ) {
832+ $ result [] = intval ($ groupId );
833+ }
834+ }
835+ return [
836+ 'success ' => count ($ result ) === count ($ groupIds ),
837+ 'removedGroupIds ' => $ result ,
838+ 'task ' => $ collectorTask ,
839+ ];
840+ }
841+
842+ /**
843+ * Delete CollectorTaskDetail groups with deleting corresponding files
805844 *
806845 * @param int $taskId
807846 * @param int $groupId
@@ -813,7 +852,7 @@ public function deleteTaskDetailFiles(int $taskId, int $groupId, array $fileIds)
813852 $ result = [];
814853 $ errors = [
815854 'locked ' => [],
816- 'not_permited ' => [],
855+ 'not_permitted ' => [],
817856 'not_found ' => [],
818857 ];
819858 $ groupFiles = $ this ->tasksDetailsMapper ->findAllByGroupId ($ taskId , $ groupId );
@@ -828,8 +867,8 @@ public function deleteTaskDetailFiles(int $taskId, int $groupId, array $fileIds)
828867 if (isset ($ deleteFileResult ['locked ' ]) && $ deleteFileResult ['locked ' ]) {
829868 array_push ($ errors ['locked ' ], $ fileId );
830869 }
831- if (isset ($ deleteFileResult ['not_permited ' ]) && $ deleteFileResult ['not_permited ' ]) {
832- array_push ($ errors ['not_permited ' ], $ fileId );
870+ if (isset ($ deleteFileResult ['not_permitted ' ]) && $ deleteFileResult ['not_permitted ' ]) {
871+ array_push ($ errors ['not_permitted ' ], $ fileId );
833872 }
834873 if (isset ($ deleteFileResult ['not_found ' ]) && $ deleteFileResult ['not_found ' ]) {
835874 array_push ($ errors ['not_found ' ], $ fileId );
@@ -855,7 +894,7 @@ public function deleteTaskDetailFiles(int $taskId, int $groupId, array $fileIds)
855894 }
856895
857896 /**
858- * Remove ColectorTaskDetail groups with deleting coresponding files
897+ * Remove CollectorTaskDetail groups with deleting corresponding files
859898 *
860899 * @param int $taskId
861900 * @param int $groupId
0 commit comments