Skip to content

Commit

Permalink
Pimcore 6.5, PHP 7.4 matrix added (#50)
Browse files Browse the repository at this point in the history
* Pimcore 6.4, PHP 7.4 matrix added
* improve geo db fetcher and array index availability
* assert server variable for tests
* fix notice errors
* add conflict for p6.4
* adjust readme
* set error reporting
* fix tests
  • Loading branch information
solverat committed Feb 24, 2020
1 parent ecac35a commit 2cf2829
Show file tree
Hide file tree
Showing 25 changed files with 171 additions and 43 deletions.
35 changes: 22 additions & 13 deletions .travis.yml
Expand Up @@ -21,19 +21,20 @@ env:
- SYMFONY_DEPRECATIONS_HELPER=weak
- DACHCOM_TEST_SECTION=codeception
- SYMFONY_VERSION=^4.0
- PIMCORE_PHP_ERROR_REPORTING=32767 # E_ALL
matrix:
include:
- name: "PHPStan Static Analysis (Pimcore 6.3.x, Symfony ^4.0, PHP 7.3)"
- name: "PHPStan Static Analysis (Pimcore 6.5.x, Symfony ^4.0, PHP 7.4)"
sudo: required
php: 7.3
php: 7.4
env:
- PIMCORE_SKELETON_BRANCH="tags/v2.3.0"
- PIMCORE_SKELETON_BRANCH="tags/v2.5.0"
- DACHCOM_TEST_SECTION=phpstan
- name: "PHP ECS (Pimcore 6.3.x, Symfony ^4.0, PHP 7.3)"
- name: "PHP ECS (Pimcore 6.5.x, Symfony ^4.0, PHP 7.4)"
sudo: required
php: 7.3
php: 7.4
env:
- PIMCORE_SKELETON_BRANCH="tags/v2.3.0"
- PIMCORE_SKELETON_BRANCH="tags/v2.5.0"
- DACHCOM_TEST_SECTION=ecs
- name: "Codeception Tests (Pimcore 6.0.x, Symfony ^4.3, PHP 7.3)"
sudo: required
Expand All @@ -53,25 +54,33 @@ matrix:
env:
- SYMFONY_VERSION="~4.3.0"
- PIMCORE_SKELETON_BRANCH="tags/v2.2.0"
- name: "Codeception Tests (Pimcore 6.3.x, Symfony ^4.0, PHP 7.2)"
- name: "Codeception Tests (Pimcore 6.3.x, Symfony ^4.0, PHP 7.3)"
sudo: required
php: 7.2
php: 7.3
env:
- PIMCORE_SKELETON_BRANCH="tags/v2.3.0"
- name: "Codeception Tests (Pimcore 6.3.x, Symfony ^4.0, PHP 7.3)"
- name: "Codeception Tests (Pimcore 6.5.x, Symfony ^4.0, PHP 7.3)"
sudo: required
php: 7.3
env:
- PIMCORE_SKELETON_BRANCH="tags/v2.3.0"
- name: "Codeception Tests (Pimcore 6.3.x, Symfony ^3.4, PHP 7.3)"
- PIMCORE_PHP_ERROR_REPORTING=30711 # E_ALL & ~E_NOTICE & ~E_STRICT: remove this after 6.5.2
- PIMCORE_SKELETON_BRANCH="tags/v2.5.0"
- name: "Codeception Tests (Pimcore 6.5.x, Symfony ^3.4, PHP 7.3)"
sudo: required
php: 7.3
env:
- SYMFONY_VERSION=^3.4
- PIMCORE_SKELETON_BRANCH="tags/v2.3.0"
- PIMCORE_PHP_ERROR_REPORTING=30711 # E_ALL & ~E_NOTICE & ~E_STRICT: remove this after 6.5.2
- PIMCORE_SKELETON_BRANCH="tags/v2.5.0"
- name: "Codeception Tests (Pimcore 6.5.x, Symfony ^4.0, PHP 7.4)"
sudo: required
php: 7.4
env:
- PIMCORE_PHP_ERROR_REPORTING=30711 # E_ALL & ~E_NOTICE & ~E_STRICT: remove this after 6.5.2
- PIMCORE_SKELETON_BRANCH="tags/v2.5.0"
allow_failures:
- env:
- PIMCORE_SKELETON_BRANCH="tags/v2.3.0"
- PIMCORE_SKELETON_BRANCH="tags/v2.5.0"
- DACHCOM_TEST_SECTION=ecs
fast_finish: true

Expand Down
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -15,14 +15,14 @@ This Bundle helps you mastering this challenges and gives you the freedom to ela

| Release | Supported Pimcore Versions | Supported Symfony Versions | Release Date | Maintained | Branch |
|---------|-----------------------------------|----------------------------|--------------|----------------|------------|
| **3.x** | `6.0` - `6.3` | `3.4`, `^4.0` | 18.07.2019 | Feature Branch | dev-master |
| **3.x** | `6.0` - `6.3`, `6.5` | `3.4`, `^4.0` | 18.07.2019 | Feature Branch | dev-master |
| **2.4** | `5.4`, `5.5`, `5.6`, `5.7`, `5.8` | `3.4` | 24.05.2019 | Bugfix only | 2.4 |

### Installation

```json
"require" : {
"dachcom-digital/i18n" : "~3.1.0"
"dachcom-digital/i18n" : "~3.2.0"
}
```

Expand Down Expand Up @@ -56,8 +56,10 @@ Does actually the same as the update command and preferred in CI-Workflow:
### Preparation
- If you're using `system` as your `locale_adapter`, which is the default, you need to enable all required locales in pimcore system settings
- Always be sure that every document translation is connected via the [localization tool](https://www.pimcore.org/docs/5.0.0/Multi_Language_i18n/Localize_your_Documents.html).
- If you're using the country detection, you need a valid maxmind geoip [data provider](docs/10_GeoControl.md)

## Further Information
- [Geo IP/Control](docs/10_GeoControl.md): Enable GeoIP Data Provider.
- [Zones](docs/20_Zones.md): Learn more about i18n zones and how to manage them.
- [Href-Lang](docs/25_HrefLang.md): Find out more about the href-lang tag generator.
- [Language Configuration](docs/26_Languages.md): Configure languages.
Expand Down
6 changes: 6 additions & 0 deletions UPGRADE.md
Expand Up @@ -6,6 +6,12 @@
After every update you should check the pimcore extension manager.
Just click the "update" button or execute the migration command to finish the bundle update.

#### Update from Version 3.1.x to Version 3.2.0
- **[ENHANCEMENT]**: Pimcore 6.5.0 ready
- **[ENHANCEMENT]**: PHP 7.4 Support
- **[IMPORTANT]**: Because of unfixed major issues within Pimcore 6.4.x, we're unable to support this version. We recommend to directly upgrade to pimcore 6.5!
- **[IMPORTANT]**: GeoLite Database is not available automatically due new download restrictions by maxmind. Read more about it [here](./docs/10_GeoControl.md), [here](https://github.com/pimcore/pimcore/issues/5512) and [here](https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-geolite2-databases/)

#### Update from Version 3.1.0 to Version 3.1.1
- **[ENHANCEMENT]**: Use locale instead of languageIso in [Document PathGenerator](https://github.com/dachcom-digital/pimcore-i18n/issues/41)
- **[NEW FEATURE]**: Respect [LinkGenerator](https://github.com/dachcom-digital/pimcore-i18n/issues/15)
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Expand Up @@ -13,22 +13,23 @@
"role": "Developer"
}
],

"autoload": {
"psr-4": {
"I18nBundle\\": "src/I18nBundle"
}
},

"extra": {
"pimcore": {
"bundles": [
"I18nBundle\\I18nBundle"
]
}
},
"conflict": {
"pimcore/pimcore": "6.4.*"
},
"require": {
"pimcore/pimcore": "^6.0.0"
"pimcore/pimcore": "^6.0"
},
"require-dev": {
"codeception/codeception": "~2.4.0",
Expand Down
14 changes: 14 additions & 0 deletions docs/10_GeoControl.md
@@ -0,0 +1,14 @@
# Geo Control

> The Data provider is only required if you want to use the country detection!
>
Follow the [official instructions](https://dev.maxmind.com/geoip/geoipupdate/) for obtaining and updating the GeoIP database.
Store the database file at the location of your choice, the default location used by _geoipupdate_ is `/usr/share/GeoIP/GeoLite2-City.mmdb`

Set the path to the database file in your `parameters.yml` to enable the geo support in Pimcore:

```yaml
pimcore.geoip.db_file: /usr/share/GeoIP/GeoLite2-City.mmdb
```

To keep the BC, I18n also will check the project path `var/config/GeoLite2-City.mmdb` for legacy reasons.
2 changes: 1 addition & 1 deletion src/I18nBundle/DependencyInjection/Configuration.php
Expand Up @@ -64,7 +64,7 @@ public function getConfigTreeBuilder()
->prototype('array')
->children()
->integerNode('id')->isRequired()->end()
->scalarNode('name')->end()
->scalarNode('name')->defaultValue(null)->end()
->arrayNode('domains')
->prototype('scalar')->end()
->end()
Expand Down
9 changes: 9 additions & 0 deletions src/I18nBundle/DependencyInjection/I18nExtension.php
Expand Up @@ -29,5 +29,14 @@ public function load(array $configs, ContainerBuilder $container)
$configManagerDefinition->addMethodCall('setConfig', [$config]);

$container->setParameter('i18n.registry_availability', $config['registry']);

// set geo db path (including legacy path)
if ($container->hasParameter('pimcore.geoip.db_file') && !is_null($container->getParameter('pimcore.geoip.db_file'))) {
$geoIpDbFile = $container->getParameter('pimcore.geoip.db_file');
} else {
$geoIpDbFile = realpath(PIMCORE_CONFIGURATION_DIRECTORY . '/GeoLite2-City.mmdb');
}

$container->setParameter('i18n.geo_ip.db_file', is_string($geoIpDbFile) ? $geoIpDbFile : '');
}
}
Expand Up @@ -119,7 +119,14 @@ public static function getSubscribedEvents()
*/
public function onKernelRequest(GetResponseEvent $event)
{
if ($this->pimcoreConfig['cache']['enabled'] === true) {
$fullPageEnabled = false;
if (isset($this->pimcoreConfig['cache']) && isset($this->pimcoreConfig['cache']['enabled'])) {
$fullPageEnabled = $this->pimcoreConfig['cache']['enabled'];
} elseif (isset($this->pimcoreConfig['full_page_cache']) && isset($this->pimcoreConfig['full_page_cache']['enabled'])) {
$fullPageEnabled = $this->pimcoreConfig['full_page_cache']['enabled'];
}

if ($fullPageEnabled === true) {
return;
}

Expand Down
23 changes: 15 additions & 8 deletions src/I18nBundle/Helper/UserHelper.php
Expand Up @@ -12,12 +12,21 @@ class UserHelper
*/
protected $requestStack;

/**
* @var string
*/
protected $geoIpDbPath;

/**
* @param RequestStack $requestStack
* @param string $geoIpDbPath
*/
public function __construct(RequestStack $requestStack)
{
public function __construct(
RequestStack $requestStack,
string $geoIpDbPath
) {
$this->requestStack = $requestStack;
$this->geoIpDbPath = $geoIpDbPath;
}

/**
Expand All @@ -43,17 +52,14 @@ public function guessLanguage()
*/
public function guessCountry()
{
$masterRequest = $this->requestStack->getMasterRequest();

$geoDbFile = realpath(PIMCORE_CONFIGURATION_DIRECTORY . '/GeoLite2-City.mmdb');
$record = null;

$country = null;
$userCountry = false;
$masterRequest = $this->requestStack->getMasterRequest();

if (file_exists($geoDbFile)) {
if (file_exists($this->geoIpDbPath)) {
try {
$reader = new Reader($geoDbFile);
$reader = new Reader($this->geoIpDbPath);
if ($masterRequest->server->has('HTTP_CLIENT_IP') &&
!empty($masterRequest->server->get('HTTP_CLIENT_IP'))) {
$ip = $masterRequest->server->get('HTTP_CLIENT_IP');
Expand All @@ -67,6 +73,7 @@ public function guessCountry()
$record = $reader->city($ip);
$country = $record->country->isoCode;
} catch (\Exception $e) {
// fail silently.
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/I18nBundle/Resources/config/services/helper.yml
Expand Up @@ -9,6 +9,9 @@ services:

I18nBundle\Helper\CookieHelper: ~

I18nBundle\Helper\UserHelper: ~
I18nBundle\Helper\RequestValidatorHelper: ~

I18nBundle\Helper\RequestValidatorHelper: ~
I18nBundle\Helper\UserHelper:
arguments:
$requestStack: '@request_stack'
$geoIpDbPath: '%i18n.geo_ip.db_file%'
10 changes: 9 additions & 1 deletion tests/_bootstrap.php
Expand Up @@ -6,6 +6,7 @@
include __DIR__ . '/../../../vendor/autoload.php';

define('PIMCORE_KERNEL_CLASS', '\DachcomBundle\Test\App\TestAppKernel');
define('PIMCORE_TEST', true);

Bootstrap::setProjectRoot();
Bootstrap::bootstrap();
Expand All @@ -20,4 +21,11 @@
define('TESTS_PATH', __DIR__);
}

define('PIMCORE_TEST', true);
if (!isset($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] = '';
}

if (!isset($_SERVER['HTTP_USER_AGENT'])) {
$_SERVER['HTTP_USER_AGENT'] = '';
}

2 changes: 2 additions & 0 deletions tests/_etc/config/bundle/symfony/config_full_page_cache.yml
Expand Up @@ -5,5 +5,7 @@ i18n:
translations: ~

pimcore:
full_page_cache:
enabled: true
cache:
enabled: true
7 changes: 6 additions & 1 deletion tests/_etc/config/bundle/system.yml.template
Expand Up @@ -48,9 +48,14 @@ pimcore:
browser_api_key: ''
cache:
exclude_cookie: ''
enabled: true
enabled: false
lifetime: null
exclude_patterns: ''
full_page_cache:
enabled: false
lifetime: null
exclude_patterns: ''
exclude_cookie: ''
httpclient:
adapter: Socket
proxy_host: ''
Expand Down
9 changes: 3 additions & 6 deletions tests/_etc/travis/install
Expand Up @@ -43,13 +43,10 @@ do
cp $K ${DACHCOM_INSTALL_CONFIG_FILES[$K]};
done


## load GeoLite2

wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz
gzip -d GeoLite2-City.mmdb.gz
mv -nv GeoLite2-City.mmdb var/config/

git clone -b 4.0.1 --single-branch https://github.com/geocoder-php/geoip2-provider
cp ./geoip2-provider/Tests/fixtures/GeoLite2-City.mmdb var/config/
rm -rf geoip2-provider

## install composer dependencies
rm composer.lock
Expand Down
22 changes: 22 additions & 0 deletions tests/_support/App/Pimcore/TestConfig.php
@@ -0,0 +1,22 @@
<?php

namespace DachcomBundle\Test\App\Pimcore;

use Pimcore\Config;

class TestConfig extends Config
{

/**
* @param string $offset
*
* @return string
*/
public function offsetGet($offset)
{
parent::$systemConfig = null;

return parent::offsetGet($offset);
}

}
2 changes: 2 additions & 0 deletions tests/_support/App/TestAppKernel.php
Expand Up @@ -3,6 +3,7 @@
namespace DachcomBundle\Test\App;

use Pimcore\Kernel;
use DachcomBundle\Test\DependencyInjection\ServiceChangePass;
use DachcomBundle\Test\DependencyInjection\MakeServicesPublicPass;
use DachcomBundle\Test\DependencyInjection\MonologChannelLoggerPass;
use Pimcore\HttpKernel\BundleCollection\BundleCollection;
Expand Down Expand Up @@ -52,6 +53,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
*/
protected function build(ContainerBuilder $container)
{
$container->addCompilerPass(new ServiceChangePass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -100000);
$container->addCompilerPass(new MakeServicesPublicPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -100000);
$container->addCompilerPass(new MonologChannelLoggerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1);
}
Expand Down
28 changes: 28 additions & 0 deletions tests/_support/DependencyInjection/ServiceChangePass.php
@@ -0,0 +1,28 @@
<?php

namespace DachcomBundle\Test\DependencyInjection;

use Pimcore;
use DachcomBundle\Test\App\Pimcore\TestConfig;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

class ServiceChangePass implements CompilerPassInterface
{
/**
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('Pimcore\Config')) {
return;
}

$testService = new Definition(TestConfig::class);
$testService->setPublic(true);

$container->setDefinition(TestConfig::class, $testService);
$container->getDefinition(Pimcore\Config::class)->setClass(TestConfig::class);
}
}

0 comments on commit 2cf2829

Please sign in to comment.