/** * Refreshes the internal list of Extensions * * @param string $dir Extension directory */ function refreshList($dir) { $moduledirs = getdirlist($dir); for ($m = 0; $m < count($moduledirs); $m++) { $path = $moduledirs[$m]; if (file_exists($dir . $path . "/extension.php") && file_exists($dir . $path . "/extension.xml")) { if (!$this->getIdByPath($path)) { $extConfig = new \framework\Config($dir . $path . "/extension.xml"); $extApiVersion = explode('.', (string) $extConfig->getVar("extension/api")); if ($extApiVersion[0] != EXTENSION_VERSION_MAJOR) { sLog()->error('Extension: API Version mismatch. Expected v' . EXTENSION_VERSION_MAJOR . '.x, Extension has v' . $extApiVersion[0] . '.x!'); return false; } require_once $dir . $path . "/extension.php"; $namespace = (string) $extConfig->getVar("extension/namespace"); $classname = $namespace . "\\" . (string) $extConfig->getVar("extension/class"); $code = strtolower(preg_replace("/[^A-Za-z0-9]/", "_", $classname)); try { $extension = new $classname(); } catch (Exception $e) { return; } $info = $extension->getInfo(); if ($this->getIdByCode($code) == NULL) { $this->add($code, $path, $info["NAME"], $info["DEVELOPERNAME"], $info["VERSION"], $info["DESCRIPTION"], $info["URL"], $info["TYPE"]); } } } } // Remove orphaned extensions from database $currentExtensions = $this->getList(0, false, true); foreach ($currentExtensions as $currentExtensionItem) { if (!$currentExtensionItem['INSTALLED'] && !in_array($currentExtensionItem['PATH'], $moduledirs)) { $currExtension = new Extension($currentExtensionItem['CODE']); $currExtension->uninstall(); $extMgr = new ExtensionMgr(); $extMgr->remove($currentExtensionItem['CODE']); } } }