1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2018, Roeland Jago Douma <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Roeland Jago Douma <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
namespace OCA\Richdocuments\Controller; |
24
|
|
|
|
25
|
|
|
use OCA\Richdocuments\Db\DirectMapper; |
26
|
|
|
use OCP\AppFramework\Http\DataResponse; |
27
|
|
|
use OCP\AppFramework\OCS\OCSBadRequestException; |
28
|
|
|
use OCP\AppFramework\OCS\OCSNotFoundException; |
29
|
|
|
use OCP\Files\Folder; |
30
|
|
|
use OCP\Files\IRootFolder; |
31
|
|
|
use OCP\Files\NotFoundException; |
32
|
|
|
use OCP\IRequest; |
33
|
|
|
use OCP\IURLGenerator; |
34
|
|
|
|
35
|
|
|
class OCSController extends \OCP\AppFramework\OCSController { |
36
|
|
|
/** @var IRootFolder */ |
37
|
|
|
private $rootFolder; |
38
|
|
|
|
39
|
|
|
/** @var string */ |
40
|
|
|
private $userId; |
41
|
|
|
|
42
|
|
|
/** @var DirectMapper */ |
43
|
|
|
private $directMapper; |
44
|
|
|
|
45
|
|
|
/** @var IURLGenerator */ |
46
|
|
|
private $urlGenerator; |
47
|
|
|
|
48
|
|
|
public function __construct($appName, |
49
|
|
|
IRequest $request, |
50
|
|
|
IRootFolder $rootFolder, |
51
|
|
|
$userId, |
52
|
|
|
DirectMapper $directMapper, |
53
|
|
|
IURLGenerator $urlGenerator) { |
54
|
|
|
parent::__construct($appName, $request); |
55
|
|
|
|
56
|
|
|
$this->rootFolder = $rootFolder; |
57
|
|
|
$this->userId = $userId; |
58
|
|
|
$this->directMapper = $directMapper; |
59
|
|
|
$this->urlGenerator = $urlGenerator; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @NoAdminRequired |
64
|
|
|
* |
65
|
|
|
* @param int $fileId |
66
|
|
|
*/ |
67
|
|
|
public function create($fileId) { |
68
|
|
|
try { |
69
|
|
|
$userFolder = $this->rootFolder->getUserFolder($this->userId); |
70
|
|
|
$nodes = $userFolder->getById($fileId); |
71
|
|
|
|
72
|
|
|
if ($nodes === []) { |
73
|
|
|
throw new NotFoundException(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$node = $nodes[0]; |
77
|
|
|
if ($node instanceof Folder) { |
|
|
|
|
78
|
|
|
throw new OCSBadRequestException('Cannot view folder'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
//TODO check if we can even edit this file with collabora |
82
|
|
|
|
83
|
|
|
$direct = $this->directMapper->newDirect($this->userId, $fileId); |
84
|
|
|
|
85
|
|
|
return new DataResponse([ |
86
|
|
|
'url' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.directView.show', [ |
87
|
|
|
'token' => $direct->getToken() |
88
|
|
|
]) |
89
|
|
|
]); |
90
|
|
|
} catch (NotFoundException $e) { |
|
|
|
|
91
|
|
|
throw new OCSNotFoundException(); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.