Skip to content
Snippets Groups Projects
Commit 0838788b authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by David Siegfried
Browse files

use PluginAdministration::registerPlugin() in cli command `plugin:register`, fixes #702

Closes #702

Merge request studip/studip!1579
parent b8ac06e9
No related branches found
No related tags found
No related merge requests found
...@@ -22,61 +22,19 @@ class PluginRegister extends AbstractPluginCommand ...@@ -22,61 +22,19 @@ class PluginRegister extends AbstractPluginCommand
protected function execute(InputInterface $input, OutputInterface $output): int protected function execute(InputInterface $input, OutputInterface $output): int
{ {
$pluginpath = $input->getArgument('pluginpath'); $pluginpath = $input->getArgument('pluginpath');
$pluginManager = \PluginManager::getInstance();
$manifest = $pluginManager->getPluginManifest($pluginpath);
if (!$manifest) {
$output->writeln('<error>The plugin\'s manifest is missing.</error>');
return Command::FAILURE;
}
// get plugin meta data try {
$pluginclass = $manifest['pluginclassname']; // This will try to set the language to english so we have a
$origin = $manifest['origin']; // consistent usage of english in cli commands.
$minVersion = $manifest['studipMinVersion']; setTempLanguage(false, 'en_GB');
$maxVersion = $manifest['studipMaxVersion'];
// check for compatible version $plugin_administration = new \PluginAdministration();
if ( $plugin_administration->registerPlugin($pluginpath);
(isset($minVersion) && \StudipVersion::olderThan($minVersion)) || } catch (\PluginInstallationException $e) {
(isset($maxVersion) && \StudipVersion::newerThan($maxVersion)) $output->writeln("<error>{$e->getMessage()}</error>");
) {
$output->writeln('<error>The plugin is not compatible with this version of Stud.IP.</error>');
return Command::FAILURE; return Command::FAILURE;
} } finally {
restoreLanguage();
// determine the plugin path
$pluginregistered = $pluginManager->getPluginInfo($pluginclass);
// create database schema if needed
if (isset($manifest['dbscheme']) && !$pluginregistered) {
$schemafile = $pluginpath . '/' . $manifest['dbscheme'];
$contents = file_get_contents($schemafile);
$statements = preg_split("/;[[:space:]]*\n/", $contents, -1, PREG_SPLIT_NO_EMPTY);
$db = \DBManager::get();
foreach ($statements as $statement) {
$db->exec($statement);
}
}
// check for migrations
if (is_dir($pluginpath . '/migrations')) {
$schemaVersion = new \DBSchemaVersion($manifest['pluginname']);
$migrator = new \Migrator($pluginpath . '/migrations', $schemaVersion);
$migrator->migrateTo(null);
}
$pluginpath = $origin . '/' . $pluginclass;
// now register the plugin in the database
$pluginid = $pluginManager->registerPlugin($manifest['pluginname'], $pluginclass, $pluginpath);
// register additional plugin classes in this package
$additionalclasses = $manifest['additionalclasses'];
if (is_array($additionalclasses)) {
foreach ($additionalclasses as $class) {
$pluginManager->registerPlugin($class, $class, $pluginpath, $pluginid);
}
} }
$output->writeln('The plugin was successfully registered.'); $output->writeln('The plugin was successfully registered.');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment