mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Implement system for user packages in composer (#13718)
This commit is contained in:
48
app/Console/Commands/PluginAddCommand.php
Normal file
48
app/Console/Commands/PluginAddCommand.php
Normal 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;
|
||||
}
|
||||
}
|
48
app/Console/Commands/PluginRemoveCommand.php
Normal file
48
app/Console/Commands/PluginRemoveCommand.php
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user