aboutsummaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/Commands/Checks/GlobalizedConfig.php148
-rw-r--r--cli/Commands/Checks/HelpTours.php4
-rw-r--r--cli/Commands/CleanupAdmissionRules.php2
-rw-r--r--cli/Commands/Cronjobs/CronjobExecute.php2
-rw-r--r--cli/Commands/DI/Reset.php30
-rw-r--r--cli/Commands/OAuth2/Keys.php6
-rw-r--r--cli/Commands/Plugins/PluginInfo.php4
-rw-r--r--cli/Commands/SORM/DescribeModels.php1
-rw-r--r--cli/Commands/Twillo/PrivateKeys.php6
-rwxr-xr-xcli/studip2
10 files changed, 44 insertions, 161 deletions
diff --git a/cli/Commands/Checks/GlobalizedConfig.php b/cli/Commands/Checks/GlobalizedConfig.php
deleted file mode 100644
index 373534a..0000000
--- a/cli/Commands/Checks/GlobalizedConfig.php
+++ /dev/null
@@ -1,148 +0,0 @@
-<?php
-namespace Studip\Cli\Commands\Checks;
-
-use Config;
-use DirectoryIterator;
-use FilesystemIterator;
-use RecursiveDirectoryIterator;
-use RecursiveIteratorIterator;
-use RecursiveRegexIterator;
-use RegexIterator;
-use Studip\Cli\Commands\AbstractCommand;
-use Symfony\Component\Console\Command\Command;
-use Symfony\Component\Console\Input\InputArgument;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Output\OutputInterface;
-
-final class GlobalizedConfig extends AbstractCommand
-{
- protected static $defaultName = 'check:globalized-config';
-
- protected function configure(): void
- {
- $this->setDescription(
- '<href=https://develop.studip.de/trac/ticket/5671>TIC 5671</> scanner - Globalized config'
- );
- $this->setHelp(
- 'Scans files for occurences of globalized config items (see <href=https://develop.studip.de/trac/ticket/5671>ticket 5671</> for more info)'
- );
-
- $this->addOption('filenames', 'f', InputOption::VALUE_NONE, 'Display filenames only (excludes -m and -o)');
- $this->addOption('matches', 'm', InputOption::VALUE_NONE, 'Show matched config variables');
- $this->addOption(
- 'recursive',
- 'r',
- InputOption::VALUE_NONE | InputOption::VALUE_NEGATABLE,
- 'Do not scan recursively into subfolders'
- );
- $this->addOption('occurences', 'o', InputOption::VALUE_NONE, 'Show occurences in files');
-
- $this->addArgument(
- 'folder',
- InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
- 'Folder(s) to scan (pass the special value of "plugins" to scan the plugin folder)',
- [$GLOBALS['STUDIP_BASE_PATH']]
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output): int
- {
- $only_filenames = (bool) $input->getOption('filenames');
- $show_occurences = !$only_filenames && ($output->isVerbose() || $input->getOption('occurences'));
- $show_matches = !$only_filenames && ($show_occurences || $input->getOption('matches'));
- $recursive = $input->getOption('recursive') ?? true;
-
- $folders = $input->getArgument('folder');
- foreach ($folders as $index => $folder) {
- if ($folder === 'plugins') {
- $folders[$index] = $GLOBALS['STUDIP_BASE_PATH'] . '/public/plugins_packages/';
- }
- }
- $folders = array_unique($folders);
-
- $config = Config::get()->getFields('global');
- $quoted = array_map(function ($item) {
- return preg_quote($item, '/');
- }, $config);
- $regexp = '/\$(?:GLOBALS\[["\']?)?(' . implode('|', $quoted) . ')\b/S';
-
- foreach ($folders as $folder) {
- if (!file_exists($folder) || !is_dir($folder)) {
- $output->writeln(
- "Skipping non-folder argument <fg=red>{$folder}</>",
- OutputInterface::VERBOSITY_VERBOSE
- );
- continue;
- }
- $output->writeln("Scanning {$folder}", OutputInterface::VERBOSITY_VERBOSE);
-
- foreach ($this->getFolderIterator($folder, $recursive, ['php', 'tpl', 'inc']) as $file) {
- $filename = $file->getPathName();
- $contents = file_get_contents($filename);
-
- $output->writeln(
- sprintf(
- 'Check <fg=magenta>%s</>',
- $this->relativeFilePath($filename)
- ),
- OutputInterface::VERBOSITY_VERBOSE
- );
-
- if ($matched = preg_match_all($regexp, $contents, $matches)) {
- if ($only_filenames) {
- $output->writeln($filename);
- } else {
- $output->writeln(
- sprintf(
- '%u matched variable(s) in <fg=green;options=bold>%s</>',
- $matched,
- $this->shorten($filename)
- )
- );
- if ($show_matches) {
- $variables = array_unique($matches[1]);
- foreach ($variables as $variable) {
- $output->writeln("> <fg=cyan>{$variable}</>");
- if ($show_occurences) {
- $output->writeln($this->highlight($contents, $variable));
- }
- }
- }
- }
- }
- }
- }
-
- return Command::SUCCESS;
- }
-
- private function highlight(string $content, string $variable): string
- {
- $lines = explode("\n", $content);
-
- $result = [];
- foreach ($lines as $index => $line) {
- if (mb_strpos($line, $variable) === false) {
- continue;
- }
- $result[$index + 1] = $line;
- }
-
- if (!$result) {
- return '';
- }
-
- $max = max(array_map('mb_strlen', array_keys($result)));
-
- foreach ($result as $index => $line) {
- $result[$index] = sprintf(
- "<fg=yellow>:%0{$max}u:</> %s",
- $index,
- str_replace($variable, "<fg=black;bg=yellow>{$variable}</>", $line)
- );
- }
-
- return implode("\n", $result);
- }
-}
diff --git a/cli/Commands/Checks/HelpTours.php b/cli/Commands/Checks/HelpTours.php
index b4b2fa7..b0c201a 100644
--- a/cli/Commands/Checks/HelpTours.php
+++ b/cli/Commands/Checks/HelpTours.php
@@ -59,7 +59,7 @@ class HelpTours extends Command
$plugin = new $plugin_info['class']();
if ($result[1]) {
- $dispatcher = app(\Trails_Dispatcher::class);
+ $dispatcher = app(\Trails\Dispatcher::class);
$dispatcher->trails_root = $GLOBALS['ABSOLUTE_PATH_STUDIP'] . $plugin->getPluginPath();
$dispatcher->trails_uri = rtrim(\PluginEngine::getLink($plugin, [], null, true), '/');
$dispatcher->default_controller = 'index';
@@ -71,7 +71,7 @@ class HelpTours extends Command
}
}
} elseif (match_route('dispatch.php/*', $step->route)) {
- $dispatcher = app(\Trails_Dispatcher::class);
+ $dispatcher = app(\Trails\Dispatcher::class);
$parsed = $dispatcher->parse(substr($step->route, strlen('dispatch.php') + 1));
$controller = $dispatcher->load_controller($parsed[0]);
if ($parsed[1] && !$controller->has_action($parsed[1])) {
diff --git a/cli/Commands/CleanupAdmissionRules.php b/cli/Commands/CleanupAdmissionRules.php
index 3079ae4..a7036d3 100644
--- a/cli/Commands/CleanupAdmissionRules.php
+++ b/cli/Commands/CleanupAdmissionRules.php
@@ -18,7 +18,7 @@ class CleanupAdmissionRules extends Command
protected function execute(InputInterface $input, OutputInterface $output): int
{
- require_once 'lib/classes/admission/CourseSet.class.php';
+ require_once 'lib/classes/admission/CourseSet.php';
$course_set = new \CourseSet();
diff --git a/cli/Commands/Cronjobs/CronjobExecute.php b/cli/Commands/Cronjobs/CronjobExecute.php
index d4789ea..93b5ddb 100644
--- a/cli/Commands/Cronjobs/CronjobExecute.php
+++ b/cli/Commands/Cronjobs/CronjobExecute.php
@@ -96,7 +96,7 @@ class CronjobExecute extends Command
if (strlen($value) && !ctype_digit($value)) {
throw new \RuntimeException('Number is invalid.');
}
- return $value;
+ return (int) $value;
});
}
}
diff --git a/cli/Commands/DI/Reset.php b/cli/Commands/DI/Reset.php
new file mode 100644
index 0000000..646bfb6
--- /dev/null
+++ b/cli/Commands/DI/Reset.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Studip\Cli\Commands\DI;
+
+use Studip\DIContainer;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class Reset extends Command
+{
+ protected static $defaultName = 'di:reset';
+
+ protected function configure(): void
+ {
+ $this->setDescription('Resets the compiled DI container');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output): int
+ {
+ $file = DIContainer::getCompilationPath() . '/' . DIContainer::getCompilationClass() . '.php';
+
+ if (file_exists($file) && !unlink($file)) {
+ $output->writeln('<error>Could not removed compiled file.</error>');
+ return Command::FAILURE;
+ }
+
+ return Command::SUCCESS;
+ }
+}
diff --git a/cli/Commands/OAuth2/Keys.php b/cli/Commands/OAuth2/Keys.php
index 609ac4e..9132ad6 100644
--- a/cli/Commands/OAuth2/Keys.php
+++ b/cli/Commands/OAuth2/Keys.php
@@ -46,9 +46,9 @@ class Keys extends Command
$this->storeKeyContentsToFile($encryptionKey, $this->generateEncryptionKey());
- $keys = RSA::createKey(4096);
- $this->storeKeyContentsToFile($publicKey, $keys->getPublicKey()->toString('PKCS1'));
- $this->storeKeyContentsToFile($privateKey, $keys->toString('PKCS1'));
+ $key = RSA::createKey(4096);
+ $this->storeKeyContentsToFile($publicKey, (string) $key->getPublicKey());
+ $this->storeKeyContentsToFile($privateKey, (string) $key);
$io->info('Schlüsseldateien erfolgreich angelegt.');
diff --git a/cli/Commands/Plugins/PluginInfo.php b/cli/Commands/Plugins/PluginInfo.php
index 9809b13..c8f9748 100644
--- a/cli/Commands/Plugins/PluginInfo.php
+++ b/cli/Commands/Plugins/PluginInfo.php
@@ -65,11 +65,11 @@ class PluginInfo extends AbstractPluginCommand
private function pluginClassExists(string $plugindir, array $plugin)
{
- $pluginfile = $plugindir . $plugin['class'] . '.class.php';
+ $pluginfile = $plugindir . $plugin['class'] . '.php';
if (file_exists($pluginfile)) {
return 1;
} else {
- $pluginfile = $plugindir . $plugin['class'] . '.php';
+ $pluginfile = $plugindir . $plugin['class'] . '.class.php';
if (file_exists($pluginfile)) {
return 1;
}
diff --git a/cli/Commands/SORM/DescribeModels.php b/cli/Commands/SORM/DescribeModels.php
index 46dd8ff..b1084d6 100644
--- a/cli/Commands/SORM/DescribeModels.php
+++ b/cli/Commands/SORM/DescribeModels.php
@@ -156,6 +156,7 @@ final class DescribeModels extends AbstractCommand
if (
$options['foreign_key'] !== 'id'
+ && !is_callable($options['foreign_key'])
&& isset($meta['fields'][$options['foreign_key']])
&& $meta['fields'][$options['foreign_key']]['null'] === 'YES'
) {
diff --git a/cli/Commands/Twillo/PrivateKeys.php b/cli/Commands/Twillo/PrivateKeys.php
index 06dd121..c517e5b 100644
--- a/cli/Commands/Twillo/PrivateKeys.php
+++ b/cli/Commands/Twillo/PrivateKeys.php
@@ -2,7 +2,7 @@
namespace Studip\Cli\Commands\Twillo;
use Config;
-use EduSharingHelper;
+use \EduSharingApiClient\EduSharingHelper;
use Studip\Cli\Commands\AbstractCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
@@ -32,13 +32,13 @@ final class PrivateKeys extends AbstractCommand
$key = EduSharingHelper::generateKeyPair();
$success = file_put_contents(
$properties,
- EduSharingHelper::generateEduAppXMLData($appId, $key['publickey'])
+ EduSharingHelper::generateEduAppXMLData($appId, $key['publicKey'])
);
if ($success !== false) {
file_put_contents(
$privateKey,
- $key['privatekey']
+ $key['privateKey']
);
Config::get()->store('OERCAMPUS_TWILLO_APPID', $appId);
diff --git a/cli/studip b/cli/studip
index a46a00d..858dc3d 100755
--- a/cli/studip
+++ b/cli/studip
@@ -15,7 +15,6 @@ $commands = [
Commands\Base\Dump::class,
Commands\Base\Tinker::class,
Commands\Checks\Compatibility::class,
- Commands\Checks\GlobalizedConfig::class,
Commands\Checks\HelpTours::class,
Commands\Checks\HelpTours::class,
Commands\CleanupAdmissionRules::class,
@@ -33,6 +32,7 @@ $commands = [
Commands\Cronjobs\CronjobWorker::class,
Commands\DB\Dump::class,
Commands\DB\MoveMatrikelnummer::class,
+ Commands\DI\Reset::class,
Commands\Files\Dump::class,
Commands\Fix\Biest7789::class,
Commands\Fix\Biest7866::class,