• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LibreSign / libresign / 20398911259

20 Dec 2025 07:18PM UTC coverage: 43.096%. First build
20398911259

Pull #6242

github

web-flow
Merge 84a3bfc58 into fae2922ee
Pull Request #6242: feat: envelope support

173 of 554 new or added lines in 13 files covered. (31.23%)

6061 of 14064 relevant lines covered (43.1%)

5.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.0
/lib/Service/FileStatusService.php
1
<?php
2

3
declare(strict_types=1);
4
/**
5
 * SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
6
 * SPDX-License-Identifier: AGPL-3.0-or-later
7
 */
8

9
namespace OCA\Libresign\Service;
10

11
use OCA\Libresign\Db\File as FileEntity;
12
use OCA\Libresign\Db\FileMapper;
13
use OCP\AppFramework\Db\DoesNotExistException;
14

15
class FileStatusService {
16
        public function __construct(
17
                private FileMapper $fileMapper,
18
        ) {
19
        }
77✔
20

21
        public function updateFileStatusIfUpgrade(FileEntity $file, int $newStatus): FileEntity {
22
                $currentStatus = $file->getStatus();
18✔
23
                if ($newStatus > $currentStatus) {
18✔
24
                        $file->setStatus($newStatus);
10✔
25
                        $this->fileMapper->update($file);
10✔
26

27
                        if ($file->hasParent()) {
10✔
NEW
28
                                $this->propagateStatusToParent($file->getParentFileId());
×
29
                        }
30
                }
31
                return $file;
18✔
32
        }
33

34
        public function canNotifySigners(?int $fileStatus): bool {
35
                return $fileStatus === FileEntity::STATUS_ABLE_TO_SIGN;
19✔
36
        }
37

38
        public function propagateStatusToParent(int $parentId): void {
39
                try {
40
                        $parent = $this->fileMapper->getById($parentId);
14✔
41
                } catch (DoesNotExistException) {
1✔
42
                        return;
1✔
43
                }
44

45
                if (!$parent->isEnvelope()) {
13✔
46
                        return;
1✔
47
                }
48

49
                $children = $this->fileMapper->getChildrenFiles($parentId);
12✔
50

51
                if (empty($children)) {
12✔
52
                        return;
1✔
53
                }
54

55
                $minStatus = FileEntity::STATUS_SIGNED;
11✔
56
                $maxStatus = FileEntity::STATUS_DRAFT;
11✔
57

58
                foreach ($children as $child) {
11✔
59
                        $status = $child->getStatus();
11✔
60
                        if ($status < $minStatus) {
11✔
61
                                $minStatus = $status;
9✔
62
                        }
63
                        if ($status > $maxStatus) {
11✔
64
                                $maxStatus = $status;
10✔
65
                        }
66
                }
67

68
                $newStatus = FileEntity::STATUS_DRAFT;
11✔
69

70
                if ($minStatus === FileEntity::STATUS_SIGNED && $maxStatus === FileEntity::STATUS_SIGNED) {
11✔
71
                        $newStatus = FileEntity::STATUS_SIGNED;
2✔
72
                } elseif ($maxStatus >= FileEntity::STATUS_PARTIAL_SIGNED) {
9✔
73
                        $newStatus = FileEntity::STATUS_PARTIAL_SIGNED;
6✔
74
                } elseif ($maxStatus >= FileEntity::STATUS_ABLE_TO_SIGN) {
3✔
75
                        $newStatus = FileEntity::STATUS_ABLE_TO_SIGN;
2✔
76
                }
77

78
                if ($parent->getStatus() !== $newStatus) {
11✔
79
                        $parent->setStatus($newStatus);
9✔
80
                        $this->fileMapper->update($parent);
9✔
81
                }
82
        }
83

84
        public function updateFileStatus(FileEntity $file, int $newStatus): FileEntity {
NEW
85
                $file->setStatus($newStatus);
×
NEW
86
                $this->fileMapper->update($file);
×
87

NEW
88
                if ($file->hasParent()) {
×
NEW
89
                        $this->propagateStatusToParent($file->getParentFileId());
×
90
                }
91

NEW
92
                return $file;
×
93
        }
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc