Commit d672b1bb authored by Tino Goratsch's avatar Tino Goratsch

Merge branch 'release/v4.9.0'

parents 74f2e0d7 4e1f0829
......@@ -6,12 +6,28 @@
#SetEnv ACP3_APPLICATION_MODE dev
# Uncomment the following lines of code if you want to use separate sitemaps for HTTP and HTTPS
#<IfModule mod_rewrite.c>
# RewriteEngine On
#
# RewriteCond %{HTTPS} =on
# RewriteRule ^ - [env=proto:https]
# RewriteCond %{HTTPS} !=on
# RewriteRule ^ - [env=proto:http]
#
# RewriteCond %{HTTPS} !=on
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteRule ^sitemap\.xml$ sitemap_http.xml [L,QSA]
#
# RewriteCond %{HTTPS} =on
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteRule ^sitemap\.xml$ sitemap_https.xml [L,QSA]
#</IfModule>
<IfModule mod_rewrite.c>
Options +FollowSymlinks
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
......
<?php
namespace ACP3\Core\ACL;
use ACP3\Core\Enum\BaseEnum;
/**
* Class PermissionEnum
* @package ACP3\Core\ACL
*/
class PermissionEnum
class PermissionEnum extends BaseEnum
{
const DENY_ACCESS = 0;
const PERMIT_ACCESS = 1;
......
<?php
namespace ACP3\Core\ACL;
use ACP3\Core\Enum\BaseEnum;
/**
* Class PrivilegeEnum
* @package ACP3\Core\ACL
*/
class PrivilegeEnum
class PrivilegeEnum extends BaseEnum
{
const ADMIN_SETTINGS = 7;
const ADMIN_DELETE = 6;
......
......@@ -3,6 +3,7 @@ namespace ACP3\Core\Application;
use ACP3\Core\Environment\ApplicationPath;
use ACP3\Core\ErrorHandler;
use Psr\Log\LoggerInterface;
/**
* Class AbstractBootstrap
......@@ -22,6 +23,10 @@ abstract class AbstractBootstrap implements BootstrapInterface
* @var \ACP3\Core\Environment\ApplicationPath
*/
protected $appPath;
/**
* @var LoggerInterface
*/
protected $logger;
/**
* @param string $appMode
......@@ -30,6 +35,7 @@ abstract class AbstractBootstrap implements BootstrapInterface
{
$this->appMode = $appMode;
$this->initializeApplicationPath();
$this->logger = (new \ACP3\Core\Logger\LoggerFactory($this->appPath))->create('system');
}
protected function initializeApplicationPath()
......@@ -42,9 +48,7 @@ abstract class AbstractBootstrap implements BootstrapInterface
*/
public function setErrorHandler()
{
$logger = new \ACP3\Core\Logger($this->appPath);
ErrorHandler::register($logger);
ErrorHandler::register($this->logger);
}
/**
......
......@@ -55,6 +55,7 @@ class Bootstrap extends AbstractBootstrap
$this->container = new \ACP3ServiceContainer();
$this->container->set('core.environment.application_path', $this->appPath);
$this->container->set('core.http.symfony_request', $symfonyRequest);
$this->container->set('core.logger.system_logger', $this->logger);
}
/**
......@@ -66,7 +67,9 @@ class Bootstrap extends AbstractBootstrap
$containerConfigCache = new ConfigCache($filePath, ($this->appMode === ApplicationMode::DEVELOPMENT));
if (!$containerConfigCache->isFresh()) {
$containerBuilder = ServiceContainerBuilder::create($this->appPath, $symfonyRequest, $this->appMode);
$containerBuilder = ServiceContainerBuilder::create(
$this->logger, $this->appPath, $symfonyRequest, $this->appMode
);
$dumper = new PhpDumper($containerBuilder);
$containerConfigCache->write(
......@@ -107,7 +110,7 @@ class Bootstrap extends AbstractBootstrap
} catch (\ACP3\Core\Controller\Exception\ControllerActionNotFoundException $e) {
$response = $this->handleException($e, $redirect, 'errors/index/not_found');
} catch (\Exception $e) {
$this->getContainer()->get('core.logger')->error('exception', $e);
$this->logger->critical($e);
$response = $this->handleException($e, $redirect, 'errors/index/server_error');
}
......@@ -142,8 +145,8 @@ class Bootstrap extends AbstractBootstrap
private function isMaintenanceModeEnabled(RequestInterface $request)
{
return (bool)$this->systemSettings['maintenance_mode'] === true &&
$request->getArea() !== AreaEnum::AREA_ADMIN &&
strpos($request->getQuery(), 'users/index/login/') !== 0;
$request->getArea() !== AreaEnum::AREA_ADMIN &&
strpos($request->getQuery(), 'users/index/login/') !== 0;
}
/**
......
......@@ -14,7 +14,7 @@ interface BootstrapInterface extends HttpKernelInterface
/**
* Contains the current ACP3 version string
*/
const VERSION = '4.8.5';
const VERSION = '4.9.0';
/**
* Performs some startup checks
......
......@@ -6,26 +6,19 @@
namespace ACP3\Core\Authentication;
use ACP3\Core\Authentication\Exception\InvalidAuthenticationMethodException;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class AuthenticationFactory
* @package ACP3\Core\Authentication
*/
class AuthenticationFactory
{
/**
* @var \Symfony\Component\DependencyInjection\ContainerInterface
* @var AuthenticationRegistrar
*/
protected $container;
private $authenticationRegistrar;
/**
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* @param AuthenticationRegistrar $authenticationRegistrar
*/
public function __construct(ContainerInterface $container)
public function __construct(AuthenticationRegistrar $authenticationRegistrar)
{
$this->container = $container;
$this->authenticationRegistrar = $authenticationRegistrar;
}
/**
......@@ -37,10 +30,7 @@ class AuthenticationFactory
public function get($authenticationMethod)
{
$serviceId = 'core.authentication.' . $authenticationMethod;
if ($this->container->has($serviceId)) {
return $this->container->get($serviceId);
}
throw new InvalidAuthenticationMethodException();
return $this->authenticationRegistrar->get($serviceId);
}
}
<?php
/**
* Copyright (c) 2017 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Authentication;
use ACP3\Core\Authentication\Exception\InvalidAuthenticationMethodException;
class AuthenticationRegistrar
{
/**
* @var AuthenticationInterface[]
*/
private $authentications = [];
/**
* @param string $serviceId
* @param AuthenticationInterface $authentication
* @return $this
*/
public function set($serviceId, AuthenticationInterface $authentication)
{
$this->authentications[$serviceId] = $authentication;
return $this;
}
/**
* @return AuthenticationInterface[]
*/
public function all()
{
return $this->authentications;
}
/**
* @param string $serviceId
* @return bool
*/
public function has($serviceId)
{
return isset($this->authentications[$serviceId]);
}
/**
* @param string $serviceId
* @return AuthenticationInterface
* @throws InvalidAuthenticationMethodException
*/
public function get($serviceId)
{
if ($this->has($serviceId)) {
return $this->authentications[$serviceId];
}
throw new InvalidAuthenticationMethodException(
sprintf('The authentication with the service id "%s" could not be found.', $serviceId)
);
}
}
<?php
/**
* Copyright (c) 2017 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Authentication\DependencyInjection;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
class RegisterAuthenticationsCompilerPass implements CompilerPassInterface
{
/**
* @inheritdoc
*/
public function process(ContainerBuilder $container)
{
$definition = $container->findDefinition('core.authentication.authentication_registrar');
foreach ($container->findTaggedServiceIds('core.authentication') as $serviceId => $tags) {
$definition->addMethodCall(
'set',
[$serviceId, new Reference($serviceId)]
);
}
}
}
......@@ -8,7 +8,8 @@ namespace ACP3\Core\Cache;
use ACP3\Core\Environment\ApplicationMode;
use ACP3\Core\Environment\ApplicationPath;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\PhpFileCache;
/**
* Class CacheDriverFactory
......@@ -16,25 +17,31 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class CacheDriverFactory
{
/**
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
/**
* @var \ACP3\Core\Environment\ApplicationPath
*/
protected $appPath;
/**
* @var string
*/
private $cacheDriver;
/**
* @var string
*/
private $environment;
/**
* CacheDriverFactory constructor.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* @param \ACP3\Core\Environment\ApplicationPath $appPath
* @param \ACP3\Core\Environment\ApplicationPath $appPath
* @param string $cacheDriver
* @param string $environment
*/
public function __construct(ContainerInterface $container, ApplicationPath $appPath)
public function __construct(ApplicationPath $appPath, $cacheDriver, $environment)
{
$this->container = $container;
$this->appPath = $appPath;
$this->cacheDriver = $cacheDriver;
$this->environment = $environment;
}
/**
......@@ -44,53 +51,38 @@ class CacheDriverFactory
*/
public function create($namespace)
{
$driverName = $this->getCacheDriverName();
$cacheDriverPath = "\\Doctrine\\Common\\Cache\\" . $driverName . 'Cache';
if (class_exists($cacheDriverPath)) {
$driver = $this->initializeCacheDriver($driverName, $cacheDriverPath);
$driver->setNamespace($namespace);
$driver = $this->initializeCacheDriver($this->getCacheDriverName());
$driver->setNamespace($namespace);
return $driver;
}
throw new \InvalidArgumentException(
sprintf('Could not find the requested cache driver "%s"!', $cacheDriverPath)
);
return $driver;
}
/**
* @return mixed|string
* @return string
*/
protected function getCacheDriverName()
{
return $this->containerHasCacheDriver() ? $this->container->getParameter('cache_driver') : 'Array';
}
/**
* @return bool
*/
protected function containerHasCacheDriver()
{
return $this->container->hasParameter('cache_driver')
&& $this->container->getParameter('core.environment') !== ApplicationMode::DEVELOPMENT;
return $this->environment !== ApplicationMode::DEVELOPMENT ? $this->cacheDriver : 'Array';
}
/**
* @param string $driverName
* @param string $driverNameFqn
*
* @return \Doctrine\Common\Cache\CacheProvider
* @throws \InvalidArgumentException
*/
protected function initializeCacheDriver($driverName, $driverNameFqn)
protected function initializeCacheDriver($driverName)
{
/** @var \Doctrine\Common\Cache\CacheProvider $driver */
switch (strtolower($driverName)) {
case 'phpfile':
$cacheDir = $this->appPath->getCacheDir() . 'sql/';
return new $driverNameFqn($cacheDir);
return new PhpFileCache($this->appPath->getCacheDir() . 'sql/');
case 'array':
return new ArrayCache();
default:
return new $driverNameFqn();
throw new \InvalidArgumentException(
sprintf('Could not find the requested cache driver "%s"!', $driverName)
);
}
}
}
......@@ -9,9 +9,9 @@ namespace ACP3\Core\Database;
use ACP3\Core\Cache\CacheDriverFactory;
use ACP3\Core\Environment\ApplicationMode;
use ACP3\Core\Environment\ApplicationPath;
use ACP3\Core\Logger;
use Doctrine\DBAL;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Psr\Log\LoggerInterface;
/**
* Class Connection
......@@ -20,7 +20,7 @@ use Doctrine\DBAL\Cache\QueryCacheProfile;
class Connection
{
/**
* @var \ACP3\Core\Logger
* @var LoggerInterface
*/
protected $logger;
/**
......@@ -49,15 +49,16 @@ class Connection
protected $prefix = '';
/**
* @param \ACP3\Core\Logger $logger
* @param \ACP3\Core\Environment\ApplicationPath $appPath
* @param \ACP3\Core\Cache\CacheDriverFactory $cacheDriverFactory
* @param string $appMode
* Connection constructor.
* @param LoggerInterface $logger
* @param ApplicationPath $appPath
* @param CacheDriverFactory $cacheDriverFactory
* @param $appMode
* @param array $connectionParams
* @param string $tablePrefix
* @param $tablePrefix
*/
public function __construct(
Logger $logger,
LoggerInterface $logger,
ApplicationPath $appPath,
CacheDriverFactory $cacheDriverFactory,
$appMode,
......@@ -214,7 +215,7 @@ class Connection
$this->connection->commit();
} catch (\Exception $e) {
$this->connection->rollBack();
$this->logger->error('database', $e);
$this->logger->error($e);
$result = false;
}
......
......@@ -6,7 +6,7 @@
namespace ACP3\Core\Database;
use ACP3\Core\Logger;
use Psr\Log\LoggerInterface;
/**
* Class SQLLogger
......@@ -15,31 +15,23 @@ use ACP3\Core\Logger;
class SQLLogger implements \Doctrine\DBAL\Logging\SQLLogger
{
/**
* @var \ACP3\Core\Logger
* @var LoggerInterface
*/
protected $logger;
private $logger;
/**
* Executed SQL queries.
*
* @var array
*/
public $queries = [];
private $queries = [];
/**
* @var float|null
*/
public $start = null;
private $start = null;
/**
* @var integer
*/
public $currentQuery = 0;
/**
* @var string
*/
private $logFilename = 'db-queries';
private $currentQuery = 0;
/**
* @var string
*/
......@@ -47,10 +39,9 @@ class SQLLogger implements \Doctrine\DBAL\Logging\SQLLogger
/**
* SQLLogger constructor.
*
* @param \ACP3\Core\Logger $logger
* @param LoggerInterface $logger
*/
public function __construct(Logger $logger)
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
$this->requestPath = $_SERVER['REQUEST_URI'];
......@@ -62,7 +53,12 @@ class SQLLogger implements \Doctrine\DBAL\Logging\SQLLogger
public function startQuery($sql, array $params = null, array $types = null)
{
$this->start = microtime(true);
$this->queries[$this->requestPath][++$this->currentQuery] = ['sql' => $sql, 'params' => $params, 'types' => $types, 'executionMS' => 0];
$this->queries[$this->requestPath][++$this->currentQuery] = [
'sql' => $sql,
'params' => $params,
'types' => $types,
'executionMS' => 0
];
}
/**
......@@ -84,7 +80,7 @@ class SQLLogger implements \Doctrine\DBAL\Logging\SQLLogger
$this->queries[$this->requestPath]['queryCount'] = count($this->queries[$this->requestPath]);
$this->queries[$this->requestPath]['totalTime'] = $totalTime;
$this->logger->debug($this->logFilename, $this->queries);
$this->logger->debug('Executed queries for: ' . $this->requestPath, $this->queries);
}
}
}
......@@ -6,13 +6,16 @@
namespace ACP3\Core\DependencyInjection;
use ACP3\Core\Authentication\DependencyInjection\RegisterAuthenticationsCompilerPass;
use ACP3\Core\Environment\ApplicationPath;
use ACP3\Core\Helpers\DataGrid\DependencyInjection\RegisterColumnRendererPass;
use ACP3\Core\Installer\DependencyInjection\RegisterInstallersCompilerPass;
use ACP3\Core\Model\DataProcessor\DependencyInjection\RegisterColumnTypesCompilerPass;
use ACP3\Core\Modules;
use ACP3\Core\Validation\DependencyInjection\RegisterValidationRulesPass;
use ACP3\Core\View\Renderer\Smarty\DependencyInjection\RegisterSmartyPluginsPass;
use ACP3\Core\WYSIWYG\DependencyInjection\RegisterWysiwygEditorsCompilerPass;
use Psr\Log\LoggerInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
......@@ -25,6 +28,10 @@ use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
*/
class ServiceContainerBuilder extends ContainerBuilder
{
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var ApplicationPath
*/
......@@ -37,48 +44,50 @@ class ServiceContainerBuilder extends ContainerBuilder
* @var string
*/
private $applicationMode;
/**
* @var bool
*/
private $allModules;
/**
* ServiceContainerBuilder constructor.
* @param LoggerInterface $logger
* @param ApplicationPath $applicationPath
* @param SymfonyRequest $symfonyRequest
* @param string $applicationMode
* @param bool $allModules
*/
public function __construct(
LoggerInterface $logger,
ApplicationPath $applicationPath,
SymfonyRequest $symfonyRequest,
$applicationMode,
$allModules = false
$applicationMode
) {
parent::__construct();
$this->logger = $logger;
$this->applicationPath = $applicationPath;
$this->symfonyRequest = $symfonyRequest;