public function __invoke($params) { $this->verifyParams($params); if ($this->finalReport->containsError()) { return $this->finalReport; } $this->removeServiceState(); $this->removeResults(); $this->removeDeliveryExecutions(); $this->finalReport->setMessage('done'); return $this->finalReport; }
/** * Import a QTI Test Package containing one or more QTI Test definitions. * * @param core_kernel_classes_Class $targetClass The Target RDFS class where you want the Test Resources to be created. * @param string $file The path to the IMS archive you want to import tests from. * @return common_report_Report An import report. */ public function importMultipleTests(core_kernel_classes_Class $targetClass, $file) { $testClass = $targetClass; $report = new common_report_Report(common_report_Report::TYPE_INFO); $validPackage = false; $validManifest = false; $testsFound = false; // Validate the given IMS Package itself (ZIP integrity, presence of an 'imsmanifest.xml' file. $invalidArchiveMsg = __("The provided archive is invalid. Make sure it is not corrupted and that it contains an 'imsmanifest.xml' file."); try { $qtiPackageParser = new taoQtiTest_models_classes_PackageParser($file); $qtiPackageParser->validate(); $validPackage = true; } catch (Exception $e) { $report->add(common_report_Report::createFailure($invalidArchiveMsg)); } // Validate the manifest (well formed XML, valid against the schema). if ($validPackage === true) { $folder = $qtiPackageParser->extract(); if (is_dir($folder) === false) { $report->add(common_report_Report::createFailure($invalidArchiveMsg)); } else { $qtiManifestParser = new taoQtiTest_models_classes_ManifestParser($folder . 'imsmanifest.xml'); $qtiManifestParser->validate(); if ($qtiManifestParser->isValid() === true) { $validManifest = true; $tests = array(); foreach (Resource::getTestTypes() as $type) { $tests = array_merge($tests, $qtiManifestParser->getResources($type)); } $testsFound = count($tests) !== 0; if ($testsFound !== true) { $report->add(common_report_Report::createFailure(__("Package is valid but no tests were found. Make sure that it contains valid QTI tests."))); } else { foreach ($tests as $qtiTestResource) { $report->add($this->importTest($testClass, $qtiTestResource, $qtiManifestParser, $folder)); } } } else { $msg = __("The 'imsmanifest.xml' file found in the archive is not valid."); $report->add(common_report_Report::createFailure($msg)); } // Cleanup the folder where the archive was extracted. tao_helpers_File::deltree($folder); } } if ($report->containsError() === true) { $report->setMessage(__('The IMS QTI Test Package could not be imported.')); $report->setType(common_report_Report::TYPE_ERROR); } else { $report->setMessage(__('IMS QTI Test Package successfully imported.')); $report->setType(common_report_Report::TYPE_SUCCESS); } if ($report->containsError() === true && $validPackage === true && $validManifest === true && $testsFound === true) { // We consider a test package as an atomic component, we then rollback it. $itemService = taoItems_models_classes_ItemsService::singleton(); foreach ($report as $r) { $data = $r->getData(); // Delete all imported items. foreach ($data->items as $item) { common_Logger::i("Rollbacking item '" . $item->getLabel() . "'..."); @$itemService->deleteItem($item); } // Delete the target Item RDFS class. common_Logger::i("Rollbacking Items target RDFS class '" . $data->itemClass->getLabel() . "'..."); @$data->itemClass->delete(); // Delete test definition. common_Logger::i("Rollbacking test '" . $data->rdfsResource->getLabel() . "..."); @$this->deleteTest($data->rdfsResource); if (count($data->items) > 0) { $msg = __("The resources related to the IMS QTI Test referenced as \"%s\" in the IMS Manifest file were rolled back.", $data->manifestResource->getIdentifier()); $report->add(new common_report_Report(common_report_Report::TYPE_WARNING, $msg)); } } } return $report; }