Commit d77c0588 authored by tino.goratsch@hotmail.com's avatar [email protected]

- added new method Modules::getInstalledModules() to get all currently...

- added new method Modules::getInstalledModules() to get all currently installed (active and inactive) modules
- reworked the module installation/uninstalled/enabling/disabling process, to work flawlessly
- fixed possible PHP warnings in the SQLLogger because of undefined array indices 
- fixed "no entries" message in categories admin index
- fixed undefined template variable in articles sidebar widget
parent 9725e50b
<?php
namespace ACP3\Core\DB;
use ACP3\Core\Logger;
/**
......@@ -30,6 +31,15 @@ class SQLLogger implements \Doctrine\DBAL\Logging\SQLLogger
* @var string
*/
private $logFilename = 'db-queries';
/**
* @var string
*/
private $requestPath = '';
public function __construct()
{
$this->requestPath = $_SERVER['REQUEST_URI'];
}
/**
* {@inheritdoc}
......@@ -37,7 +47,7 @@ class SQLLogger implements \Doctrine\DBAL\Logging\SQLLogger
public function startQuery($sql, array $params = null, array $types = null)
{
$this->start = microtime(true);
$this->queries[$_SERVER['REQUEST_URI']][++$this->currentQuery] = ['sql' => $sql, 'params' => $params, 'types' => $types, 'executionMS' => 0];
$this->queries[$this->requestPath][++$this->currentQuery] = ['sql' => $sql, 'params' => $params, 'types' => $types, 'executionMS' => 0];
}
/**
......@@ -45,19 +55,21 @@ class SQLLogger implements \Doctrine\DBAL\Logging\SQLLogger
*/
public function stopQuery()
{
$this->queries[$_SERVER['REQUEST_URI']][$this->currentQuery]['executionMS'] = microtime(true) - $this->start;
$this->queries[$this->requestPath][$this->currentQuery]['executionMS'] = microtime(true) - $this->start;
}
public function __destruct()
{
$totalTime = 0;
foreach ($this->queries[$_SERVER['REQUEST_URI']] as $query) {
$totalTime += $query['executionMS'];
}
if (isset($this->queries[$this->requestPath])) {
$totalTime = 0;
foreach ($this->queries[$this->requestPath] as $query) {
$totalTime += $query['executionMS'];
}
$this->queries[$_SERVER['REQUEST_URI']]['queryCount'] = count($this->queries[$_SERVER['REQUEST_URI']]);
$this->queries[$_SERVER['REQUEST_URI']]['totalTime'] = $totalTime;
$this->queries[$this->requestPath]['queryCount'] = count($this->queries[$this->requestPath]);
$this->queries[$this->requestPath]['totalTime'] = $totalTime;
Logger::debug($this->logFilename, $this->queries);
Logger::debug($this->logFilename, $this->queries);
}
}
}
\ No newline at end of file
......@@ -92,7 +92,7 @@ class Modules
public function isActive($module)
{
$info = $this->getModuleInfo($module);
return !empty($info) && $info['active'] == 1;
return !empty($info) && $info['active'] === true;
}
/**
......@@ -152,6 +152,7 @@ class Modules
$infos[$moduleName] = [
'id' => !empty($moduleInfoDb) ? $moduleInfoDb['id'] : 0,
'dir' => $dir,
'installed' => (!empty($moduleInfoDb)),
'active' => (!empty($moduleInfoDb) && $moduleInfoDb['active'] == 1),
'schema_version' => !empty($moduleInfoDb) ? (int)$moduleInfoDb['version'] : 0,
'description' => isset($moduleInfo['description']['lang']) && $moduleInfo['description']['lang'] === 'true' ? $this->lang->t($moduleName, 'mod_description') : $moduleInfo['description']['lang'],
......@@ -179,25 +180,44 @@ class Modules
*/
public function isInstalled($moduleName)
{
return $this->systemModel->moduleExists($moduleName);
$info = $this->getModuleInfo($moduleName);
return !empty($info) && $info['installed'] === true;
}
/**
* Gibt alle derzeit aktiven Module in einem Array zurück
* Returns all currently installed AND active modules
*
* @return array
*/
public function getActiveModules()
{
$activeModules = $this->getAllModules();
$modules = $this->getAllModules();
foreach ($this->allModules as $key => $values) {
if ($values['active'] !== true) {
unset($activeModules[$key]);
if ($values['active'] === false) {
unset($modules[$key]);
}
}
return $activeModules;
return $modules;
}
/**
* Returns all currently installed modules
*
* @return mixed
*/
public function getInstalledModules()
{
$modules = $this->getAllModules();
foreach ($this->allModules as $key => $values) {
if ($values['installed'] === false) {
unset($modules[$key]);
}
}
return $modules;
}
/**
......@@ -221,4 +241,4 @@ class Modules
return $this->allModules;
}
}
}
\ No newline at end of file
......@@ -45,34 +45,36 @@ class Session
{
$this->db = $db;
// php.ini Session Einstellungen konfigurieren
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);
// Session GC
ini_set('session.gc_maxlifetime', $this->expireTime);
ini_set('session.gc_probability', $this->gcProbability);
ini_set('session.gc_divisor', 100);
// Eigene Session Handling Methoden setzen
ini_set('session.save_handler', 'user');
session_set_save_handler(
[$this, 'session_open'],
[$this, 'session_close'],
[$this, 'session_read'],
[$this, 'session_write'],
[$this, 'session_destroy'],
[$this, 'session_gc']
);
// Session starten und anschließend sichern
self::startSession();
self::secureSession();
register_shutdown_function('session_write_close');
if (session_status() == PHP_SESSION_NONE) {
// php.ini Session Einstellungen konfigurieren
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);
// Session GC
ini_set('session.gc_maxlifetime', $this->expireTime);
ini_set('session.gc_probability', $this->gcProbability);
ini_set('session.gc_divisor', 100);
// Eigene Session Handling Methoden setzen
ini_set('session.save_handler', 'user');
session_set_save_handler(
[$this, 'session_open'],
[$this, 'session_close'],
[$this, 'session_read'],
[$this, 'session_write'],
[$this, 'session_destroy'],
[$this, 'session_gc']
);
// Session starten und anschließend sichern
self::startSession();
self::secureSession();
register_shutdown_function('session_write_close');
}
}
/**
......
......@@ -5,7 +5,7 @@
<div class="list-group">
{if !empty($sidebar_articles)}
{foreach $sidebar_articles as $row}
<a href="{uri args="articles/index/details/id_`$row.id`"}" class="list-group-item" title="{date_format date=$row.start format=$dateformat} - {$row.title}">{$row.title|truncate:30}</a>
<a href="{uri args="articles/index/details/id_`$row.id`"}" class="list-group-item" title="{date_format date=$row.start} - {$row.title}">{$row.title|truncate:30}</a>
{/foreach}
{else}
<span class="list-group-item">{lang t="system|no_entries_short"}</span>
......
......@@ -53,7 +53,7 @@
{include file="asset:system/datatable.tpl" dt=$datatable_config}
{else}
<div class="alert alert-warning text-center">
<h5>{lang t="system|entries"}</h5>
<strong>{lang t="system|no_entries"}</strong>
</div>
{/if}
</form>
......
......@@ -179,12 +179,14 @@ class Extensions extends Core\Modules\Controller\Admin
} else {
$serviceId = strtolower($this->request->dir . '.installer');
if ($this->container->has($serviceId) === true) {
$container = $this->systemHelpers->updateServiceContainer();
if ($container->has($serviceId) === true) {
/** @var Core\Modules\AbstractInstaller $installer */
$installer = $this->get($serviceId);
$installer = $container->get($serviceId);
// Modulabhängigkeiten prüfen
$deps = $this->systemHelpers->checkUninstallDependencies($installer::MODULE_NAME, $this->container);
$deps = $this->systemHelpers->checkUninstallDependencies($installer::MODULE_NAME, $container);
if (empty($deps)) {
$bool = $this->systemModel->update(['active' => 0], ['name' => $this->request->dir]);
......@@ -212,8 +214,10 @@ class Extensions extends Core\Modules\Controller\Admin
if ($this->modules->isInstalled($this->request->dir) === false) {
$serviceId = strtolower($this->request->dir . '.installer');
if ($this->container->has($serviceId) === true) {
$installer = $this->get($serviceId);
$container = $this->systemHelpers->updateServiceContainer(true);
if ($container->has($serviceId) === true) {
$installer = $container->get($serviceId);
// Modulabhängigkeiten prüfen
$deps = $this->systemHelpers->checkInstallDependencies($installer);
......@@ -246,12 +250,14 @@ class Extensions extends Core\Modules\Controller\Admin
if ($info['protected'] === false && $this->modules->isInstalled($this->request->dir) === true) {
$serviceId = strtolower($this->request->dir . '.installer');
if ($this->container->has($serviceId) === true) {
$container = $this->systemHelpers->updateServiceContainer();
if ($container->has($serviceId) === true) {
/** @var Core\Modules\AbstractInstaller $installer */
$installer = $this->get($serviceId);
$installer = $container->get($serviceId);
// Modulabhängigkeiten prüfen
$deps = $this->systemHelpers->checkUninstallDependencies($installer::MODULE_NAME, $this->container);
$deps = $this->systemHelpers->checkUninstallDependencies($installer::MODULE_NAME, $container);
// Modul deinstallieren
if (empty($deps)) {
......
......@@ -2,7 +2,10 @@
namespace ACP3\Modules\System;
use ACP3\Core;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
/**
* Class Helpers
......@@ -59,8 +62,9 @@ class Helpers
*/
public function checkUninstallDependencies($moduleToBeUninstalled, Container $container)
{
$modules = $this->modules->getActiveModules();
$modules = $this->modules->getInstalledModules();
$moduleDependencies = [];
foreach ($modules as $localizedModuleName => $values) {
$moduleName = strtolower($values['dir']);
if ($moduleName !== $moduleToBeUninstalled) {
......@@ -73,6 +77,36 @@ class Helpers
return $moduleDependencies;
}
/**
* @param bool $allModules
*
* @return \Symfony\Component\DependencyInjection\ContainerBuilder
*/
public function updateServiceContainer($allModules = false)
{
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(__DIR__));
$loader->load(ACP3_DIR . 'config/services.yml');
$loader->load(CLASSES_DIR . 'View/Renderer/Smarty/services.yml');
// Try to get all available services
if ($allModules === true) {
$modules = $this->modules->getAllModules();
} else {
$modules = $this->modules->getInstalledModules();
}
foreach ($modules as $module) {
$path = MODULES_DIR . $module['dir'] . '/config/services.yml';
if (is_file($path)) {
$loader->load($path);
}
}
$container->compile();
return $container;
}
/**
* @param array $tables
* @param $exportType
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment