/**
  * Executes the plug-in test.
  * @param $pluginCategory string
  * @param $pluginDir string
  * @param $pluginName string
  * @param $filterGroups array
  */
 protected function executePluginTest($pluginCategory, $pluginDir, $pluginName, $filterGroups)
 {
     // Make sure that the xml configuration is valid.
     $filterConfigFile = 'plugins/' . $pluginCategory . '/' . $pluginDir . '/filter/' . PLUGIN_FILTER_DATAFILE;
     $this->validateXmlConfig(array('./' . $filterConfigFile, './lib/pkp/' . $filterConfigFile));
     // Make sure that data from earlier tests is being deleted first.
     $filterDao =& DAORegistry::getDAO('FilterDAO');
     /* @var $filterDao FilterDAO */
     foreach ($filterGroups as $filterGroupSymbolic) {
         foreach ($filterDao->getObjectsByGroup($filterGroupSymbolic) as $filter) {
             $filterDao->deleteObject($filter);
         }
         foreach ($filterDao->getObjectsByGroup($filterGroupSymbolic, 0, true) as $filter) {
             $filterDao->deleteObject($filter);
         }
     }
     $filterGroupDao =& DAORegistry::getDAO('FilterGroupDAO');
     /* @var $filterGroupDao FilterGroupDAO */
     foreach ($filterGroups as $filterGroupSymbolic) {
         $filterGroupDao->deleteObjectBySymbolic($filterGroupSymbolic);
     }
     // Mock request and router.
     import('lib.pkp.classes.core.PKPRouter');
     import('classes.core.Request');
     $mockRequest = $this->getMock('Request', array('getRouter', 'getUser'));
     $router = new PKPRouter();
     $mockRequest->expects($this->any())->method('getRouter')->will($this->returnValue($router));
     $mockRequest->expects($this->any())->method('getUser')->will($this->returnValue(null));
     Registry::set('request', $mockRequest);
     // Instantiate the installer.
     import('classes.install.Install');
     $installFile = './lib/pkp/tests/plugins/testPluginInstall.xml';
     $params = $this->getConnectionParams();
     $installer = new Install($params, $installFile, true);
     // Parse the plug-ins version.xml.
     import('lib.pkp.classes.site.VersionCheck');
     self::assertFileExists($versionFile = './plugins/' . $pluginCategory . '/' . $pluginDir . '/version.xml');
     self::assertArrayHasKey('version', $versionInfo =& VersionCheck::parseVersionXML($versionFile));
     self::assertType('Version', $pluginVersion =& $versionInfo['version']);
     $installer->setCurrentVersion($pluginVersion);
     // Install the plug-in.
     self::assertTrue($installer->execute());
     // Reset the hook registry.
     Registry::set('hooks', $nullVar = null);
     // Test whether the installation is idempotent.
     self::assertTrue($installer->execute());
     // Test whether the filter groups have been installed.
     foreach ($filterGroups as $filterGroupSymbolic) {
         // Check the group.
         self::assertType('FilterGroup', $filterGroupDao->getObjectBySymbolic($filterGroupSymbolic), $filterGroupSymbolic);
     }
 }
 /**
  * Installs the uploaded plugin
  * @param $path string path to plugin Directory
  * @param $templateMgr reference to template manager
  * @return boolean
  */
 function installPlugin($path, &$templateMgr)
 {
     $this->validate();
     $versionFile = $path . VERSION_FILE;
     $templateMgr->assign('error', true);
     $templateMgr->assign('pageHierarchy', $this->setBreadcrumbs(true));
     $pluginVersion =& VersionCheck::getValidPluginVersionInfo($versionFile, $templateMgr);
     if (is_null($pluginVersion)) {
         return false;
     }
     assert(is_a($pluginVersion, 'Version'));
     $versionDao =& DAORegistry::getDAO('VersionDAO');
     /* @var $versionDao VersionDAO */
     $installedPlugin = $versionDao->getCurrentVersion($pluginVersion->getProductType(), $pluginVersion->getProduct(), true);
     if (!$installedPlugin) {
         $pluginLibDest = Core::getBaseDir() . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'pkp' . DIRECTORY_SEPARATOR . strtr($pluginVersion->getProductType(), '.', DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $pluginVersion->getProduct();
         $pluginDest = Core::getBaseDir() . DIRECTORY_SEPARATOR . strtr($pluginVersion->getProductType(), '.', DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $pluginVersion->getProduct();
         // Copy the plug-in from the temporary folder to the
         // target folder.
         // Start with the library part (if any).
         $libPath = $path . DIRECTORY_SEPARATOR . 'lib';
         if (is_dir($libPath)) {
             if (!FileManager::copyDir($libPath, $pluginLibDest)) {
                 $templateMgr->assign('message', 'manager.plugins.copyError');
                 return false;
             }
             // Remove the library part of the temporary folder.
             FileManager::rmtree($libPath);
         }
         // Continue with the application-specific part (mandatory).
         if (!FileManager::copyDir($path, $pluginDest)) {
             $templateMgr->assign('message', 'manager.plugins.copyError');
             return false;
         }
         // Remove the temporary folder.
         FileManager::rmtree(dirname($path));
         // Upgrade the database with the new plug-in.
         $installFile = $pluginDest . INSTALL_FILE;
         if (!is_file($installFile)) {
             $installFile = Core::getBaseDir() . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'pkp' . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'defaultPluginInstall.xml';
         }
         assert(is_file($installFile));
         $params = $this->_setConnectionParams();
         $installer = new Install($params, $installFile, true);
         $installer->setCurrentVersion($pluginVersion);
         if (!$installer->execute()) {
             // Roll back the copy
             if (is_dir($pluginLibDest)) {
                 FileManager::rmtree($pluginLibDest);
             }
             if (is_dir($pluginDest)) {
                 FileManager::rmtree($pluginDest);
             }
             $templateMgr->assign('message', array('manager.plugins.installFailed', $installer->getErrorString()));
             return false;
         }
         $message = array('manager.plugins.installSuccessful', $pluginVersion->getVersionString());
         $templateMgr->assign('message', $message);
         $templateMgr->assign('uploaded', true);
         $templateMgr->assign('error', false);
         $versionDao->insertVersion($pluginVersion, true);
         return true;
     } else {
         if ($this->_checkIfNewer($pluginVersion->getProductType(), $pluginVersion->getProduct(), $pluginVersion)) {
             $templateMgr->assign('message', 'manager.plugins.pleaseUpgrade');
             return false;
         } else {
             $templateMgr->assign('message', 'manager.plugins.installedVersionOlder');
             return false;
         }
     }
 }
 /**
  * Installs the uploaded plugin
  * @param $path string path to plugin Directory
  * @param $templateMgr reference to template manager
  * @return boolean
  */
 function installPlugin($path, &$templateMgr)
 {
     $this->validate();
     $versionFile = $path . VERSION_FILE;
     $templateMgr->assign('error', true);
     $templateMgr->assign('path', 'install');
     $pluginVersion =& VersionCheck::getValidPluginVersionInfo($versionFile, $templateMgr);
     if (is_null($pluginVersion)) {
         return false;
     }
     assert(is_a($pluginVersion, 'Version'));
     $versionDao =& DAORegistry::getDAO('VersionDAO');
     $installedPlugin = $versionDao->getCurrentVersion($pluginVersion->getProduct(), true);
     if (!$installedPlugin) {
         $pluginDest = Core::getBaseDir() . DIRECTORY_SEPARATOR . strtr($pluginVersion->getProductType(), '.', DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $pluginVersion->getProduct();
         if (!FileManager::copyDir($path, $pluginDest)) {
             $templateMgr->assign('message', 'manager.plugins.copyError');
             return false;
         }
         // If plugin has an install.xml file, update database with it
         $installFile = $pluginDest . INSTALL_FILE;
         if (FileManager::fileExists($installFile)) {
             $params = $this->setConnectionParams();
             $installer = new Install($params, $installFile, true);
             $installer->setCurrentVersion($pluginVersion);
             if (!$installer->execute()) {
                 // Roll back the copy
                 FileManager::rmtree($pluginDest);
                 $templateMgr->assign('message', array('manager.plugins.installFailed', $installer->getErrorString()));
                 return false;
             }
         }
         $message = array('manager.plugins.installSuccessful', $pluginVersion->getVersionString());
         $templateMgr->assign('message', $message);
         $templateMgr->assign('uploaded', true);
         $templateMgr->assign('error', false);
         $versionDao->insertVersion($pluginVersion, true);
         return true;
     } else {
         if ($this->checkIfNewer($pluginVersion->getProduct(), $pluginVersion)) {
             $templateMgr->assign('message', 'manager.plugins.pleaseUpgrade');
             return false;
         } else {
             $templateMgr->assign('message', 'manager.plugins.installedVersionOlder');
             return false;
         }
     }
 }
Exemple #4
0
 /**
  * Installs an extracted plugin
  * @param $path string path to plugin Directory
  * @param $errorMsg string Reference to string receiving error message
  * @return Version|null Version of installed plugin on success
  */
 function installPlugin($path, &$errorMsg)
 {
     $versionFile = $path . '/' . PLUGIN_VERSION_FILE;
     $pluginVersion = VersionCheck::getValidPluginVersionInfo($versionFile, $errorMsg);
     if (!$pluginVersion) {
         return null;
     }
     $versionDao = DAORegistry::getDAO('VersionDAO');
     /* @var $versionDao VersionDAO */
     $installedPlugin = $versionDao->getCurrentVersion($pluginVersion->getProductType(), $pluginVersion->getProduct(), true);
     if (!$installedPlugin) {
         $pluginLibDest = Core::getBaseDir() . '/' . PKP_LIB_PATH . '/' . strtr($pluginVersion->getProductType(), '.', '/') . '/' . $pluginVersion->getProduct();
         $pluginDest = Core::getBaseDir() . '/' . strtr($pluginVersion->getProductType(), '.', '/') . '/' . $pluginVersion->getProduct();
         // Copy the plug-in from the temporary folder to the
         // target folder.
         // Start with the library part (if any).
         $libPath = $path . '/lib';
         $fileManager = new FileManager();
         if (is_dir($libPath)) {
             if (!$fileManager->copyDir($libPath, $pluginLibDest)) {
                 $errorMsg = __('manager.plugins.copyError');
                 return null;
             }
             // Remove the library part of the temporary folder.
             $fileManager->rmtree($libPath);
         }
         // Continue with the application-specific part (mandatory).
         if (!$fileManager->copyDir($path, $pluginDest)) {
             $errorMsg = __('manager.plugins.copyError');
             return null;
         }
         // Remove the temporary folder.
         $fileManager->rmtree(dirname($path));
         // Upgrade the database with the new plug-in.
         $installFile = $pluginDest . '/' . PLUGIN_INSTALL_FILE;
         if (!is_file($installFile)) {
             $installFile = Core::getBaseDir() . '/' . PKP_LIB_PATH . '/xml/defaultPluginInstall.xml';
         }
         assert(is_file($installFile));
         $params = $this->_getConnectionParams();
         $installer = new Install($params, $installFile, true);
         $installer->setCurrentVersion($pluginVersion);
         if (!$installer->execute()) {
             // Roll back the copy
             if (is_dir($pluginLibDest)) {
                 $fileManager->rmtree($pluginLibDest);
             }
             if (is_dir($pluginDest)) {
                 $fileManager->rmtree($pluginDest);
             }
             $errorMsg = __('manager.plugins.installFailed', array('errorString' => $installer->getErrorString()));
             return null;
         }
         $versionDao->insertVersion($pluginVersion, true);
         return $pluginVersion;
     } else {
         if ($this->_checkIfNewer($pluginVersion->getProductType(), $pluginVersion->getProduct(), $pluginVersion)) {
             $errorMsg = __('manager.plugins.pleaseUpgrade');
         } else {
             $errorMsg = __('manager.plugins.installedVersionOlder');
         }
     }
     return null;
 }
 /**
  * Installs the uploaded plugin
  * @param $path string path to plugin Directory
  * @param $templateMgr reference to template manager
  * @return boolean
  */
 function installPlugin($path, &$templateMgr)
 {
     $versionFile = $path . VERSION_FILE;
     $templateMgr->assign('error', true);
     $templateMgr->assign('path', 'install');
     if (FileManager::fileExists($versionFile)) {
         $versionInfo =& VersionCheck::parseVersionXML($versionFile);
     } else {
         $templateMgr->assign('message', 'manager.plugins.versionFileNotFound');
         return false;
     }
     $pluginVersion = $versionInfo['version'];
     $pluginName = $pluginVersion->getProduct();
     $pluginType = explode(".", $versionInfo['type']);
     $category = $pluginType[1];
     $versionDao =& DAORegistry::getDAO('VersionDAO');
     $installedPlugin = $versionDao->getCurrentVersion($pluginName, false, true);
     if (!$installedPlugin) {
         $pluginDest = Core::getBaseDir() . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $category . DIRECTORY_SEPARATOR . $pluginName;
         if (!FileManager::copyDir($path, $pluginDest)) {
             $templateMgr->assign('message', 'manager.plugins.copyError');
             return false;
         }
         // If plugin has an install.xml file, update database with it
         $installFile = $pluginDest . DIRECTORY_SEPARATOR . INSTALL_FILE;
         if (FileManager::fileExists($installFile)) {
             $params = $this->setConnectionParams();
             $installer = new Install($params, $installFile, true);
             $installer->setCurrentVersion($pluginVersion);
             if (!$installer->execute()) {
                 // Roll back the copy
                 FileManager::rmtree($pluginDest);
                 $templateMgr->assign('message', array('manager.plugins.installFailed', $installer->getErrorString()));
                 return false;
             }
         }
         $message = array('manager.plugins.installSuccessful', $pluginVersion->getVersionString());
         $templateMgr->assign('message', $message);
         $templateMgr->assign('uploaded', true);
         $templateMgr->assign('error', false);
         $pluginVersion->setCurrent(1);
         $versionDao->insertVersion($pluginVersion);
         return true;
     } else {
         if ($this->checkIfNewer($pluginName, $pluginVersion)) {
             $templateMgr->assign('message', 'manager.plugins.pleaseUpgrade');
             return false;
         }
         if (!$this->checkIfNewer($pluginName, $pluginVersion)) {
             $templateMgr->assign('message', 'manager.plugins.installedVersionOlder');
             return false;
         }
     }
 }