<?php
namespace App\Centralstage\DeviceBundle\EventSubscriber;
use App\Centralstage\CoreBundle\Service\LogService;
use App\Centralstage\DeviceBundle\Event\DeviceSummaryEvent as Devicesummary;
use App\Centralstage\DeviceBundle\Models\DeviceDataModel;
use App\Centralstage\CoreBundle\Utils\FileHelper;
use App\Centralstage\ProductionMonitoringBundle\Service\PreGenerateDataService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Process\Process;
class DeviceSummarySubscriber implements EventSubscriberInterface
{
public function onDeviceSummary(Devicesummary $Devicesummary): void
{
try{
//DATA
$EventData = $Devicesummary->getData();
$rawData = base64_encode($EventData["rawData"]);
$orgID = $EventData["orgID"];
$phpExecutable = $_ENV['PHP_EXECUTABLE_PATH'];
$projectRoot = PreGenerateDataService::ProjectPhpBinPath();
if(!empty($rawData) && !empty($orgID)){
$command = [$phpExecutable,"$projectRoot/bin/console",'app:summaryV2',$rawData,$orgID];
$process = new Process($command);
$process->start();
while ($process->isRunning()) {
}
}else{
// LogService::log("error message missing arguments orgID:$orgID rawData:$rawData ", "pushMissingArguments");
}
unset($EventData); //free memory
}catch (\Exception $exception) { $error = $exception->getMessage(); }
}
public static function getSubscribedEvents(): array
{
return [
'device.summary.process' => 'onDeviceSummary'
];
}
}