Implement system for user packages in composer (#13718)

This commit is contained in:
Jellyfrog
2022-02-02 17:33:23 +01:00
committed by GitHub
parent 2dcc70301c
commit fdebee86b4
8 changed files with 200 additions and 17 deletions

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use LibreNMS\ComposerHelper;
class PluginAddCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'plugin:add {package} {version?}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Install a plugin';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
// Add package to "real" composer.json first, to catch dependency failures etc.
if (ComposerHelper::addPackage($this->argument('package'), $this->argument('version')) == 0) {
return ComposerHelper::addPlugin($this->argument('package'), $this->argument('version'));
}
return 1;
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use LibreNMS\ComposerHelper;
class PluginRemoveCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'plugin:remove {package}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Remove an installed plugin';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
// Remove package from plugin first
// in case of failure, daily.sh should then be able to cleanup and leftover mess.
ComposerHelper::removePlugin($this->argument('package'));
ComposerHelper::removePackage($this->argument('package'));
return 0;
}
}