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