TYPO3 CMS  TYPO3_6-2
CoreVersionService.php
Go to the documentation of this file.
1 <?php
3 
19 
24 
29  protected $objectManager;
30 
35  protected $registry;
36 
42  protected $downloadBaseUri;
43 
47  public function getDownloadBaseUri() {
49  }
50 
54  public function __construct() {
55  $this->downloadBaseUri = 'https://get.typo3.org/';
56  }
57 
64  public function updateVersionMatrix() {
65  $versionArray = $this->fetchVersionMatrixFromRemote();
66  // This is a 'hack' to keep the string stored in the registry small. We are usually only
67  // interested in information from 6.2 and up and older releases do not matter in current
68  // use cases. If this unset() is removed and everything is stored for some reason, the
69  // table sys_file field entry_value needs to be extended from blob to longblob.
70  unset($versionArray['6.1'], $versionArray['6.0'], $versionArray['4.7'], $versionArray['4.6'],
71  $versionArray['4.5'], $versionArray['4.4'], $versionArray['4.3'], $versionArray['4.2'],
72  $versionArray['4.1'], $versionArray['4.0'], $versionArray['3.8'], $versionArray['3.7'],
73  $versionArray['3.6'], $versionArray['3.5'], $versionArray['3.3']);
74  $this->registry->set('TYPO3.CMS.Install', 'coreVersionMatrix', $versionArray);
75  }
76 
84  $version = $this->getInstalledVersion();
85  return substr($version, -4) !== '-dev';
86  }
87 
95  public function getTarGzSha1OfVersion($version) {
96  $this->ensureVersionExistsInMatrix($version);
97 
98  $minorVersion = $this->getMinorVersion($version);
99  $versionMatrix = $this->getVersionMatrix();
100 
101  if (empty($versionMatrix[$minorVersion]['releases'][$version]['checksums']['tar']['sha1'])) {
102  throw new Exception\CoreVersionServiceException(
103  'Release sha1 of version ' . $version . ' not found in version matrix.'
104  . ' This is probably a bug on get.typo3.org.',
105  1381263173
106  );
107  }
108 
109  return $versionMatrix[$minorVersion]['releases'][$version]['checksums']['tar']['sha1'];
110  }
111 
117  public function getInstalledVersion() {
119  }
120 
126  public function isYoungerPatchReleaseAvailable() {
127  $result = FALSE;
128  $version = $this->getInstalledVersion();
129  $youngestVersion = $this->getYoungestPatchRelease();
130  if ($youngestVersion !== $version) {
131  $result = TRUE;
132  }
133  return $result;
134  }
135 
142  $result = FALSE;
143  $version = $this->getInstalledVersion();
144  $youngestVersion = $this->getYoungestPatchDevelopmentRelease();
145  if ($youngestVersion !== $version) {
146  $result = TRUE;
147  }
148  return $result;
149  }
150 
156  public function isUpdateSecurityRelevant() {
157  $result = FALSE;
158  $version = $this->getInstalledVersion();
159  $youngestVersion = $this->getYoungestReleaseByType(array('security'));
160  if ($youngestVersion !== $version) {
161  $result = TRUE;
162  }
163  return $result;
164  }
165 
171  public function getYoungestPatchRelease() {
172  return $this->getYoungestReleaseByType(array('release', 'security', 'regular'));
173  }
174 
181  return $this->getYoungestReleaseByType(array('release', 'security', 'regular', 'development'));
182  }
183 
192  protected function getYoungestReleaseByType(array $types) {
193  $version = $this->getInstalledVersion();
194 
195  $minorVersion = $this->getMinorVersion($version);
196  $versionMatrix = $this->getVersionMatrix();
197 
198  $youngestRelease = $version;
199  $versionReleaseTimestamp = $this->getReleaseTimestampOfVersion($version);
200 
201  $patchLevelVersions = $versionMatrix[$minorVersion]['releases'];
202  foreach ($patchLevelVersions as $aVersionNumber => $aVersionDetails) {
203  if (!array_key_exists('type', $aVersionDetails)) {
204  throw new Exception\CoreVersionServiceException(
205  'Release type of version ' . $aVersionNumber . ' not found in version matrix.'
206  . ' This is probably a bug on get.typo3.org.',
207  1380909029
208  );
209  }
210  $type = $aVersionDetails['type'];
211  $aVersionNumberReleaseTimestamp = $this->getReleaseTimestampOfVersion($aVersionNumber);
212  if (
213  $aVersionNumberReleaseTimestamp > $versionReleaseTimestamp
214  && in_array($type, $types)
215  ) {
216  $youngestRelease = $aVersionNumber;
217  $versionReleaseTimestamp = $aVersionNumberReleaseTimestamp;
218  }
219  }
220  return $youngestRelease;
221  }
222 
228  protected function getInstalledMinorVersion() {
229  return $this->getMinorVersion($this->getInstalledVersion());
230  }
231 
238  protected function getMinorVersion($version) {
239  $explodedVersion = explode('.', $version);
240  $minor = explode('-', $explodedVersion[1]);
241  return $explodedVersion[0] . '.' . $minor[0];
242  }
243 
250  protected function getVersionMatrix() {
251  $versionMatrix = $this->registry->get('TYPO3.CMS.Install', 'coreVersionMatrix');
252  if (empty($versionMatrix) || !is_array($versionMatrix)) {
253  throw new Exception\CoreVersionServiceException(
254  'No version matrix found in registry, call updateVersionMatrix() first.',
255  1380898792
256  );
257  }
258  return $versionMatrix;
259  }
260 
267  protected function fetchVersionMatrixFromRemote() {
268  $url = $this->downloadBaseUri . 'json';
269  $versionJson = GeneralUtility::getUrl($url);
270  if (!$versionJson) {
271  throw new Exception\RemoteFetchException(
272  'Fetching ' . $url . ' failed. Maybe this instance can not connect to the remote system properly.',
273  1380897593
274  );
275  }
276  return json_decode($versionJson, TRUE);
277  }
278 
286  protected function getReleaseTimestampOfVersion($version) {
287  $minorVersion = $this->getMinorVersion($version);
288  $versionMatrix = $this->getVersionMatrix();
289  $this->ensureVersionExistsInMatrix($version);
290  if (!array_key_exists('date', $versionMatrix[$minorVersion]['releases'][$version])) {
291  throw new Exception\CoreVersionServiceException(
292  'Release date of version ' . $version . ' not found in version matrix. This is probably a bug on get.typo3.org',
293  1380905853
294  );
295  }
296  $dateString = $versionMatrix[$minorVersion]['releases'][$version]['date'];
297  $date = new \DateTime($dateString);
298  return $date->getTimestamp();
299  }
300 
307  protected function ensureVersionExistsInMatrix($version) {
308  $minorVersion = $this->getMinorVersion($version);
309  $versionMatrix = $this->getVersionMatrix();
310  if (!array_key_exists($minorVersion, $versionMatrix)) {
311  throw new Exception\CoreVersionServiceException(
312  'Minor release ' . $minorVersion . ' not found in version matrix.',
313  1380905851
314  );
315  }
316  if (!array_key_exists($version, $versionMatrix[$minorVersion]['releases'])) {
317  throw new Exception\CoreVersionServiceException(
318  'Patch level release ' . $version . ' not found in version matrix.',
319  1380905852
320  );
321  }
322  }
323 }
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
static getUrl($url, $includeHeader=0, $requestHeaders=FALSE, &$report=NULL)