* * Run example: * ``` * sudo -u www-data php index.php 'oat\taoProctoring\scripts\UpdateMonitoringCache' * ``` */ class UpdateMonitoringCache implements Action, ServiceLocatorAwareInterface { use ServiceLocatorAwareTrait; /** * @var Report */ protected $report; /** * @param $params * @return Report */ public function __invoke($params) { $deliveryMonitoringService = $this->getServiceLocator()->get(DeliveryMonitoringService::SERVICE_ID); $deliveryClass = new \core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAODelivery.rdf#AssembledDelivery'); $deliveries = $deliveryClass->getInstances(true); $deliveryExecutionService = ServiceProxy::singleton(); $this->report = new Report( Report::TYPE_INFO, 'Updating of delivery monitoring cache...' ); foreach ($deliveries as $delivery) { if ($delivery->exists()) { $deliveryExecutions = $deliveryExecutionService->getExecutionsByDelivery($delivery); foreach ($deliveryExecutions as $deliveryExecution) { $data = $deliveryMonitoringService->getData($deliveryExecution); $data->updateData(); if ($deliveryMonitoringService->partialSave($data)) { $this->report->add( new Report( Report::TYPE_SUCCESS, "Delivery execution {$deliveryExecution->getUri()} successfully updated." ) ); } else { $errors = $data->getErrors(); $errorsStr = " " . PHP_EOL; array_walk($errors, function ($val, $key) use (&$errorsStr) { $errorsStr .= " $key - $val" . PHP_EOL; }); $this->report->add( new Report( Report::TYPE_ERROR, "Delivery execution {$deliveryExecution->getUri()} was not updated. $errorsStr" ) ); } } } } return $this->report; } }