Skip to content

Commit

Permalink
MVC / MenuInitException - handle broken menu xml files more gracefull…
Browse files Browse the repository at this point in the history
…y, dump to error log, but don't crash out with a fatal exception.
  • Loading branch information
AdSchellevis committed Nov 13, 2023
1 parent 53b8f0f commit 22f939b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Expand Up @@ -97,7 +97,6 @@ private function search(&$menuItems, $query)
* request user context sensitive menu (items)
* @param string $selected_uri selected uri
* @return array menu items
* @throws Menu\MenuInitException when unable to construct menu
*/
private function getMenu($selected_uri)
{
Expand Down Expand Up @@ -166,7 +165,6 @@ private function extractMenuLeaves($menu_items, &$items)
/**
* return menu items for this user
* @return array
* @throws Menu\MenuInitException when unable to construct menu
*/
public function treeAction()
{
Expand All @@ -178,7 +176,6 @@ public function treeAction()
/**
* search menu items
* @return array
* @throws Menu\MenuInitException when unable to construct menu
*/
public function searchAction()
{
Expand Down
11 changes: 7 additions & 4 deletions src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuSystem.php
Expand Up @@ -108,7 +108,6 @@ public function invalidateCache()
* Load and persist Menu configuration to disk.
* @param bool $nowait when the cache is locked, skip waiting for it to become available.
* @return SimpleXMLElement
* @throws MenuInitException
*/
public function persist($nowait = true)
{
Expand All @@ -133,9 +132,13 @@ public function persist($nowait = true)
foreach (glob($vendor . '/*') as $module) {
$menu_cfg_xml = $module . '/Menu/Menu.xml';
if (file_exists($menu_cfg_xml)) {
$domNode = dom_import_simplexml($this->addXML($menu_cfg_xml));
$domNode = $root->ownerDocument->importNode($domNode, true);
$root->appendChild($domNode);
try {
$domNode = dom_import_simplexml($this->addXML($menu_cfg_xml));
$domNode = $root->ownerDocument->importNode($domNode, true);
$root->appendChild($domNode);
} catch (MenuInitException $e) {
error_log($e);
}
}
}
}
Expand Down

0 comments on commit 22f939b

Please sign in to comment.