-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/Improvement for cases when a theme was selected but than removed #855
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,10 @@ | |
namespace ImpressCMS\Core\View; | ||
|
||
use icms; | ||
use ImpressCMS\Core\Database\Criteria\CriteriaCompo; | ||
use ImpressCMS\Core\Database\Criteria\CriteriaItem; | ||
use ImpressCMS\Core\Facades\Config; | ||
use ImpressCMS\Core\View\Theme\ThemeFactory; | ||
use Psr\Cache\CacheItemPoolInterface; | ||
use Psr\Cache\InvalidArgumentException; | ||
use SmartyBC; | ||
|
@@ -73,7 +77,7 @@ public function __construct() { | |
|
||
parent::__construct(); | ||
|
||
foreach (\icms::getInstance()->get('smarty.resource') as $plugin) { | ||
foreach (icms::getInstance()->get('smarty.resource') as $plugin) { | ||
$this->registerResource( | ||
$plugin->getName(), | ||
$plugin | ||
|
@@ -84,7 +88,7 @@ public function __construct() { | |
'modifier' => 'register_modifier', | ||
'compiler' => 'register_compiler_function', | ||
] as $type => $function) { | ||
foreach (\icms::getInstance()->get('smarty.' . $type) as $plugin) { | ||
foreach (icms::getInstance()->get('smarty.' . $type) as $plugin) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call to undeclared method |
||
$this->$function( | ||
$plugin->getName(), | ||
[$plugin, 'execute'] | ||
|
@@ -209,4 +213,67 @@ public static function template_clear_module_cache($mid) { | |
} | ||
} | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null) | ||
fiammybe marked this conversation as resolved.
Show resolved
Hide resolved
fiammybe marked this conversation as resolved.
Show resolved
Hide resolved
fiammybe marked this conversation as resolved.
Show resolved
Hide resolved
fiammybe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opening brace should be on the same line as the declaration |
||
try { | ||
return parent::fetch($template, $cache_id, $compile_id, $parent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reference to undeclared class |
||
} catch (SmartyException $exception) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Catching undeclared class |
||
if (strpos($exception->getMessage(), 'Unable to load template') === 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call to method |
||
$this->handleDeletedTemplateSet($exception); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method fetch uses an else expression. Else is never necessary and you can simplify the code to work without else. |
||
throw $exception; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Handle exception for deleted template set | ||
* (if there is possibility automatically auto updates selected theme in config) | ||
* | ||
* @param SmartyException $exception | ||
* | ||
* @throws SmartyException | ||
*/ | ||
private function handleDeletedTemplateSet(SmartyException $exception): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parameter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @throws type of |
||
$isAdmin = $this->getTemplateVars('icms_isadmin'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call to undeclared method |
||
$themesList = $isAdmin ? ThemeFactory::getAdminThemesList() : ThemeFactory::getThemesList(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using static access to class '\ImpressCMS\Core\View\Theme\ThemeFactory' in method 'handleDeletedTemplateSet'. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using static access to class '\ImpressCMS\Core\View\Theme\ThemeFactory' in method 'handleDeletedTemplateSet'. |
||
$configKey = $isAdmin ? 'theme_admin_set' : 'theme_set'; | ||
|
||
if (empty($themesList)) { | ||
throw $exception; | ||
} | ||
|
||
$configCriteria = new CriteriaCompo( | ||
new CriteriaItem('conf_modid', 0) | ||
); | ||
$configCriteria->add( | ||
new CriteriaItem('conf_name', $configKey) | ||
); | ||
$configCriteria->add( | ||
new CriteriaItem('conf_catid', Config::CATEGORY_MAIN) | ||
); | ||
|
||
/** | ||
* @var Config $configHandler | ||
*/ | ||
$configHandler = icms::getInstance()->get('config'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call to undeclared method |
||
$config = $configHandler->getConfigs($configCriteria); | ||
if (!isset($config[0])) { | ||
throw $exception; | ||
} | ||
|
||
if (isset($themesList[$config[0]->conf_value])) { | ||
throw $exception; | ||
} | ||
|
||
$config[0]->conf_value = current($themesList); | ||
$config[0]->store(); | ||
|
||
redirect_header(ICMS_URL); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call to undeclared method
\icms::get