File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 \Exception \LibresignException ;
12+ use OCP \Files \Node ;
13+ use OCP \IUser ;
14+
15+ class EnvelopeFileRelocator {
16+ public function __construct (
17+ private FolderService $ folderService ,
18+ ) {
19+ }
20+
21+ public function ensureFileInEnvelopeFolder (Node $ sourceNode , int $ envelopeFolderId , IUser $ userManager ): Node {
22+ $ this ->folderService ->setUserId ($ userManager ->getUID ());
23+ $ userRootFolder = $ this ->folderService ->getUserRootFolder ();
24+ $ envelopeFolder = $ userRootFolder ->getFirstNodeById ($ envelopeFolderId );
25+
26+ if (!$ envelopeFolder instanceof \OCP \Files \Folder) {
27+ throw new LibresignException ('Envelope folder not found ' );
28+ }
29+
30+ if ($ this ->isNodeInsideFolder ($ sourceNode , $ envelopeFolder )) {
31+ return $ sourceNode ;
32+ }
33+
34+ if (!$ sourceNode instanceof \OCP \Files \File) {
35+ throw new LibresignException ('Invalid file type for envelope ' );
36+ }
37+
38+ return $ envelopeFolder ->newFile ($ sourceNode ->getName (), $ sourceNode ->getContent ());
39+ }
40+
41+ private function isNodeInsideFolder (Node $ node , \OCP \Files \Folder $ folder ): bool {
42+ return str_starts_with ($ node ->getPath (), $ folder ->getPath () . '/ ' );
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments