Следующий код необходим для выполнения простой команды в командной строке в LimeSurvey.
Структура вашей папки в upload/plugins
должна быть такой:
- HelloWorld
- config.xml
- HelloWorld.php
<?xml version="1.0" encoding="UTF-8"?>
<config>
<metadata>
<name>HelloWorld</name>
<type>plugin</type>
<lastUpdate>2022-05-21</lastUpdate>
<author>My Name</author>
<authorEmail>My Email Address</authorEmail>
<authorUrl>MY Homepage</authorUrl>
<license></license>
<version>1.0.0</version>
<description><![CDATA[This Plugin does some magic on the command line]]></description>
</metadata>
<compatibility>
<version>5.0</version>
<version>4.0</version>
<version>3.0</version>
</compatibility>
</config>
class HelloWorld extends PluginBase
{
protected $storage = 'LimeSurveyPluginManagerDbStorage';
static protected $description = 'HelloWorld';
static protected $name = 'HelloWorld';
/**
* subscribe to all needed events
* @see https://manual.limesurvey.org/Plugin_events
*/
public function init()
{
/** @see https://manual.limesurvey.org/Direct_(command) */
$this->subscribe('direct');
}
/**
* php application/commands/console.php plugin --target=HelloWorld
*/
public function direct()
{
$event = $this->getEvent();
$target = $event->get('target');
if ($target != get_class()) return;
echo 'HELLO WORLD' . PHP_EOL;
exit;
}
}
В PluginManager scan files
LimeSurvey установите и активируйте плагин.
Затем в командной строке запустите:
И, надеюсь, вы сможете увидеть: Hello World
Пока!