Select Git revision
Container.php
Forked from
Stud.IP / Stud.IP
Source project has a limited visibility.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
TracToGitlabPlugin.php 3.67 KiB
<?php
require_once __DIR__ . '/bootstrap.php';
final class TracToGitlabPlugin extends StudIPPlugin implements StandardPlugin, SystemPlugin
{
private $container = null;
public function __construct()
{
parent::__construct();
if (!is_object($GLOBALS['user']) || $GLOBALS['user']->id === 'nobody') {
return;
}
$this->buildNavigation();
}
public function getDIContainer()
{
if ($this->container === null) {
require_once __DIR__ . '/vendor/autoload.php';
$this->container = new Pimple\Container();
$this->container['trac'] = function () {
return new TracToGitlab\TracLookup(Config::get()->TRAC2GITLAB_TRAC_URL);
};
$this->container['gitlab'] = function () {
$builder = new Gitlab\HttpClient\Builder(
new GuzzleHttp\Client(),
new Http\Factory\Guzzle\RequestFactory(),
new Http\Factory\Guzzle\StreamFactory(),
new Http\Factory\Guzzle\UriFactory()
);
$client = new Gitlab\Client($builder);
$client->setUrl(Config::get()->TRAC2GITLAB_GITLAB_URL);
$client->authenticate(Config::get()->TRAC2GITLAB_GITLAB_TOKEN, Gitlab\Client::AUTH_HTTP_TOKEN);
return $client;
};
$this->container['gitlabProjectId'] = function () {
return Config::get()->TRAC2GITLAB_GITLAB_PROJECT_ID;
};
$this->container['gitlabPager'] = function ($c) {
return new Gitlab\ResultPager($c['gitlab']);
};
$this->container['parsedown'] = function () {
$parsedown = new Parsedown();
$parsedown->setSafeMode(true);
return $parsedown;
};
}
return $this->container;
}
public function getIconNavigation($course_id, $last_visit, $user_id)
{
return null;
}
public function getTabNavigation($course_id)
{
return [
'trac2gitlab' => new Navigation('trac2gitlab', PluginEngine::getURL($this, [], 'convert')),
];
}
public function getInfoTemplate($course_id)
{
return null;
}
public function getPluginName()
{
return 'Tickets von trac zu GitLab migrieren';
}
public function isActivatableForContext(Range $context)
{
if (!$context instanceof Course) {
return false;
}
$query = "SELECT 1
FROM `tools_activated`
WHERE `plugin_id` = ?
AND `range_id` != ?";
$activated = DBManager::get()->fetchColumn($query, [
$this->getPluginId(),
$context->id
]);
return !$activated;
}
public function perform($unconsumed)
{
$this->addStylesheet('assets/style.scss');
$this->addScript('assets/script.js');
parent::perform($unconsumed);
}
private function buildNavigation()
{
$navigation = new Navigation(_('Dashboard'), PluginEngine::getURL($this, [], 'dashboard'));
$navigation->setImage(Icon::create($this->getPluginURL() . '/assets/cardiogram.svg', Icon::ROLE_NAVIGATION));
$navigation->addSubnavigation(
'dashboard',
new Navigation(_('Dashboard'), PluginEngine::getURL($this, [], 'dashboard'))
);
$navigation->addSubnavigation(
'translations',
new Navigation(_('Übersetzungen'), PluginEngine::getURL($this, [], 'translations'))
);
Navigation::addItem('/gitlab-dashboard', $navigation);
}
}