*/ class UpdateDelivery extends AbstractAction implements \JsonSerializable { use OntologyAwareTrait; const OPTION_WHERE = 'where'; const OPTION_PARAMETERS = 'parameters'; /** * @param $params * @throws \common_exception_MissingParameter * @return \common_report_Report */ public function __invoke($params) { $propertyValues = $params[self::OPTION_PARAMETERS]; $where = $params[self::OPTION_WHERE]; $deliveryModelClass = new \core_kernel_classes_Class(DeliveryAssemblyService::CLASS_URI); $deliveries = $deliveryModelClass->searchInstances($where, ['like' => false, 'recursive' => true]); $report = Report::createSuccess(); /** @var \core_kernel_classes_Resource $delivery */ foreach ($deliveries as $key => $delivery) { foreach ($propertyValues as $rdfKey => $rdfValue) { $rdfKey = \tao_helpers_Uri::decode($rdfKey); $property = $this->getProperty($rdfKey); $delivery->editPropertyValues($property, $rdfValue); } $report->add(Report::createSuccess($delivery->getUri())); } return $report; } /** * @return string */ public function jsonSerialize() { return __CLASS__; } /** * Create a task to update a delivery * @param array $where * @param array $propertyValues * @return TaskInterface */ public static function createTask($where = [], $propertyValues = []) { $serviceManager = ServiceManager::getServiceManager(); $action = new self(); $action->setServiceLocator($serviceManager); $parameters = [ self::OPTION_WHERE => $where, self::OPTION_PARAMETERS => $propertyValues ]; /** @var QueueDispatcher $queueDispatcher */ $queueDispatcher = ServiceManager::getServiceManager()->get(QueueDispatcher::SERVICE_ID); return $queueDispatcher->createTask($action, $parameters, null, null, true); } }