16 import(
'lib.pkp.classes.site.Version');
17 import(
'lib.pkp.classes.site.VersionCheck');
18 import(
'lib.pkp.classes.file.FileManager');
19 import(
'classes.install.Install');
20 import(
'classes.install.Upgrade');
22 define(
'PLUGIN_ACTION_UPLOAD',
'upload');
23 define(
'PLUGIN_ACTION_UPGRADE',
'upgrade');
25 define(
'PLUGIN_VERSION_FILE',
'version.xml');
26 define(
'PLUGIN_INSTALL_FILE',
'install.xml');
27 define(
'PLUGIN_UPGRADE_FILE',
'upgrade.xml');
43 $pluginShortName = array_pop($matches);
44 if (!$pluginShortName) {
45 throw new Exception(__(
'manager.plugins.invalidPluginArchive'));
49 $pluginExtractDir = dirname($filePath) . DIRECTORY_SEPARATOR . $pluginShortName . substr(md5(mt_rand()), 0, 10);
50 if (!mkdir($pluginExtractDir))
throw new Exception(
'Could not create directory ' . $pluginExtractDir);
54 if (empty($tarBinary) || !file_exists($tarBinary)) {
55 rmdir($pluginExtractDir);
56 throw new Exception(__(
'manager.plugins.tarCommandNotFound'));
61 if (in_array(
'exec', explode(
',', ini_get(
'disable_functions'))))
throw new Exception(
'The "exec" PHP function has been disabled on your server. Contact your system adminstrator to enable it.');
62 exec($tarBinary.
' -xzf ' . escapeshellarg($filePath) .
' -C ' . escapeshellarg($pluginExtractDir), $output, $returnCode);
64 $fileManager->rmtree($pluginExtractDir);
65 throw new Exception(__(
'form.dropzone.dictInvalidFileType'));
70 if (is_dir($tryDir = $pluginExtractDir .
'/' . $pluginShortName)) {
78 if (is_dir($tryDir = $pluginExtractDir .
'/' . array_pop($matches))) {
87 $fileManager->rmtree($pluginExtractDir);
88 throw new Exception(__(
'manager.plugins.invalidPluginArchive'));
97 $versionFile = $path .
'/' . PLUGIN_VERSION_FILE;
102 $installedPlugin = $versionDao->getCurrentVersion($pluginVersion->getProductType(), $pluginVersion->getProduct(),
true);
103 $pluginDest =
Core::getBaseDir() .
'/' . strtr($pluginVersion->getProductType(),
'.',
'/') .
'/' . $pluginVersion->getProduct();
105 if ($installedPlugin && file_exists($pluginDest)) {
106 if ($this->
_checkIfNewer($pluginVersion->getProductType(), $pluginVersion->getProduct(), $pluginVersion)) {
107 throw new Exception(__(
'manager.plugins.pleaseUpgrade'));
109 throw new Exception(__(
'manager.plugins.installedVersionOlder'));
115 if (!$fileManager->copyDir($path, $pluginDest))
throw new Exception(
'Could not copy plugin to desination!');
116 if (!$fileManager->rmtree($path))
throw new Exception(
'Could not remove temporary plugin path!');
119 $installFile = $pluginDest .
'/' . PLUGIN_INSTALL_FILE;
120 if(!is_file($installFile)) $installFile =
Core::getBaseDir() .
'/' . PKP_LIB_PATH .
'/xml/defaultPluginInstall.xml';
121 assert(is_file($installFile));
123 $site = $siteDao->getSite();
125 $params[
'locale'] = $site->getPrimaryLocale();
126 $params[
'additionalLocales'] = $site->getSupportedLocales();
127 $installer =
new Install($params, $installFile,
true);
128 $installer->setCurrentVersion($pluginVersion);
129 if (!$installer->execute()) {
131 if (is_dir($pluginDest)) $fileManager->rmtree($pluginDest);
132 throw new Exception(__(
'manager.plugins.installFailed', array(
'errorString' => $installer->getErrorString())));
135 $versionDao->insertVersion($pluginVersion,
true);
136 return $pluginVersion;
148 $installedPlugin = $versionDao->getCurrentVersion($productType, $productName,
true);
149 if ($installedPlugin && $installedPlugin->compare($newVersion) > 0)
return true;
160 'connectionCharset' =>
Config::getVar(
'i18n',
'connection_charset'),
179 $versionFile = $path .
'/' . PLUGIN_VERSION_FILE;
183 if (
'plugins.'.$category != $pluginVersion->getProductType()) {
184 throw new Exception(__(
'manager.plugins.wrongCategory'));
187 if ($plugin != $pluginVersion->getProduct()) {
188 throw new Exception(__(
'manager.plugins.wrongName'));
192 $installedPlugin = $versionDao->getCurrentVersion($pluginVersion->getProductType(), $pluginVersion->getProduct(),
true);
193 if(!$installedPlugin) {
194 throw new Exception(__(
'manager.plugins.pleaseInstall'));
197 if ($this->
_checkIfNewer($pluginVersion->getProductType(), $pluginVersion->getProduct(), $pluginVersion)) {
198 throw new Exception(__(
'manager.plugins.installedVersionNewer'));
204 if (is_dir($pluginDest)) $fileManager->rmtree($pluginDest);
207 if(is_dir($pluginDest)) {
208 throw new Exception(__(
'manager.plugins.deleteError', array(
'pluginName' => $pluginVersion->getProduct())));
212 if (!$fileManager->copyDir($path, $pluginDest))
throw new Exception(
'Could not copy plugin to desination!');
213 if (!$fileManager->rmtree($path))
throw new Exception(
'Could not remove temporary plugin path!');
215 $upgradeFile = $pluginDest .
'/' . PLUGIN_UPGRADE_FILE;
216 if($fileManager->fileExists($upgradeFile)) {
218 $site = $siteDao->getSite();
220 $params[
'locale'] = $site->getPrimaryLocale();
221 $params[
'additionalLocales'] = $site->getSupportedLocales();
222 $installer =
new Upgrade($params, $upgradeFile,
true);
224 if (!$installer->execute())
throw new Exception(__(
'manager.plugins.upgradeFailed', array(
'errorString' => $installer->getErrorString())));
227 $installedPlugin->setCurrent(0);
228 $pluginVersion->setCurrent(1);
229 $versionDao->insertVersion($pluginVersion,
true);
230 return $pluginVersion;