1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8class Tiki_Version_Utils
9{
10	/**
11	 * Validates if there are some updates for a given version of Tiki
12	 *
13	 * @param $version
14	 * @return array
15	 * @throws Exception
16	 */
17	static function checkUpdatesForVersion($version)
18	{
19		$tikilib = TikiLib::lib('tiki');
20
21		$checker = new Tiki_Version_Checker;
22		$checker->setVersion(Tiki_Version_Version::get($version));
23		$checker->setCycle($tikilib->get_preference('tiki_release_cycle'));
24
25		$expiry = $tikilib->now - $tikilib->get_preference('tiki_version_check_frequency');
26		$upgrades = $checker->check(
27			function ($url) use ($expiry) {
28				$cachelib = TikiLib::lib('cache');
29				$tikilib = TikiLib::lib('tiki');
30
31				$content = $cachelib->getCached($url, 'http', $expiry);
32
33				if ($content === false) {
34					$content = $tikilib->httprequest($url);
35					$cachelib->cacheItem($url, $content, 'http');
36				}
37
38				return $content;
39			}
40		);
41
42		return array_map(
43			function ($upgrade) {
44				return $upgrade->getMessage();
45			},
46			$upgrades
47		);
48	}
49}
50