OA_Permission::enforceAccount(OA_ACCOUNT_ADMIN); $oPluginManager = new OX_PluginManager(); $oComponentGroupManager = new OX_Plugin_ComponentGroupManager(); $action = $_REQUEST['action']; $plugin = $_REQUEST['package']; $group = $_REQUEST['group']; $parent = $_REQUEST['parent']; //install if (array_key_exists('install', $_POST)) { if (array_key_exists('filename', $_FILES)) { $oPluginManager->installPackage($_FILES['filename']); } } else { if (array_key_exists('import', $_POST)) { if (array_key_exists('filename', $_FILES)) { $oPluginManager->installPackageCodeOnly($_FILES['filename']); } } else { if (array_key_exists('getupgrade', $_POST)) { $downloadurl = $_POST['downloadurl']; $aFile['error'] = 0; $aFile['type'] = 'application/zip'; $aFile['name'] = basename($downloadurl); $aFile['tmp_name'] = MAX_PATH . '/var/' . $aFile['name']; file_put_contents($aFile['tmp_name'], file_get_contents($downloadurl)); if (file_exists($aFile['tmp_name'])) { $oPluginManager->upgradePackage($aFile, $plugin); $oTpl = new OA_Admin_Template('plugin-view.html'); $aPackageInfo = $oPluginManager->getPackageInfo($plugin); $aComponents = $aPackageInfo['contents']; unset($aPackageInfo['contents']);
function checkPlugin($pluginName) { $aErrors = array(); $aResult = array('name' => $pluginName, 'status' => '', 'errors' => &$aErrors); require_once LIB_PATH . '/Plugin/PluginManager.php'; $oPluginManager = new OX_PluginManager(); // if plugin definition is not found in situ // try to import plugin code from the previous installation if (!file_exists(MAX_PATH . $GLOBALS['_MAX']['CONF']['pluginPaths']['packages'] . $pluginName . '.xml')) { if (isset($GLOBALS['_MAX']['CONF']['pluginPaths']['export'])) { $file = $GLOBALS['_MAX']['CONF']['pluginPaths']['export'] . $pluginName . '.zip'; if (file_exists($file)) { $aFile['name'] = $file; $aFile['tmp_name'] = $file; $aErrors[] = 'Exported plugin file found, attempting to import from ' . $file; if (!$oPluginManager->installPackageCodeOnly($aFile)) { if ($oPluginManager->countErrors()) { $aResult['status'] = 'Failed'; foreach ($oPluginManager->aErrors as $errmsg) { $aErrors[] = $errmsg; } } } else { $aResult['status'] = 'OK'; } } } } // Try to upgrade bundled plugins include_once MAX_PATH . '/etc/default_plugins.php'; if ($aDefaultPlugins) { foreach ($aDefaultPlugins as $idx => $aPlugin) { if ($aPlugin['name'] == $pluginName) { $upgraded = false; $oPluginManager = new OX_PluginManager(); $aFileName['name'] = $aPlugin['name'] . '.' . $aPlugin['ext']; $aFileName['tmp_name'] = $aPlugin['path'] . $aPlugin['name'] . '.' . $aPlugin['ext']; $aFileName['type'] = 'application/zip'; $upgraded = $oPluginManager->upgradePackage($aFileName, $pluginName); if (!empty($oPluginManager->aErrors) && !empty($oPluginManager->previousVersionInstalled) && $oPluginManager->previousVersionInstalled != OX_PLUGIN_SAME_VERSION_INSTALLED) { foreach ($oPluginManager->aErrors as $i => $msg) { $aErrors[] = $msg; } } } } } // now diagnose problems $aDiag = $oPluginManager->getPackageDiagnostics($pluginName); if ($aDiag['plugin']['error']) { $aErrors[] = 'Problems found with plugin ' . $pluginName . '. The plugin has been disabled. Go to the Configuration Plugins page for details '; foreach ($aDiag['plugin']['errors'] as $i => $msg) { $aErrors[] = $msg; } } foreach ($aDiag['groups'] as $idx => &$aGroup) { if ($aGroup['error']) { $aDiag['plugin']['error'] = true; $aErrors[] = 'Problems found with components in group ' . $aGroup['name'] . '. The ' . $pluginName . ' plugin has been disabled. Go to the Configuration->Plugins page for details '; foreach ($aGroup['errors'] as $i => $msg) { $aErrors[] = $msg; } } } $enabled = wasPluginEnabled($pluginName); // original setting if (!$aDiag['plugin']['error']) { if ($upgraded) { $aResult['status'] .= 'OK, Upgraded'; } elseif ($oPluginManager->previousVersionInstalled == OX_PLUGIN_NEWER_VERSION_INSTALLED) { $aResult['status'] .= 'OK. Notice: You have a newer plugin version installed than the one that comes with this upgrade package.'; } elseif ($oPluginManager->previousVersionInstalled == OX_PLUGIN_SAME_VERSION_INSTALLED) { $aResult['status'] .= 'OK, Up to date'; } else { $aResult['status'] .= 'OK'; } if ($enabled) { if ($oPluginManager->enablePackage($pluginName)) { $aResult['status'] .= ', Enabled'; } else { $aResult['status'] .= ', failed to enable, check plugin configuration'; } } else { $aResult['status'] .= ', Disabled'; } } else { $aResult['status'] = 'Errors, disabled'; } return $aResult; }