* @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', ])); } } }