getServiceLocator()->get('ltiDeliveryProvider/LtiDeliveryExecution'); if (!$ltiDeliveryExecution instanceof KvLtiDeliveryExecutionService) { return new \common_report_Report(\common_report_Report::TYPE_ERROR, ' migration only available for KvLtiDeliveryExecutionService'); } $migrated = false; $persistenceOption = $ltiDeliveryExecution->getOption(KvLtiDeliveryExecutionService::OPTION_PERSISTENCE); $persistence = (is_object($persistenceOption)) ? $persistenceOption : \common_persistence_KeyValuePersistence::getPersistence($persistenceOption); $keys = $persistence->getDriver()->keys(KvLtiDeliveryExecutionService::LTI_DE_LINK_LINK . '*'); foreach ($keys as $key) { $data = $persistence->get($key); if (is_null($data)) { continue; } $objects = $ltiDeliveryExecutionLinks = KvLTIDeliveryExecutionLink::unSerialize($data); /** @var KvLTIDeliveryExecutionLink $object */ foreach ($objects as $object) { $linkKey = KvLtiDeliveryExecutionService::LINKS_OF_DELIVERY_EXECUTION . $object->getUserId() . $object->getDeliveryExecutionId(); $linksOfExecutionAndUser = $persistence->get($linkKey); if (is_null($linksOfExecutionAndUser)) { $linksOfExecutionAndUser = []; } else { $linksOfExecutionAndUser = json_decode($linksOfExecutionAndUser, true); } $linksOfExecutionAndUser[] = $object->getLinkId(); $persistence->set($linkKey, json_encode($linksOfExecutionAndUser)); $migrated = true; } } if ($migrated) { return new \common_report_Report(\common_report_Report::TYPE_SUCCESS, ' migration success'); } return new \common_report_Report(\common_report_Report::TYPE_SUCCESS, ' nothing migrated'); } }