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_Upgrade
9{
10	// old actually means current
11	private $old;
12	private $new;
13	private $isRequired;
14
15	function __construct($old, $new, $isRequired)
16	{
17		$this->old = Tiki_Version_Version::get($old);
18		$this->new = Tiki_Version_Version::get($new);
19		$this->isRequired = $isRequired;
20	}
21
22	function getMessage()
23	{
24		$parts = [];
25		if ($this->isRequired) {
26			$parts[] = tr('Version %0 is no longer supported.', (string) $this->old);
27
28			if ($this->isMinor()) {
29				$parts[] = tr('A minor upgrade to %0 is strongly recommended.', (string) $this->new);
30			} else {
31				$parts[] = tr('A major upgrade to %0 is strongly recommended.', (string) $this->new);
32			}
33		} else {
34			// Do not encourage people to leave an LTS which is still supported. Just inform them
35			$current = $this->old;
36			$current_major = (strstr($current, '.', true) != false) ? strstr($current, '.', true) : $current;
37			if (in_array($current_major, ['9','12','15'])) {	// Keep list of LTS up to date or write method isLTS, whichever is less work
38				$current = "$current LTS";
39				$parts[] = tr('Version %0 is still supported. However, an upgrade to %1 is available.', $current, (string) $this->new);
40			} else {
41				$parts[] = tr('Version %0 is still supported. However, a major upgrade to %1 is available.', (string) $this->old, (string) $this->new);
42			}
43		}
44
45		return implode(' ', $parts);
46	}
47
48	private function isMinor()
49	{
50		return $this->old->getMajor() === $this->new->getMajor();
51	}
52}
53