1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) Enalean, 2014. All Rights Reserved. |
4
|
|
|
* |
5
|
|
|
* This file is a part of Tuleap. |
6
|
|
|
* |
7
|
|
|
* Tuleap is free software; you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* Tuleap is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with Tuleap. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
class ArtifactAttachmentXMLLinker implements ArtifactAttachmentXMLExporter { |
22
|
|
|
|
23
|
|
|
/** @var ArtifactXMLNodeHelper */ |
24
|
|
|
private $node_helper; |
25
|
|
|
|
26
|
|
|
/** @var ArtifactXMLExporterDao */ |
27
|
|
|
private $dao; |
28
|
|
|
|
29
|
|
|
public function __construct(ArtifactXMLNodeHelper $node_helper, ArtifactXMLExporterDao $dao) { |
30
|
|
|
$this->node_helper = $node_helper; |
31
|
|
|
$this->dao = $dao; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function addFilesToArtifact(DOMElement $artifact_node, $artifact_type_id, $artifact_id) { |
35
|
|
|
$dar = $this->dao->searchFilesForArtifact($artifact_id); |
36
|
|
|
foreach($dar as $row) { |
|
|
|
|
37
|
|
|
$xml_file_id = ArtifactAttachmentFieldXMLExporter::XML_FILE_PREFIX.$row['id']; |
38
|
|
|
|
39
|
|
|
$file = $this->node_helper->createElement('file'); |
40
|
|
|
$file->setAttribute('id', $xml_file_id); |
41
|
|
|
$file->appendChild($this->node_helper->getNodeWithValue('filename', $row['filename'])); |
42
|
|
|
$file->appendChild($this->node_helper->getNodeWithValue('path', $this->getPathRelativeToTv3RootPath($artifact_type_id, $row['id']))); |
43
|
|
|
$file->appendChild($this->node_helper->getNodeWithValue('filesize', $row['filesize'])); |
44
|
|
|
$file->appendChild($this->node_helper->getNodeWithValue('filetype', $row['filetype'])); |
45
|
|
|
$file->appendChild($this->node_helper->getNodeWithValue('description', $row['description'])); |
46
|
|
|
$artifact_node->appendChild($file); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
private function getPathRelativeToTv3RootPath($artifact_type_id, $attachment_id) { |
51
|
|
|
$full_path = $this->getFilePathOnServer($artifact_type_id, $attachment_id); |
52
|
|
|
|
53
|
|
|
return dirname($full_path) . DIRECTORY_SEPARATOR . basename($full_path); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
private function getFilePathOnServer($artifact_type_id, $attachment_id) { |
57
|
|
|
return ArtifactFile::getPathOnFilesystemByArtifactTypeId($artifact_type_id, $attachment_id); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.