‪TYPO3CMS  10.4
LinkNode.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
26 {
30  protected ‪$target = '';
31 
39  public function ‪__construct(array $structure, ‪NodeInterface ‪$parent = null)
40  {
41  if (‪$parent === null) {
43  'Link node must have parent',
44  1380485700
45  );
46  }
47  $this->parent = ‪$parent;
48 
49  // Ensure name is a single segment, but not a path like foo/bar or an absolute path /foo
50  if (strpos($structure['name'], '/') !== false) {
52  'File name must not contain forward slash',
53  1380546061
54  );
55  }
56  $this->name = $structure['name'];
57 
58  if (isset($structure['target']) && $structure['target'] !== '') {
59  $this->target = $structure['target'];
60  }
61  }
62 
71  public function ‪getStatus(): array
72  {
73  if ($this->‪isWindowsOs()) {
74  return [
75  new ‪FlashMessage(
76  'This node is not handled for Windows OS and should be checked manually.',
77  $this->‪getRelativePathBelowSiteRoot() . ' should be a link, but this support is incomplete for Windows.',
79  ),
80  ];
81  }
82 
83  if (!$this->‪exists()) {
84  return [
85  new ‪FlashMessage(
86  'Links cannot be fixed by this system',
87  $this->‪getRelativePathBelowSiteRoot() . ' should be a link, but it does not exist',
89  ),
90  ];
91  }
92 
93  if (!$this->‪isLink()) {
94  $type = @filetype($this->‪getAbsolutePath());
95  if ($type) {
96  $messageBody =
97  'The target ' . $this->‪getRelativePathBelowSiteRoot() . ' should be a link,' .
98  ' but is of type ' . $type . '. This cannot be fixed automatically. Please investigate.'
99  ;
100  } else {
101  $messageBody =
102  'The target ' . $this->‪getRelativePathBelowSiteRoot() . ' should be a file,' .
103  ' but is of unknown type, probably because an upper level directory does not exist. Please investigate.'
104  ;
105  }
106  return [
107  new ‪FlashMessage(
108  $messageBody,
109  'Path ' . $this->‪getRelativePathBelowSiteRoot() . ' is not a link',
111  ),
112  ];
113  }
114 
115  if (!$this->‪isTargetCorrect()) {
116  return [
117  new ‪FlashMessage(
118  'Link target should be ' . $this->‪getTarget() . ' but is ' . $this->‪getCurrentTarget(),
119  $this->‪getRelativePathBelowSiteRoot() . ' is a link, but link target is not as specified',
121  ),
122  ];
123  }
124  $message = 'Is a link';
125  if ($this->‪getTarget() !== '') {
126  $message .= ' and correctly points to target ' . $this->‪getTarget();
127  }
128  return [
129  new ‪FlashMessage(
130  $message,
132  ),
133  ];
134  }
135 
143  public function ‪fix(): array
144  {
145  return [];
146  }
147 
153  protected function ‪getTarget()
154  {
155  return ‪$this->target;
156  }
157 
164  protected function ‪isLink()
165  {
166  if (!$this->‪exists()) {
167  throw new ‪InvalidArgumentException(
168  'Link does not exist',
169  1380556246
170  );
171  }
172  return @is_link($this->‪getAbsolutePath());
173  }
174 
181  protected function ‪isTargetCorrect()
182  {
183  if (!$this->‪exists()) {
184  throw new ‪InvalidArgumentException(
185  'Link does not exist',
186  1380556245
187  );
188  }
189  if (!$this->‪isLink()) {
190  throw new ‪InvalidArgumentException(
191  'Node is not a link',
192  1380556247
193  );
194  }
195 
196  $result = false;
197  $expectedTarget = $this->‪getTarget();
198  if (empty($expectedTarget)) {
199  $result = true;
200  } else {
201  $actualTarget = $this->‪getCurrentTarget();
202  if ($expectedTarget === rtrim($actualTarget, '/')) {
203  $result = true;
204  }
205  }
206  return $result;
207  }
208 
214  protected function ‪getCurrentTarget()
215  {
216  return readlink($this->‪getAbsolutePath());
217  }
218 }
‪TYPO3\CMS\Install\FolderStructure\AbstractNode\exists
‪bool exists()
Definition: AbstractNode.php:126
‪TYPO3\CMS\Install\FolderStructure
Definition: AbstractNode.php:16
‪TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
Definition: InvalidArgumentException.php:24
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:30
‪TYPO3\CMS\Install\FolderStructure\AbstractNode\getRelativePathBelowSiteRoot
‪string getRelativePathBelowSiteRoot($path=null)
Definition: AbstractNode.php:207
‪TYPO3\CMS\Core\Messaging\AbstractMessage\INFO
‪const INFO
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪TYPO3\CMS\Install\FolderStructure\AbstractNode\getAbsolutePath
‪string getAbsolutePath()
Definition: AbstractNode.php:104
‪TYPO3\CMS\Install\FolderStructure\AbstractNode\$parent
‪NodeInterface null $parent
Definition: AbstractNode.php:38
‪TYPO3\CMS\Install\FolderStructure\AbstractNode
Definition: AbstractNode.php:27
‪TYPO3\CMS\Install\FolderStructure\AbstractNode\isWindowsOs
‪bool isWindowsOs()
Definition: AbstractNode.php:195
‪TYPO3\CMS\Install\FolderStructure\NodeInterface
Definition: NodeInterface.php:24
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31