Skip to content

Commit

Permalink
base/MenuSystem - remove Phalcon dependency, in theory it was possibl…
Browse files Browse the repository at this point in the history
…e to offer multiple model paths in the phalcon configuration, in practice this was never used (all models live in /usr/local/opnsense/mvc/app/models).

for #6389
  • Loading branch information
AdSchellevis committed Apr 30, 2024
1 parent d1962f8 commit 2aa15e4
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
namespace OPNsense\Base\Menu;

use OPNsense\Core\Config;
use Phalcon\Di\FactoryDefault;

/**
* Class MenuSystem
Expand Down Expand Up @@ -111,38 +110,29 @@ public function invalidateCache()
*/
public function persist($nowait = true)
{
// fetch our model locations
if (!empty(FactoryDefault::getDefault()->get('config')->application->modelsDir)) {
$modelDirs = FactoryDefault::getDefault()->get('config')->application->modelsDir;
if (!is_array($modelDirs) && !is_object($modelDirs)) {
$modelDirs = array($modelDirs);
}
} else {
// failsafe, if we don't have a Phalcon Dependency Injector object, use our relative location
$modelDirs = array("__DIR__.'/../../../");
}
// find out models location
$modelDir = __DIR__.'/../../../';

// collect all XML menu definitions into a single file
$menuXml = new \DOMDocument('1.0');
$root = $menuXml->createElement('menu');
$menuXml->appendChild($root);
// crawl all vendors and modules and add menu definitions
foreach ($modelDirs as $modelDir) {
foreach (glob(preg_replace('#/+#', '/', "{$modelDir}/*")) as $vendor) {
foreach (glob($vendor . '/*') as $module) {
$menu_cfg_xml = $module . '/Menu/Menu.xml';
if (file_exists($menu_cfg_xml)) {
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);
}
foreach (glob(preg_replace('#/+#', '/', "{$modelDir}/*")) as $vendor) {
foreach (glob($vendor . '/*') as $module) {
$menu_cfg_xml = $module . '/Menu/Menu.xml';
if (file_exists($menu_cfg_xml)) {
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);
}
}
}
}

// flush to disk
$fp = fopen($this->menuCacheFilename, file_exists($this->menuCacheFilename) ? "r+" : "w+");
$lockMode = $nowait ? LOCK_EX | LOCK_NB : LOCK_EX;
Expand Down

0 comments on commit 2aa15e4

Please sign in to comment.