/** * (non-PHPdoc) * @see \oat\oatbox\action\Action::__invoke() */ public function __invoke($params) { $merged = array_merge(common_ext_ExtensionsManager::singleton()->getInstalledExtensions(), $this->getMissingExtensions()); $sorted = \helpers_ExtensionHelper::sortByDependencies($merged); $report = new common_report_Report(common_report_Report::TYPE_INFO, 'Running extension update'); foreach ($sorted as $ext) { try { if (!common_ext_ExtensionsManager::singleton()->isInstalled($ext->getId())) { $installer = new \tao_install_ExtensionInstaller($ext); $installer->install(); $report->add(new common_report_Report(common_report_Report::TYPE_SUCCESS, 'Installed ' . $ext->getName())); } else { $report->add($this->updateExtension($ext)); } } catch (common_ext_MissingExtensionException $ex) { $report->add(new common_report_Report(common_report_Report::TYPE_ERROR, $ex->getMessage())); break; } catch (common_ext_OutdatedVersionException $ex) { $report->add(new common_report_Report(common_report_Report::TYPE_ERROR, $ex->getMessage())); break; } catch (Exception $e) { $this->logError('Exception during update of ' . $ext->getId() . ': ' . get_class($e) . ' "' . $e->getMessage() . '"'); $report->setType(common_report_Report::TYPE_ERROR); $report->setTitle('Update failed'); $report->add(new common_report_Report(common_report_Report::TYPE_ERROR, 'Exception during update of ' . $ext->getId() . '.')); break; } } $this->logInfo(helpers_Report::renderToCommandline($report, false)); 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; }
/** * @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; }
/** * 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; }
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; }
/** * 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; }
/** * * @param unknown $xhtml * @param unknown $destination * @return common_report_Report */ public static function retrieveExternalResources($xhtml, $destination) { if (!file_exists($destination)) { if (!mkdir($destination)) { common_Logger::e('Folder ' . $destination . ' could not be created'); return new common_report_Report(common_report_Report::TYPE_ERROR, __('Unable to create deployement directory'), $xhtml); } } $authorizedMedia = self::$defaultMedia; $mediaList = array(); $expr = "/http[s]?:(\\\\)?\\/(\\\\)?\\/[^<'\"&?]+\\.(" . implode('|', $authorizedMedia) . ")/mi"; //take into account json encoded url preg_match_all($expr, $xhtml, $mediaList, PREG_PATTERN_ORDER); $uniqueMediaList = array_unique($mediaList[0]); $report = new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Retrieving external resources')); foreach ($uniqueMediaList as $mediaUrl) { // This is a file that has to be stored in the item compilation folder itself... // I do not get why they are all copied. They are all there they were copied from the item module... // But I agree that remote resources (somewhere on the Internet) should be copied via curl. // So if the URL does not matches a place where the TAO server is, we curl the resource and store it. // FileManager files should be considered as remote resources to avoid 404 issues. Indeed, a backoffice // user might delete an image in the filemanager during a delivery campain. This is dangerous. $decodedMediaUrl = str_replace('\\/', '/', $mediaUrl); $mediaPath = self::retrieveFile($decodedMediaUrl, $destination); if (!empty($mediaPath) && $mediaPath !== false) { $xhtml = str_replace($mediaUrl, basename($mediaPath), $xhtml, $replaced); //replace only when copyFile is successful } else { $report->add(new common_report_Report(common_report_Report::TYPE_ERROR, __('Failed retrieving %s', $decodedMediaUrl))); $report->setType(common_report_Report::TYPE_ERROR); } } if ($report->getType() == common_report_Report::TYPE_SUCCESS) { $report->setData($xhtml); } return $report; }
/** * Walk through the cloned process and replace the item runner placeholders * * @param core_kernel_classes_Resource $processDefinition */ protected function process(core_kernel_classes_Resource $processDefinition) { $report = new common_report_Report(common_report_Report::TYPE_SUCCESS); $activities = wfEngine_models_classes_ProcessDefinitionService::singleton()->getAllActivities($processDefinition); foreach ($activities as $activity) { $services = wfEngine_models_classes_ActivityService::singleton()->getInteractiveServices($activity); foreach ($services as $service) { $serviceDefinition = $service->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_CALLOFSERVICES_SERVICEDEFINITION)); if ($serviceDefinition->getUri() == INSTANCE_ITEMCONTAINER_SERVICE) { $item = taoWfTest_models_classes_WfTestService::singleton()->getItemByService($service); if (is_null($item)) { $report->add($this->fail(__('No valid item found for service "%s"', $service->getLabel()))); } else { $itemReport = $this->subCompile($item); if ($itemReport->getType() == common_report_Report::TYPE_SUCCESS) { $serviceCall = $itemReport->getData(); $storedServiceCall = $serviceCall->toOntology(); // remove old service wfEngine_models_classes_InteractiveServiceService::singleton()->deleteInteractiveService($service); $activity->removePropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_INTERACTIVESERVICES), $service); // add new service $activity->setPropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_INTERACTIVESERVICES), $storedServiceCall); } $report->add($itemReport); if ($itemReport->getType() != common_report_Report::TYPE_SUCCESS) { $report->setType($itemReport->getType()); } } } } } 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; }