/** * @copydoc Form::execute() */ function execute($request) { parent::execute($request); // Retrieve the temporary file. $user = $request->getUser(); $temporaryFileId = $this->getData('temporaryFileId'); $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO'); $temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId()); $pluginHelper = new PluginHelper(); $errorMsg = null; $pluginDir = $pluginHelper->extractPlugin($temporaryFile->getFilePath(), $temporaryFile->getOriginalFileName(), $errorMsg); $notificationMgr = new NotificationManager(); if ($pluginDir) { if ($this->_function == PLUGIN_ACTION_UPLOAD) { $pluginVersion = $pluginHelper->installPlugin($pluginDir, $errorMsg); if ($pluginVersion) { $notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('manager.plugins.installSuccessful', array('versionNumber' => $pluginVersion->getVersionString(false))))); } } else { if ($this->_function == PLUGIN_ACTION_UPGRADE) { $pluginVersion = $pluginHelper->upgradePlugin($request->getUserVar('category'), $request->getUserVar('plugin'), $pluginDir, $errorMsg); if ($pluginVersion) { $notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('manager.plugins.upgradeSuccessful', array('versionString' => $pluginVersion->getVersionString(false))))); } } } } else { $errorMsg = __('manager.plugins.invalidPluginArchive'); } if ($errorMsg) { $notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_ERROR, array('contents' => $errorMsg)); return false; } return true; }
/** * Install or upgrade a plugin */ function installPlugin($args, $request, $isUpgrade = false) { $plugin = $this->_getSpecifiedPlugin($request); $notificationMgr = new NotificationManager(); $user = $request->getUser(); $dispatcher = $request->getDispatcher(); // Download the file and ensure the MD5 sum $fileManager = new FileManager(); $destPath = tempnam(sys_get_temp_dir(), 'plugin'); $fileManager->copyFile($plugin->getReleasePackage(), $destPath); if (md5_file($destPath) !== $plugin->getReleaseMD5()) { fatalError('Incorrect MD5 checksum!'); } // Extract the plugin import('lib.pkp.classes.plugins.PluginHelper'); $pluginHelper = new PluginHelper(); $errorMsg = null; if (!($pluginDir = $pluginHelper->extractPlugin($destPath, $plugin->getProduct() . '-' . $plugin->getVersion(), $errorMsg))) { $notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_ERROR, array('contents' => $errorMsg)); } // Install the plugin if (!$isUpgrade) { if (!($pluginVersion = $pluginHelper->installPlugin($pluginDir, $errorMsg))) { $notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_ERROR, array('contents' => $errorMsg)); } } else { if (!($pluginVersion = $pluginHelper->upgradePlugin($plugin->getCategory(), $plugin->getProduct(), $pluginDir, $errorMsg))) { $notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_ERROR, array('contents' => $errorMsg)); } } if (!$errorMsg) { $notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('manager.plugins.upgradeSuccessful', array('versionString' => $pluginVersion->getVersionString(false))))); } return $request->redirectUrlJson($dispatcher->url($request, ROUTE_PAGE, null, 'management', 'settings', array('website'), null, 'plugins')); }
require '../base.php'; ob_start(); require LANGS . 'ACPPluginsT.php'; ACPPluginsT::init(); function __autoload($c) { require LIB . 'plugins/' . basename($c) . '.php'; } if (!$userManager->loggedIn() || !$user->isAdmin()) { echo ErrorMessage::setText('You are not allowed to view this page.', true); } if (isset($_GET['install'])) { $packageName = basename($_GET['install']); try { $manifest = PluginManifest::fromPackageName($packageName); PluginHelper::installPlugin($manifest); header("Location: ./plugins.php"); exit; } catch (Exception $e) { echo AdminErrorMessage::setText(ACPPluginsT::getFormat('install_error', htmlspecialchars($packageName), $e->getMessage()), true); } } else { if (isset($_GET['uninstall'])) { $packageName = basename($_GET['uninstall']); if ($_GET['ok'] == 1) { PluginHelper::uninstallPlugin($packageName); header("Location: ./plugins.php"); exit; } else { echo AdminQuestionMessage::setText(ACPPluginsT::get('uninstall_confirmation'), true)->addLink(GeneralT::get('yes'), './plugins.php?uninstall=' . htmlspecialchars($packageName) . '&ok=1')->addLink(GeneralT::get('no'), './plugins.php'); }