Commit 0e66ae12 authored by Tino Goratsch's avatar Tino Goratsch

Merge branch 'release/v4.6.0'

parents 8acbbc22 2d4db06f
......@@ -14,7 +14,7 @@ interface BootstrapInterface extends HttpKernelInterface
/**
* Contains the current ACP3 version string
*/
const VERSION = '4.5.0';
const VERSION = '4.6.0';
/**
* Performs some startup checks
......
......@@ -5,12 +5,7 @@ namespace ACP3\Core;
use ACP3\Core\Date\DateTranslator;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\System\Installer\Schema;
use ACP3\Modules\ACP3\Users\Model\UserModel;
/**
* Class Date
* @package ACP3\Core
*/
class Date
{
const DEFAULT_DATE_FORMAT_LONG = 'Y-m-d H:i';
......@@ -41,37 +36,26 @@ class Date
/**
* Date constructor.
* @param UserModel $user
* @param DateTranslator $dateTranslator
* @param SettingsInterface $config
*/
public function __construct(
UserModel $user,
DateTranslator $dateTranslator,
SettingsInterface $config
) {
$this->dateTranslator = $dateTranslator;
$this->config = $config;
$this->setFormatAndTimeZone($user->getUserInfo());
$this->setFormatAndTimeZone();
}
/**
* @param array $userInfo
*/
protected function setFormatAndTimeZone(array $userInfo = [])
protected function setFormatAndTimeZone()
{
if (!empty($userInfo)) {
$this->dateFormatLong = $userInfo['date_format_long'];
$this->dateFormatShort = $userInfo['date_format_short'];
$timeZone = $userInfo['time_zone'];
} else {
$settings = $this->config->getSettings(Schema::MODULE_NAME);
$this->dateFormatLong = $settings['date_format_long'];
$this->dateFormatShort = $settings['date_format_short'];
$timeZone = $settings['date_time_zone'];
}
$settings = $this->config->getSettings(Schema::MODULE_NAME);
$this->dateFormatLong = $settings['date_format_long'];
$this->dateFormatShort = $settings['date_format_short'];
$timeZone = $settings['date_time_zone'];
$this->dateTimeZone = new \DateTimeZone($timeZone);
}
......@@ -120,8 +104,8 @@ class Date
*
* @param string $time
* @param string $format
* @param bool $toLocalTimeZone
* @param bool $isLocalTimeZone
* @param bool $toLocalTimeZone
* @param bool $isLocalTimeZone
*
* @return string
*/
......@@ -156,7 +140,7 @@ class Date
* Gibt einen einfachen Zeitstempel zurück, welcher sich an UTC ausrichtet
*
* @param string $value
* @param bool $isLocalTime
* @param bool $isLocalTime
*
* @return int
*/
......@@ -193,7 +177,7 @@ class Date
* Konvertiert einen Unixstamp in das MySQL-Datetime Format
*
* @param string $value
* @param bool $isLocalTime
* @param bool $isLocalTime
*
* @return string
*/
......
<?php
namespace ACP3\Core\Helpers;
/**
* Class Country
* @package ACP3\Core\Helpers
*/
class Country
{
/**
* Returns an array with all countries on earth
*
* @return array
*/
public static function worldCountries()
{
return [
'AU' => 'Australia',
'AF' => 'Afghanistan',
'AL' => 'Albania',
'DZ' => 'Algeria',
'AS' => 'American Samoa',
'AD' => 'Andorra',
'AO' => 'Angola',
'AI' => 'Anguilla',
'AQ' => 'Antarctica',
'AG' => 'Antigua & Barbuda',
'AR' => 'Argentina',
'AM' => 'Armenia',
'AW' => 'Aruba',
'AT' => 'Austria',
'AZ' => 'Azerbaijan',
'BS' => 'Bahamas',
'BH' => 'Bahrain',
'BD' => 'Bangladesh',
'BB' => 'Barbados',
'BY' => 'Belarus',
'BE' => 'Belgium',
'BZ' => 'Belize',
'BJ' => 'Benin',
'BM' => 'Bermuda',
'BT' => 'Bhutan',
'BO' => 'Bolivia',
'BA' => 'Bosnia/Hercegovina',
'BW' => 'Botswana',
'BV' => 'Bouvet Island',
'BR' => 'Brazil',
'IO' => 'British Indian Ocean Territory',
'BN' => 'Brunei Darussalam',
'BG' => 'Bulgaria',
'BF' => 'Burkina Faso',
'BI' => 'Burundi',
'KH' => 'Cambodia',
'CM' => 'Cameroon',
'CA' => 'Canada',
'CV' => 'Cape Verde',
'KY' => 'Cayman Is',
'CF' => 'Central African Republic',
'TD' => 'Chad',
'CL' => 'Chile',
'CN' => 'China, People\'s Republic of',
'CX' => 'Christmas Island',
'CC' => 'Cocos Islands',
'CO' => 'Colombia',
'KM' => 'Comoros',
'CG' => 'Congo',
'CD' => 'Congo, Democratic Republic',
'CK' => 'Cook Islands',
'CR' => 'Costa Rica',
'CI' => 'Cote d\'Ivoire',
'HR' => 'Croatia',
'CU' => 'Cuba',
'CY' => 'Cyprus',
'CZ' => 'Czech Republic',
'DK' => 'Denmark',
'DJ' => 'Djibouti',
'DM' => 'Dominica',
'DO' => 'Dominican Republic',
'TP' => 'East Timor',
'EC' => 'Ecuador',
'EG' => 'Egypt',
'SV' => 'El Salvador',
'GQ' => 'Equatorial Guinea',
'ER' => 'Eritrea',
'EE' => 'Estonia',
'ET' => 'Ethiopia',
'FK' => 'Falkland Islands',
'FO' => 'Faroe Islands',
'FJ' => 'Fiji',
'FI' => 'Finland',
'FR' => 'France',
'FX' => 'France, Metropolitan',
'GF' => 'French Guiana',
'PF' => 'French Polynesia',
'TF' => 'French South Territories',
'GA' => 'Gabon',
'GM' => 'Gambia',
'GE' => 'Georgia',
'DE' => 'Germany',
'GH' => 'Ghana',
'GI' => 'Gibraltar',
'GR' => 'Greece',
'GL' => 'Greenland',
'GD' => 'Grenada',
'GP' => 'Guadeloupe',
'GU' => 'Guam',
'GT' => 'Guatemala',
'GN' => 'Guinea',
'GW' => 'Guinea-Bissau',
'GY' => 'Guyana',
'HT' => 'Haiti',
'HM' => 'Heard Island And Mcdonald Island',
'HN' => 'Honduras',
'HK' => 'Hong Kong',
'HU' => 'Hungary',
'IS' => 'Iceland',
'IN' => 'India',
'ID' => 'Indonesia',
'IR' => 'Iran',
'IQ' => 'Iraq',
'IE' => 'Ireland',
'IL' => 'Israel',
'IT' => 'Italy',
'JM' => 'Jamaica',
'JP' => 'Japan',
'JT' => 'Johnston Island',
'JO' => 'Jordan',
'KZ' => 'Kazakhstan',
'KE' => 'Kenya',
'KI' => 'Kiribati',
'KP' => 'Korea, Democratic Peoples Republic',
'KR' => 'Korea, Republic of',
'KW' => 'Kuwait',
'KG' => 'Kyrgyzstan',
'LA' => 'Lao People\'s Democratic Republic',
'LV' => 'Latvia',
'LB' => 'Lebanon',
'LS' => 'Lesotho',
'LR' => 'Liberia',
'LY' => 'Libyan Arab Jamahiriya',
'LI' => 'Liechtenstein',
'LT' => 'Lithuania',
'LU' => 'Luxembourg',
'MO' => 'Macau',
'MK' => 'Macedonia',
'MG' => 'Madagascar',
'MW' => 'Malawi',
'MY' => 'Malaysia',
'MV' => 'Maldives',
'ML' => 'Mali',
'MT' => 'Malta',
'MH' => 'Marshall Islands',
'MQ' => 'Martinique',
'MR' => 'Mauritania',
'MU' => 'Mauritius',
'YT' => 'Mayotte',
'MX' => 'Mexico',
'FM' => 'Micronesia',
'MD' => 'Moldavia',
'MC' => 'Monaco',
'MN' => 'Mongolia',
'MS' => 'Montserrat',
'MA' => 'Morocco',
'MZ' => 'Mozambique',
'MM' => 'Union Of Myanmar',
'NA' => 'Namibia',
'NR' => 'Nauru Island',
'NP' => 'Nepal',
'NL' => 'Netherlands',
'AN' => 'Netherlands Antilles',
'NC' => 'New Caledonia',
'NZ' => 'New Zealand',
'NI' => 'Nicaragua',
'NE' => 'Niger',
'NG' => 'Nigeria',
'NU' => 'Niue',
'NF' => 'Norfolk Island',
'MP' => 'Mariana Islands, Northern',
'NO' => 'Norway',
'OM' => 'Oman',
'PK' => 'Pakistan',
'PW' => 'Palau Islands',
'PS' => 'Palestine',
'PA' => 'Panama',
'PG' => 'Papua New Guinea',
'PY' => 'Paraguay',
'PE' => 'Peru',
'PH' => 'Philippines',
'PN' => 'Pitcairn',
'PL' => 'Poland',
'PT' => 'Portugal',
'PR' => 'Puerto Rico',
'QA' => 'Qatar',
'RE' => 'Reunion Island',
'RO' => 'Romania',
'RU' => 'Russian Federation',
'RW' => 'Rwanda',
'WS' => 'Samoa',
'SH' => 'St Helena',
'KN' => 'St Kitts & Nevis',
'LC' => 'St Lucia',
'PM' => 'St Pierre & Miquelon',
'VC' => 'St Vincent',
'SM' => 'San Marino',
'ST' => 'Sao Tome & Principe',
'SA' => 'Saudi Arabia',
'SN' => 'Senegal',
'SC' => 'Seychelles',
'SL' => 'Sierra Leone',
'SG' => 'Singapore',
'SK' => 'Slovakia',
'SI' => 'Slovenia',
'SB' => 'Solomon Islands',
'SO' => 'Somalia',
'ZA' => 'South Africa',
'GS' => 'South Georgia and South Sandwich',
'ES' => 'Spain',
'LK' => 'Sri Lanka',
'XX' => 'Stateless Persons',
'SD' => 'Sudan',
'SR' => 'Suriname',
'SJ' => 'Svalbard and Jan Mayen',
'SZ' => 'Swaziland',
'SE' => 'Sweden',
'CH' => 'Switzerland',
'SY' => 'Syrian Arab Republic',
'TW' => 'Taiwan, Republic of China',
'TJ' => 'Tajikistan',
'TZ' => 'Tanzania',
'TH' => 'Thailand',
'TL' => 'Timor Leste',
'TG' => 'Togo',
'TK' => 'Tokelau',
'TO' => 'Tonga',
'TT' => 'Trinidad & Tobago',
'TN' => 'Tunisia',
'TR' => 'Turkey',
'TM' => 'Turkmenistan',
'TC' => 'Turks And Caicos Islands',
'TV' => 'Tuvalu',
'UG' => 'Uganda',
'UA' => 'Ukraine',
'AE' => 'United Arab Emirates',
'GB' => 'United Kingdom',
'UM' => 'US Minor Outlying Islands',
'US' => 'USA',
'HV' => 'Upper Volta',
'UY' => 'Uruguay',
'UZ' => 'Uzbekistan',
'VU' => 'Vanuatu',
'VA' => 'Vatican City State',
'VE' => 'Venezuela',
'VN' => 'Vietnam',
'VG' => 'Virgin Islands (British)',
'VI' => 'Virgin Islands (US)',
'WF' => 'Wallis And Futuna Islands',
'EH' => 'Western Sahara',
'YE' => 'Yemen Arab Rep.',
'YD' => 'Yemen Democratic',
'YU' => 'Yugoslavia',
'ZR' => 'Zaire',
'ZM' => 'Zambia',
'ZW' => 'Zimbabwe'
];
}
}
<?php
/**
* Copyright (c) 2017 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\I18n;
class CountryList
{
/**
* @var Translator
*/
private $translator;
/**
* Country constructor.
* @param Translator $translator
*/
public function __construct(Translator $translator)
{
$this->translator = $translator;
}
/**
* Returns an array with all earth countries
*
* @return array
*/
public function worldCountries()
{
$path = ACP3_ROOT_DIR . 'vendor/umpirsky/country-list/data/' . $this->translator->getLocale() . '/country.json';
if (preg_match('/^[a-z]{2}_[A-Z]{2}/', $this->translator->getLocale()) && is_file($path)) {
$countries = file_get_contents($path);
return json_decode($countries, true);
}
return [];
}
}
......@@ -5,18 +5,9 @@ use ACP3\Core\Environment\ApplicationPath;
use ACP3\Core\I18n\DictionaryCache as LanguageCache;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\System\Installer\Schema;
use ACP3\Modules\ACP3\Users\Model\UserModel;
/**
* Class Translator
* @package ACP3\Core\I18n
*/
class Translator
{
/**
* @var \ACP3\Modules\ACP3\Users\Model\UserModel
*/
protected $user;
/**
* @var \ACP3\Core\Environment\ApplicationPath
*/
......@@ -50,18 +41,15 @@ class Translator
/**
* Translator constructor.
* @param UserModel $user
* @param ApplicationPath $appPath
* @param DictionaryCache $dictionaryCache
* @param SettingsInterface $config
*/
public function __construct(
UserModel $user,
ApplicationPath $appPath,
LanguageCache $dictionaryCache,
SettingsInterface $config
) {
$this->user = $user;
$this->appPath = $appPath;
$this->dictionaryCache = $dictionaryCache;
$this->config = $config;
......@@ -86,10 +74,7 @@ class Translator
public function getLocale()
{
if ($this->locale === '') {
$locale = $this->user->getLanguage();
$this->locale = $this->languagePackExists($locale) === true
? $locale
: $this->config->getSettings(Schema::MODULE_NAME)['lang'];
$this->locale = $this->config->getSettings(Schema::MODULE_NAME)['lang'];
}
return $this->locale;
......
......@@ -6,10 +6,6 @@
namespace ACP3\Core\Session;
/**
* Class AbstractSessionHandler
* @package ACP3\Core\Session
*/
abstract class AbstractSessionHandler implements SessionHandlerInterface
{
/**
......@@ -19,25 +15,32 @@ abstract class AbstractSessionHandler implements SessionHandlerInterface
/**
* @var integer
*/
protected $gcProbability = 10;
protected $gcProbability = 1;
/**
* @var int
*/
protected $gcDivisor = 100;
/**
* Configures the session
* @param bool $isSecure
*/
protected function configureSession()
protected function configureSession($isSecure = false)
{
if (session_status() == PHP_SESSION_NONE) {
// Configure the php.ini session settings
ini_set('session.name', self::SESSION_NAME);
ini_set('session.use_trans_sid', 0);
ini_set('session.use_cookies', 1);
ini_set('session.use_only_cookies', 1);
ini_set('session.cookie_httponly', 1);
ini_set('session.use_cookies', 'on');
ini_set('session.use_only_cookies', 'on');
ini_set('session.cookie_httponly', 'on');
ini_set('session.use_strict_mode', 'on');
ini_set('session.cookie_secure', $isSecure ? 'on' : 'off');
// Session GC
ini_set('session.gc_maxlifetime', $this->expireTime);
ini_set('session.gc_probability', $this->gcProbability);
ini_set('session.gc_divisor', 100);
ini_set('session.gc_divisor', $this->gcDivisor);
// Set our own session handling methods
ini_set('session.save_handler', 'user');
......
......@@ -12,9 +12,6 @@ use ACP3\Core\Http\RequestInterface;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Response;
/**
* @package ACP3\Core
*/
class SessionHandler extends AbstractSessionHandler
{
/**
......@@ -55,7 +52,7 @@ class SessionHandler extends AbstractSessionHandler
$this->request = $request;
$this->response = $response;
$this->configureSession();
$this->configureSession($this->request->getSymfonyRequest()->isSecure());
}
/**
......@@ -105,7 +102,7 @@ class SessionHandler extends AbstractSessionHandler
$this->gcCalled = false;
$this->db->getConnection()->executeUpdate(
"DELETE FROM `{$this->db->getPrefix()}sessions` WHERE `session_starttime` + ? < ?",
"DELETE FROM `{$this->db->getPrefix()}sessions` WHERE `session_starttime` + ? < ?;",
[$this->expireTime, time()]
);
}
......@@ -127,7 +124,7 @@ class SessionHandler extends AbstractSessionHandler
public function read($sessionId)
{
$session = $this->db->fetchColumn(
"SELECT `session_data` FROM `{$this->db->getPrefix()}sessions` WHERE `session_id` = ?",
"SELECT `session_data` FROM `{$this->db->getPrefix()}sessions` WHERE `session_id` = ?;",
[$sessionId]
);
......@@ -140,7 +137,7 @@ class SessionHandler extends AbstractSessionHandler
public function write($sessionId, $data)
{
$this->db->getConnection()->executeUpdate(
"INSERT INTO `{$this->db->getPrefix()}sessions` (`session_id`, `session_starttime`, `session_data`) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE `session_data` = ?",
"INSERT INTO `{$this->db->getPrefix()}sessions` (`session_id`, `session_starttime`, `session_data`) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE `session_data` = ?;",
[$sessionId, time(), $data, $data]
);
......
......@@ -8,7 +8,6 @@ use ACP3\Core\Helpers\DataGrid\ColumnRenderer\DateColumnRenderer;
use ACP3\Core\Helpers\Formatter\DateRange;
use ACP3\Core\I18n\Translator;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\Users\Model\UserModel;
class DateColumnRendererTest extends AbstractColumnRendererTest
{
......@@ -16,10 +15,6 @@ class DateColumnRendererTest extends AbstractColumnRendererTest
* @var Translator|\PHPUnit_Framework_MockObject_MockObject
*/
protected $langMock;
/**
* @var UserModel|\PHPUnit_Framework_MockObject_MockObject
*/
protected $userMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
......@@ -44,24 +39,20 @@ class DateColumnRendererTest extends AbstractColumnRendererTest
->setMethods(['t'])
->getMock();
$this->dateTranslator = new DateTranslator($this->langMock);
$this->userMock = $this->getMockBuilder(UserModel::class)
->disableOriginalConstructor()
->getMock();
$this->configMock = $this->getMockBuilder(SettingsInterface::class)
->disableOriginalConstructor()
->setMethods(['getSettings', 'saveSettings'])
->getMock();
$this->userMock->expects($this->once())
->method('getUserInfo')
$this->configMock->expects($this->once())
->method('getSettings')
->willReturn([
'date_format_long' => 'Y-m-d H:i',
'date_format_short' => 'Y-m-d',
'time_zone' => 'Europe/Berlin',
'date_time_zone' => 'Europe/Berlin',
]);
$this->date = new Date(
$this->userMock,
$this->dateTranslator,
$this->configMock
);
......
......@@ -7,7 +7,6 @@ use ACP3\Core\Date\DateTranslator;
use ACP3\Core\Helpers\Formatter\DateRange;
use ACP3\Core\I18n\Translator;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\Users\Model\UserModel;
class DateRangeTest extends \PHPUnit_Framework_TestCase
{
......@@ -27,11 +26,6 @@ class DateRangeTest extends \PHPUnit_Framework_TestCase
* @var Translator|\PHPUnit_Framework_MockObject_MockObject
*/
private $langMock;
/**
* @var UserModel|\PHPUnit_Framework_MockObject_MockObject
*/
private $userMock;
/**
* @var DateRange
*/
......@@ -43,26 +37,22 @@ class DateRangeTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor()
->setMethods(['t'])
->getMock();
$this->userMock = $this->getMockBuilder(UserModel::class)
->disableOriginalConstructor()
->getMock();
$this->configMock = $this->getMockBuilder(SettingsInterface::class)
->disableOriginalConstructor()
->setMethods(['getSettings', 'saveSettings'])
->getMock();
$this->userMock->expects($this->once())
->method('getUserInfo')
$this->configMock->expects($this->once())
->method('getSettings')
->willReturn([
'date_format_long' => 'Y-m-d H:i',
'date_format_short' => 'Y-m-d',
'time_zone' => 'Europe/Berlin',
'date_time_zone' => 'Europe/Berlin',
]);
$this->dateTranslator = new DateTranslator($this->langMock);
$this->date = new Date(
$this->userMock,
$this->dateTranslator,
$this->configMock
);
......
<?php
/**
* Copyright (c) 2017 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Test\I18n;
use ACP3\Core\I18n\CountryList;
use ACP3\Core\I18n\Translator;
class CountryListTest extends \PHPUnit_Framework_TestCase
{
/**
* @var CountryList
*/
private $countryList;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $translatorMock;
protected function setUp()
{
$this->translatorMock = $this->getMockBuilder(Translator::class)
->disableOriginalConstructor()
->setMethods(['getLocale'])
->getMock();
$this->countryList = new CountryList($this->translatorMock);
}
public function testValidLocale()
{
$this->translatorMock->expects($this->exactly(2))
->method('getLocale')
->willReturn('en_US');
$actual = $this->countryList->worldCountries();
$this->assertTrue(is_array($actual));
$this->assertNotEmpty($actual);
}
public function testInvalidLocaleByPath()
{
$this->translatorMock->expects($this->exactly(2))