mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
Add option to execute "install" part of the plugin
This commit is contained in:
parent
19c06df300
commit
36ec2e1e56
31
system/bin/execute_install_plugin.php
Normal file
31
system/bin/execute_install_plugin.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if(PHP_SAPI !== 'cli') {
|
||||||
|
echo 'This script can be run only in command line mode.';
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../common.php';
|
||||||
|
require_once SYSTEM . 'functions.php';
|
||||||
|
require_once SYSTEM . 'init.php';
|
||||||
|
require_once SYSTEM . 'hooks.php';
|
||||||
|
require_once LIBS . 'plugins.php';
|
||||||
|
|
||||||
|
if($argc !== 2) {
|
||||||
|
echo 'This command expects one parameter: plugin name' . PHP_EOL;
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pluginName = $argv[1];
|
||||||
|
if(Plugins::executeInstall($pluginName)) {
|
||||||
|
foreach(Plugins::getWarnings() as $warning) {
|
||||||
|
echo 'WARNING: ' . $warning;
|
||||||
|
}
|
||||||
|
|
||||||
|
$info = Plugins::getPluginJson();
|
||||||
|
echo 'Script for install ' . (isset($info['name']) ? $info['name'] . ' p' : 'P') . 'lugin has been successfully executed.' . PHP_EOL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo 'ERROR: ' . Plugins::getError() . PHP_EOL;
|
||||||
|
exit(3);
|
||||||
|
}
|
@ -557,6 +557,45 @@ class Plugins {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is to execute the "install" part of the plugin
|
||||||
|
*
|
||||||
|
* @param $plugin_name
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function executeInstall($plugin_name): bool
|
||||||
|
{
|
||||||
|
$filename = BASE . 'plugins/' . $plugin_name . '.json';
|
||||||
|
if(!file_exists($filename)) {
|
||||||
|
self::$error = 'Plugin ' . $plugin_name . ' does not exist.';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$string = file_get_contents($filename);
|
||||||
|
$plugin_json = json_decode($string, true);
|
||||||
|
if(!$plugin_json) {
|
||||||
|
self::$error = 'Cannot load plugin info ' . $plugin_name . '.json';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isset($plugin_json['install'])) {
|
||||||
|
self::$error = "Plugin doesn't have install options defined. Skipping...";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
global $db;
|
||||||
|
if (file_exists(BASE . $plugin_json['install'])) {
|
||||||
|
$db->revalidateCache();
|
||||||
|
require BASE . $plugin_json['install'];
|
||||||
|
$db->revalidateCache();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self::$warnings[] = 'Cannot load install script. Your plugin might be not working correctly.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static function uninstall($plugin_name): bool
|
public static function uninstall($plugin_name): bool
|
||||||
{
|
{
|
||||||
$filename = BASE . 'plugins/' . $plugin_name . '.json';
|
$filename = BASE . 'plugins/' . $plugin_name . '.json';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user