/** * @return Report * @throws \common_exception_Error */ public function runQueue() { $count = 0; $statistics = array(); $queue = $this->getServiceManager()->get(Queue::CONFIG_ID); $report = new Report(Report::TYPE_SUCCESS); $limit = $this->getLimit(); foreach ($queue as $task) { $subReport = $this->runTask($task); $statistics[$subReport->getType()] = isset($statistics[$subReport->getType()]) ? $statistics[$subReport->getType()] + 1 : 1; $report->add($subReport); $count++; if ($limit !== 0 && $count === $limit) { break; } } if (empty($statistics)) { $report = new Report(Report::TYPE_INFO, __('No tasks to run')); } else { if (isset($statistics[Report::TYPE_ERROR]) || isset($statistics[Report::TYPE_WARNING])) { $report->setType(Report::TYPE_WARNING); } $report->setMessage(__('Ran %s task(s):', array_sum($statistics))); } return $report; }
/** * Compile an item. * * @param core_kernel_file_File $destinationDirectory * @throws taoItems_models_classes_CompilationFailedException * @return tao_models_classes_service_ServiceCall */ public function compile() { $destinationDirectory = $this->spawnPublicDirectory(); $item = $this->getResource(); $itemUri = $item->getUri(); $report = new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Published %s', $item->getLabel())); if (!taoItems_models_classes_ItemsService::singleton()->isItemModelDefined($item)) { return $this->fail(__('Item \'%s\' has no model', $item->getLabel())); } $langs = $this->getContentUsedLanguages(); foreach ($langs as $compilationLanguage) { $compiledFolder = $this->getLanguageCompilationPath($destinationDirectory, $compilationLanguage); if (!is_dir($compiledFolder)) { if (!@mkdir($compiledFolder)) { common_Logger::e('Could not create directory ' . $compiledFolder, 'COMPILER'); return $this->fail(__('Could not create language specific directory for item \'%s\'', $item->getLabel())); } } $langReport = $this->deployItem($item, $compilationLanguage, $compiledFolder); $report->add($langReport); if ($langReport->getType() == common_report_Report::TYPE_ERROR) { $report->setType(common_report_Report::TYPE_ERROR); break; } } if ($report->getType() == common_report_Report::TYPE_SUCCESS) { $report->setData($this->createService($item, $destinationDirectory)); } else { $report->setMessage(__('Failed to publish %s', $item->getLabel())); } return $report; }
/** * Apply css to all instances of this class and its subclasses * * @param \core_kernel_classes_Class $class * @param $destPath, optional * @return \common_report_Report * @throws \common_exception_Error */ public function applyToClass(\core_kernel_classes_Class $class, $destPath = null) { $destPath = is_null($destPath) ? basename($this->cssFile) : $destPath; if (strtolower(substr(strrchr($destPath, '.'), 1)) !== 'css') { throw new \common_exception_Error($destPath . ' does not appear to be a stylesheet'); } $report = new \common_report_Report(\common_report_Report::TYPE_SUCCESS); $itemIterator = new \core_kernel_classes_ResourceIterator(array($class)); $count = 0; foreach ($itemIterator as $item) { // is QTI? $model = \taoItems_models_classes_ItemsService::singleton()->getItemModel($item); if (!is_null($model) && $model->getUri() == TAO_ITEM_MODEL_QTI) { $subReport = $this->applyToItem($item, $destPath); $report->add($subReport); if ($subReport->getType() == \common_report_Report::TYPE_SUCCESS) { $count++; } else { $report->setType($subReport->getType()); } } } $report->setMessage($count > 0 ? __('%1s has been applied to %2s items', basename($destPath), $count) : __('CSS was not applied to any items')); return $report; }
/** * @param core_kernel_classes_Resource $instance * @param $tmpFile * * @return \common_report_Report */ public function updateInstanceAttachment($instance, $tmpFile) { $report = new \common_report_Report(\common_report_Report::TYPE_SUCCESS); StorageService::removeAttachedFile($instance); $fileResource = StorageService::storeFile($tmpFile); $property = new \core_kernel_classes_Property(self::PROPERTY_FILE_CONTENT); $instance->editPropertyValues($property, $fileResource); $report->setMessage(__('%s updated', $instance->getLabel())); $report->setData($instance); return $report; }
public function __invoke($params) { $tasksRun = 0; $queue = $this->getServiceManager()->get(Queue::CONFIG_ID); $runner = new TaskRunner(); $report = new \common_report_Report(\common_report_Report::TYPE_SUCCESS); foreach ($queue as $task) { $subReport = $runner->run($task); $tasksRun++; $report->add($subReport); } $report->setMessage(__('Successfully ran %s tasks:', $tasksRun)); return $report; }
public function __invoke($params) { $statistics = array(); $queue = $this->getServiceManager()->get(Queue::CONFIG_ID); $runner = new TaskRunner(); $report = new Report(Report::TYPE_SUCCESS); foreach ($queue as $task) { $subReport = $runner->run($task); $statistics[$subReport->getType()] = isset($statistics[$subReport->getType()]) ? $statistics[$subReport->getType()] + 1 : 1; $report->add($subReport); } if (empty($statistics)) { $report = new Report(Report::TYPE_INFO, __('No tasks to run')); } else { if (isset($statistics[Report::TYPE_ERROR]) || isset($statistics[Report::TYPE_WARNING])) { $report->setType(Report::TYPE_WARNING); } $report->setMessage(__('Ran %s task(s):', array_sum($statistics))); } return $report; }
/** * (non-PHPdoc) * @see tao_models_classes_Compiler::compile() */ public function compile() { $report = new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Published test "%s"', $this->getResource()->getLabel())); common_ext_ExtensionsManager::singleton()->getExtensionById('taoWfTest'); // loads the extension $test = $this->getResource(); common_Logger::i('Compiling test ' . $test->getLabel() . ' items'); $process = $test->getUniquePropertyValue(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP)); if (count(wfEngine_models_classes_ProcessDefinitionService::singleton()->getAllActivities($process)) == 0) { return new common_report_Report(common_report_Report::TYPE_ERROR, __('An empty test cannot be published.')); } $processCloner = new wfAuthoring_models_classes_ProcessCloner(); try { $processClone = $processCloner->cloneProcess($process); $report->add(new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Cloned the process %s', $process->getLabel()))); $itemsServiceReport = $this->process($processClone); foreach ($itemsServiceReport as $subReport) { $report->add($subReport); } if ($itemsServiceReport->getType() == common_report_Report::TYPE_SUCCESS) { $serviceCall = new tao_models_classes_service_ServiceCall(new core_kernel_classes_Resource(INSTANCE_SERVICE_PROCESSRUNNER)); $param = new tao_models_classes_service_ConstantParameter(new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_PROCESSDEFINITION), $processClone->getUri()); $serviceCall->addInParameter($param); $report->setData($serviceCall); } else { $report->setType(common_report_Report::TYPE_ERROR); } } catch (common_Exception $e) { $report->add(new common_report_Report(common_report_Report::TYPE_ERROR, __('Failed to clone the process'))); $report->setType(common_report_Report::TYPE_ERROR); } if ($report->getType() != common_report_Report::TYPE_SUCCESS) { $report->setMessage(__('Failed to publish test "%s".', $this->getResource()->getLabel())); } return $report; }
/** * Compile the items referended by $compactDoc. * * @param XmlCompactDocument $compactDoc An XmlCompactDocument object referencing the items of the test. * @throws taoQtiTest_models_classes_QtiTestCompilationFailedException If the test does not refer to at least one item. * @return common_report_Report */ protected function compileItems(XmlCompactDocument $compactDoc) { $report = new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Items Compilation')); $iterator = new QtiComponentIterator($compactDoc->getDocumentComponent(), array('assessmentItemRef')); $itemCount = 0; foreach ($iterator as $assessmentItemRef) { // Each item could take some time to be compiled, making the request to timeout. helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::SHORT); $itemToCompile = new core_kernel_classes_Resource($assessmentItemRef->getHref()); $subReport = $this->subCompile($itemToCompile); $report->add($subReport); if ($subReport->getType() == common_report_Report::TYPE_SUCCESS) { $itemService = $subReport->getdata(); $inputValues = tao_models_classes_service_ServiceCallHelper::getInputValues($itemService, array()); $assessmentItemRef->setHref($inputValues['itemUri'] . '|' . $inputValues['itemPath'] . '|' . $inputValues['itemDataPath']); } else { $report->setType(common_report_Report::TYPE_ERROR); } // Count the item even if it fails to avoid false "no item" error. $itemCount++; common_Logger::t("QTI Item successfully compiled and registered as a service call in the QTI Test Definition."); } if ($itemCount === 0) { $report->setType(common_report_Report::TYPE_ERROR); $report->setMessage(__("A QTI Test must contain at least one QTI Item to be compiled. None found.")); } return $report; }
protected function removeDeliveryExecutions() { $report = new \common_report_Report(\common_report_Report::TYPE_SUCCESS); // deliveryExecutions $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDelivery'); $deliveryService = $extension->getConfig('execution_service'); if ($deliveryService instanceof \taoDelivery_models_classes_execution_KeyValueService) { $persistenceOption = $deliveryService->getOption(\taoDelivery_models_classes_execution_KeyValueService::OPTION_PERSISTENCE); $persistence = \common_persistence_KeyValuePersistence::getPersistence($persistenceOption); $count = 0; foreach ($persistence->keys('kve_*') as $key) { if (substr($key, 0, 4) == 'kve_') { $persistence->del($key); $count++; } } $report->setMessage('Removed ' . $count . ' key-value delivery executions'); } elseif ($deliveryService instanceof \taoDelivery_models_classes_execution_OntologyService) { $count = 0; $deliveryExecutionClass = new \core_kernel_classes_Class(\taoDelivery_models_classes_execution_OntologyDeliveryExecution::CLASS_URI); $deliveryExecutions = $deliveryExecutionClass->getInstances(); /** @var \core_kernel_classes_Class $deliveryExecution */ foreach ($deliveryExecutions as $deliveryExecution) { $deliveryExecution->delete(true); $count++; } $report->setMessage('Removed ' . $count . ' ontology delivery executions'); } else { $report->setType(\common_report_Report::TYPE_ERROR); $report->setMessage('Cannot cleanup delivery executions from ' . get_class($deliveryService)); } $this->finalReport->add($report); }
/** * 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; }
/** * Imports the currently loaded CsvFile into the destination Class. * The map should be set in the options before executing it. * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param string $source * @param core_kernel_classes_Class $destination * @return common_report_Report */ public function import($source, core_kernel_classes_Class $destination = null) { if (!isset($this->options['map'])) { throw new BadFunctionCallException("import map not set"); } if (is_null($destination)) { throw new InvalidArgumentException("{$destination} must be a valid core_kernel_classes_Class"); } $csvData = $this->load($source); $createdResources = 0; $toImport = $csvData->count(); $rangeProperty = new core_kernel_classes_Property(RDFS_RANGE); $report = new common_report_Report(common_report_Report::TYPE_ERROR, __('Data not imported. All records are invalid.')); for ($rowIterator = 0; $rowIterator < $csvData->count(); $rowIterator++) { helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::SHORT); common_Logger::d("CSV - Importing CSV row {$rowIterator}."); $resource = null; $csvRow = $csvData->getRow($rowIterator); try { // default values $evaluatedData = $this->options['staticMap']; // validate csv values foreach ($this->options['map'] as $propUri => $csvColumn) { $this->validate($destination, $propUri, $csvRow, $csvColumn); } // evaluate csv values foreach ($this->options['map'] as $propUri => $csvColumn) { if ($csvColumn != 'csv_null' && $csvColumn != 'csv_select') { // process value if (isset($csvRow[$csvColumn]) && !is_null($csvRow[$csvColumn])) { $property = new core_kernel_classes_Property($propUri); $evaluatedData[$propUri] = $this->evaluateValues($csvColumn, $property, $csvRow[$csvColumn]); } } } // create resource $resource = $destination->createInstanceWithProperties($evaluatedData); // Apply 'resourceImported' callbacks. foreach ($this->resourceImported as $callback) { $callback($resource); } $report->add(new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Imported resource "%s"', $resource->getLabel()), $resource)); $createdResources++; } catch (ValidationException $valExc) { $failure = common_report_Report::createFailure(__('Row %s', $rowIterator + 1) . ' ' . $valExc->getProperty()->getLabel() . ': ' . $valExc->getUserMessage() . ' "' . $valExc->getValue() . '"'); $report->add($failure); } helpers_TimeOutHelper::reset(); } $this->addOption('to_import', $toImport); $this->addOption('imported', $createdResources); if ($createdResources == $toImport) { $report->setType(common_report_Report::TYPE_SUCCESS); $report->setMessage(__('Imported %d resources', $toImport)); } elseif ($createdResources > 0) { $report->setType(common_report_Report::TYPE_WARNING); $report->setMessage(__('Imported %1$d/%2$d. Some records are invalid.', $createdResources, $toImport)); } return $report; }