Files
b2b.redline.com.pl/modules/teamwant_redis/classes/versions/TeamwantRedisFor1700.php
2025-06-24 14:14:35 +02:00

117 lines
3.7 KiB
PHP

<?php
/**
* Redis Cache
* Version: 2.1.1
* Copyright (c) 2020-2022. Mateusz Szymański Teamwant
* https://teamwant.pl
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @author Teamwant <kontakt@teamwant.pl>
* @copyright Copyright 2020-2023 © Teamwant Mateusz Szymański All right reserved
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* @category Teamwant
* @package Teamwant
*/
namespace Teamwant\Prestashop17\Redis\Classes\Versions;
use Media;
use Teamwant\Prestashop17\Redis\Classes\TeamwantRedis;
use Tools;
trait TeamwantRedisVersion
{
use TeamwantRedis;
public function install()
{
$this->createCustomOverride($this->prestashopVersion);
$out = parent::install()
&& $this->registerHook('backOfficeHeader');
$this->registerAdminControllers();
return $out;
}
public function uninstall()
{
$this->uninstallAdminControllers();
$this->removeCustomOverride();
return parent::uninstall();
}
public function enable($force_all = false)
{
$this->createCustomOverride($this->prestashopVersion);
$this->registerHook('backOfficeHeader');
$this->registerAdminControllers();
return parent::enable($force_all);
}
public function disable($force_all = false)
{
$this->uninstallAdminControllers();
$this->removeCustomOverride();
return parent::disable($force_all);
}
public function hookBackOfficeHeader()
{
//custom js variables
Media::addJsDef([
'token_AdminRedisConfiguration' => Tools::getAdminTokenLite('AdminRedisConfiguration'),
]);
$controller = Tools::getValue('controller', '');
if ($controller === 'AdminPerformance') {
//custom js variables
Media::addJsDef([
'tw_redis_lang_save_change_on_performance' => $this->l('Are you sure to save the changes? The redis configuration has not been saved.')
]);
}
// custom js
$this->context->controller->addJquery();
$this->context->controller->addJs($this->_path . 'views/js/redis-admin1700.js');
// custom css
$this->context->controller->addCSS($this->_path . 'views/css/redis-admin1700.css');
}
public function validateFilePrivilagesForTeamwantRedisModule()
{
if (!file_exists(TEAMWANT_REDIS_ROOT_DIR . '/config/_RedisConfiguration.php')) {
@file_put_contents(TEAMWANT_REDIS_ROOT_DIR . '/config/_RedisConfiguration.php', '');
}
if (file_exists(TEAMWANT_REDIS_ROOT_DIR . '/config/_RedisConfiguration.php')) {
if (!is_writable(TEAMWANT_REDIS_ROOT_DIR . '/config/_RedisConfiguration.php')) {
$this->adminDisplayWarning(self::staticModuleTranslate('File %s must be writable.', [
TEAMWANT_REDIS_ROOT_DIR . '/config/_RedisConfiguration.php',
]));
}
if (!is_readable(TEAMWANT_REDIS_ROOT_DIR . '/config/_RedisConfiguration.php')) {
$this->adminDisplayWarning(self::staticModuleTranslate('File %s must be readable.', [
TEAMWANT_REDIS_ROOT_DIR . '/config/_RedisConfiguration.php',
]));
}
} else {
$this->adminDisplayWarning(self::staticModuleTranslate('Can\'t create file %s.', [
TEAMWANT_REDIS_ROOT_DIR . '/config/_RedisConfiguration.php',
]));
}
}
}