/**
  * 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;
 }
Exemplo n.º 2
0
 public function run(Task $task)
 {
     \common_Logger::d('Running task ' . $task->getId());
     $report = new \common_report_Report(\common_report_Report::TYPE_INFO, __('Running task %s', $task->getId()));
     $queue = $this->getServiceLocator()->get(Queue::CONFIG_ID);
     $queue->updateTaskStatus($task->getId(), Task::STATUS_RUNNING);
     try {
         $actionService = $this->getServiceLocator()->get(ActionService::SERVICE_ID);
         $invocable = $task->getInvocable();
         if (is_string($invocable)) {
             $invocable = $actionService->resolve($task->getInvocable());
         } else {
             if ($invocable instanceof ServiceLocatorAwareInterface) {
                 $invocable->setServiceLocator($this->getServiceLocator());
             }
         }
         $subReport = call_user_func($invocable, $task->getParameters());
         $report->add($subReport);
     } catch (\Exception $e) {
         $message = 'Task ' . $task->getId() . ' failed. Error message: ' . $e->getMessage();
         \common_Logger::e($message);
         $report = new \common_report_Report(\common_report_Report::TYPE_ERROR, $message);
     }
     $queue->updateTaskStatus($task->getId(), Task::STATUS_FINISHED, $report);
     return $report;
 }
 public function __invoke($params)
 {
     $this->dryrun = in_array('dryrun', $params) || in_array('--dryrun', $params);
     /** @var StorageInterface $storageService */
     $storageService = ServiceManager::getServiceManager()->get(StorageInterface::SERVICE_ID);
     $page = 1;
     $rows = 500;
     $this->report = new \common_report_Report(\common_report_Report::TYPE_INFO, 'Converting of dates for the event log');
     while (true) {
         $slice = $storageService->searchInstances(['page' => $page, 'rows' => $rows]);
         if (!count($slice['data'])) {
             break;
         }
         foreach ($slice['data'] as $row) {
             if (empty($row['occurred']) || $row['occurred'] == '0000-00-00 00:00:00') {
                 $this->report->add(new \common_report_Report(\common_report_Report::TYPE_WARNING, 'Would not be converted date in id="' . $row['id'] . '" date is "' . $row['occurred'] . '"'));
                 continue;
             }
             if ($this->dryrun) {
                 $this->report->add(new \common_report_Report(\common_report_Report::TYPE_SUCCESS, 'Would be changed date "' . $row['occurred'] . '" to "' . $this->convertToUtcDate($row['occurred']) . '"'));
             } else {
                 $this->setOccurred($storageService, $row['id'], $this->convertToUtcDate($row['occurred']));
             }
         }
         if ($this->dryrun) {
             $this->report->add(new \common_report_Report(\common_report_Report::TYPE_SUCCESS, 'In the same way would be changed "' . $slice['records'] . '" records'));
             break;
         }
         $page++;
     }
     $this->report->add(new \common_report_Report(\common_report_Report::TYPE_SUCCESS, 'Done'));
     return $this->report;
 }
Exemplo n.º 4
0
 /**
  * @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;
 }
 public function testCompile()
 {
     //test with items
     $config = array('previous' => true);
     $items = array($this->item->getUri());
     $this->testModel->save($this->test, array('itemUris' => $items, 'config' => $config));
     $waitingReport = new \common_report_Report(\common_report_Report::TYPE_SUCCESS);
     $serviceCall = $this->getMockBuilder('tao_models_classes_service_ServiceCall')->disableOriginalConstructor()->setMethods(array('serializeToString'))->getMock();
     $serviceCall->expects($this->once())->method('serializeToString')->willReturn('greatString');
     $waitingReport->setData($serviceCall);
     $testCompiler = $this->getMockBuilder('oat\\taoTestLinear\\model\\TestCompiler')->setConstructorArgs(array($this->test, $this->storage))->setMethods(array('subCompile', 'spawnPrivateDirectory'))->getMock();
     $testCompiler->expects($this->once())->method('subCompile')->willReturn($waitingReport);
     //will spawn a new directory and store the content file
     $directoryMock = $this->getMockBuilder('tao_models_classes_service_StorageDirectory')->disableOriginalConstructor()->setMethods(array('getPath'))->getMock();
     if (!file_exists(sys_get_temp_dir() . '/sample/compile/')) {
         mkdir(sys_get_temp_dir() . '/sample/compile/', 0777, true);
     }
     $directoryMock->expects($this->once())->method('getPath')->willReturn(sys_get_temp_dir() . '/sample/compile/');
     $testCompiler->expects($this->once())->method('spawnPrivateDirectory')->willReturn($directoryMock);
     $report = $testCompiler->compile();
     $this->assertEquals(__('Test Compilation'), $report->getMessage(), __('Compilation should work'));
     $this->assertFileExists(sys_get_temp_dir() . '/sample/compile/data.json', __('Compilation file not created'));
     $compile = '{"items":{"http:\\/\\/myFancyDomain.com\\/myGreatResourceUriForItem":"greatString"},"previous":true}';
     $this->assertEquals($compile, file_get_contents(sys_get_temp_dir() . '/sample/compile/data.json', __('File content error')));
 }
Exemplo n.º 6
0
 /**
  * Contains the logic to render a report and its children to the command line
  *
  * @param common_report_Report $report A report to be rendered.
  * @param boolean $useColor
  * @param integer $intend the intend of the message.
  * @return string The shell output of $report.
  */
 public static function renderToCommandLine(common_report_Report $report, $useColor = self::AUTOSENSE, $intend = 0)
 {
     switch ($report->getType()) {
         case common_report_Report::TYPE_SUCCESS:
             $color = '0;32';
             // green
             break;
         case common_report_Report::TYPE_WARNING:
             $color = '1;33';
             // yellow
             break;
         case common_report_Report::TYPE_ERROR:
             $color = '1;31';
             // red
             break;
         default:
             $color = '0;37';
             // light grey
     }
     if ($useColor == self::AUTOSENSE) {
         $useColor = getenv('TAO_CONSOLE') !== 'nocolor' && !helpers_PlatformInstance::isWindows();
     }
     $output = ($useColor ? "[" . $color . 'm' : '') . ($intend > 0 ? str_repeat(' ', $intend) : '') . $report->getMessage() . ($useColor ? "" : '') . PHP_EOL;
     foreach ($report as $child) {
         $output .= self::renderToCommandline($child, $useColor, $intend + 2);
     }
     return $output;
 }
 /**
  * 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;
 }
Exemplo n.º 8
0
 /**
  * Contains the logic to render a report and its children.
  * 
  * @param common_report_Report $report A report to be rendered.
  * @param array $childRenderedReports An array of strings containing the separate rendering of $report's child reports.
  * @param integer $nesting The current nesting level (root = 0).
  * @return string The HTML output of $report.
  */
 private static function renderReport(common_report_Report $report, array $childRenderedReports = array(), $nesting = 0, $leaf = false)
 {
     switch ($report->getType()) {
         case common_report_Report::TYPE_SUCCESS:
             $typeClass = 'success';
             break;
         case common_report_Report::TYPE_WARNING:
             $typeClass = 'warning';
             break;
         case common_report_Report::TYPE_ERROR:
             $typeClass = 'error';
             break;
         default:
             $typeClass = 'info';
             break;
     }
     $openingTag = '<div class="feedback-' . $typeClass . ' feedback-nesting-' . $nesting . ' ' . ($leaf === true ? 'leaf' : 'hierarchical') . ' tao-scope">';
     $leafIcon = $leaf === true ? ' leaf-icon' : ' hierarchical-icon';
     $icon = '<span class="icon-' . $typeClass . $leafIcon . '"></span>';
     $message = nl2br(_dh($report->__toString()));
     $endingTag = '</div>';
     $okButton = '<p><button id="import-continue" class="btn-info"><span class="icon-right"></span>' . __("Continue") . '</button></p>';
     // Put all the children renderings together.
     $content = implode('', $childRenderedReports);
     return $openingTag . $icon . $message . $content . ($nesting != 0 ? '' : $okButton) . $endingTag;
 }
 /**
  * @param $params
  * @return Report
  */
 public function __invoke($params)
 {
     \common_ext_ExtensionsManager::singleton()->getExtensionById('taoProctoring');
     \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDeliveryRdf');
     \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
     $report = new Report(Report::TYPE_INFO, 'Updating of delivery monitoring cache...');
     $testCenters = TestCenterService::singleton()->getRootClass()->getInstances(true);
     $deliveryMonitoringService = $this->getServiceLocator()->get(DeliveryMonitoringService::CONFIG_ID);
     $deliveryService = $this->getServiceLocator()->get(DeliveryService::CONFIG_ID);
     $eligibilityService = EligibilityService::singleton();
     foreach ($testCenters as $testCenter) {
         $deliveries = $eligibilityService->getEligibleDeliveries($testCenter, false);
         foreach ($deliveries as $delivery) {
             if ($delivery->exists()) {
                 $deliveryExecutions = $deliveryService->getCurrentDeliveryExecutions($delivery->getUri(), $testCenter->getUri());
                 foreach ($deliveryExecutions as $deliveryExecution) {
                     $data = $deliveryMonitoringService->getData($deliveryExecution, true);
                     if ($deliveryMonitoringService->save($data)) {
                         $report->add(new Report(Report::TYPE_SUCCESS, "Delivery execution {$deliveryExecution->getUri()} successfully updated."));
                     } else {
                         $errors = $data->getErrors();
                         $errorsStr = "    " . PHP_EOL;
                         array_walk($errors, function ($val, $key) use(&$errorsStr) {
                             $errorsStr .= "    {$key} - {$val}" . PHP_EOL;
                         });
                         $report->add(new Report(Report::TYPE_ERROR, "Delivery execution {$deliveryExecution->getUri()} was not updated. {$errorsStr}"));
                     }
                 }
             }
         }
     }
     return $report;
 }
Exemplo n.º 10
0
 public function __invoke($params)
 {
     $actionResolver = $this->getServiceLocator()->get(ActionService::SERVICE_ID);
     $report = new \common_report_Report(\common_report_Report::TYPE_INFO, __('Available Actions:'));
     foreach ($actionResolver->getAvailableActions() as $actionClass) {
         $report->add(new \common_report_Report(\common_report_Report::TYPE_INFO, '  ' . $actionClass));
     }
     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;
 }
Exemplo n.º 12
0
 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;
 }
 /**
  *
  * @param unknown $params
  */
 public function __invoke($params)
 {
     if (count($params) < 1) {
         return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('Usage: %s ASSEMBLY_FILE [ASSEMBLY_FILE_2] [ASSEMBLY_FILE_3] ...', __CLASS__));
     }
     \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDeliveryRdf');
     $deliveryClass = DeliveryAssemblyService::singleton()->getRootClass()->createSubClass('Import ' . \tao_helpers_Date::displayeDate(time()));
     $importer = new Assembler();
     $report = new \common_report_Report(\common_report_Report::TYPE_INFO, __('Importing %1$s files into \'%2$s\'', count($params), $deliveryClass->getLabel()));
     while (!empty($params)) {
         $file = array_shift($params);
         $report->add($importer->importDelivery($deliveryClass, $file));
     }
     return $report;
 }
 /**
  * Create a formatted failure report and log a warning
  *
  * @param $userMessage
  * @param null $model
  * @return Report
  */
 private function createFailure($userMessage, $model = null)
 {
     $typeIdentifier = is_null($model) ? 'unknown type' : $model->getTypeIdentifier();
     $message = 'The portable element cannot be registered "' . $typeIdentifier . '", reason: ' . $userMessage;
     \common_Logger::w($message);
     return Report::createFailure($message);
 }
 public static function importDelivery(core_kernel_classes_Class $deliveryClass, $archiveFile)
 {
     $folder = tao_helpers_File::createTempDir();
     $zip = new ZipArchive();
     if ($zip->open($archiveFile) === true) {
         if ($zip->extractTo($folder)) {
             $returnValue = $folder;
         }
         $zip->close();
     }
     $manifestPath = $folder . self::MANIFEST_FILE;
     if (!file_exists($manifestPath)) {
         return common_report_Report::createFailure(__('Manifest not found in assembly'));
     }
     $manifest = json_decode(file_get_contents($manifestPath), true);
     $label = $manifest['label'];
     $serviceCall = tao_models_classes_service_ServiceCall::fromString(base64_decode($manifest['runtime']));
     $dirs = $manifest['dir'];
     $resultServer = taoResultServer_models_classes_ResultServerAuthoringService::singleton()->getDefaultResultServer();
     try {
         foreach ($dirs as $id => $relPath) {
             tao_models_classes_service_FileStorage::singleton()->import($id, $folder . $relPath);
         }
         $delivery = $deliveryClass->createInstanceWithProperties(array(RDFS_LABEL => $label, PROPERTY_COMPILEDDELIVERY_DIRECTORY => array_keys($dirs), PROPERTY_COMPILEDDELIVERY_TIME => time(), PROPERTY_COMPILEDDELIVERY_RUNTIME => $serviceCall->toOntology(), TAO_DELIVERY_RESULTSERVER_PROP => $resultServer));
         $report = common_report_Report::createSuccess(__('Delivery "%s" successfully imported', $label), $delivery);
     } catch (Exception $e) {
         if (isset($delivery) && $delivery instanceof core_kernel_classes_Resource) {
             $delivery->delete();
         }
         $report = common_report_Report::createFailure(__('Unkown error during impoort'));
     }
     return $report;
 }
 /**
  * (non-PHPdoc)
  * @see tao_models_classes_import_ImportHandler::import()
  */
 public function import($class, $form)
 {
     $fileInfo = $form->getValue('source');
     //import for CSV
     if (isset($fileInfo)) {
         set_time_limit(200);
         //the zip extraction is a long process that can exced the 30s timeout
         //get the services instances we will need
         $itemService = taoItems_models_classes_ItemsService::singleton();
         $uploadedFile = $fileInfo['uploaded_file'];
         $uploadedFileBaseName = basename($uploadedFile);
         // uploaded file name contains an extra prefix that we have to remove.
         $uploadedFileBaseName = preg_replace('/^([0-9a-z])+_/', '', $uploadedFileBaseName, 1);
         $uploadedFileBaseName = preg_replace('/.zip|.ZIP$/', '', $uploadedFileBaseName);
         $validate = count($form->getValue('disable_validation')) == 0 ? true : false;
         try {
             $report = taoDelivery_models_classes_import_Assembler::importDelivery($class, $uploadedFile);
         } catch (common_Exception $e) {
             $report = common_report_Report::createFailure(__('An error occured during the import'));
             if ($e instanceof common_exception_UserReadableException) {
                 $report->add($e);
             }
         }
         tao_helpers_File::remove($uploadedFile);
     } else {
         throw new common_exception_Error('No file provided as parameter \'source\' for OWI import');
     }
     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);
 }
 public function importDelivery(core_kernel_classes_Class $deliveryClass, $archiveFile)
 {
     $folder = tao_helpers_File::createTempDir();
     $zip = new ZipArchive();
     if ($zip->open($archiveFile) !== true) {
         return common_report_Report::createFailure(__('Unable to export Archive'));
     }
     $zip->extractTo($folder);
     $zip->close();
     $manifestPath = $folder . self::MANIFEST_FILE;
     if (!file_exists($manifestPath)) {
         return common_report_Report::createFailure(__('Manifest not found in assembly'));
     }
     $manifest = json_decode(file_get_contents($manifestPath), true);
     try {
         $this->importDeliveryFiles($deliveryClass, $manifest, $folder);
         $delivery = $this->importDeliveryResource($deliveryClass, $manifest);
         $report = common_report_Report::createSuccess(__('Delivery "%s" successfully imported', $delivery->getUri()), $delivery);
     } catch (Exception $e) {
         common_Logger::w($e->getMessage());
         if (isset($delivery) && $delivery instanceof core_kernel_classes_Resource) {
             $delivery->delete();
         }
         $report = common_report_Report::createFailure(__('Unkown error during impoort'));
     }
     return $report;
 }
 public function __invoke($params)
 {
     // recreate languages
     $modelCreator = new \tao_install_utils_ModelCreator(LOCAL_NAMESPACE);
     $models = $modelCreator->getLanguageModels();
     foreach ($models as $ns => $modelFiles) {
         foreach ($modelFiles as $file) {
             $modelCreator->insertLocalModel($file);
         }
     }
     OntologyUpdater::syncModels();
     // reapply access rights
     $exts = \common_ext_ExtensionsManager::singleton()->getInstalledExtensions();
     foreach ($exts as $ext) {
         $installer = new \tao_install_ExtensionInstaller($ext);
         $installer->installManagementRole();
         $installer->applyAccessRules();
     }
     // recreate admin
     if (count($params) >= 2) {
         $login = array_shift($params);
         $password = array_shift($params);
         $sysAdmin = $this->getResource(INSTANCE_ROLE_SYSADMIN);
         $userClass = $this->getClass(CLASS_TAO_USER);
         \core_kernel_users_Service::singleton()->addUser($login, $password, $sysAdmin, $userClass);
     }
     // empty cache
     \common_cache_FileCache::singleton()->purge();
     return \common_report_Report::createSuccess('All done');
 }
 /**
  * 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;
 }
Exemplo n.º 21
0
 public function testNestedReport()
 {
     $report = new common_report_Report(common_report_Report::TYPE_WARNING, 'test message3');
     $sub1 = new common_report_Report(common_report_Report::TYPE_INFO, 'info31');
     $sub2 = new common_report_Report(common_report_Report::TYPE_ERROR, 'error31');
     $report->add(array($sub1, $sub2));
     $this->assertTrue($report->hasChildren());
     $this->assertEquals('test message3', (string) $report);
     $this->assertEquals(common_report_Report::TYPE_WARNING, $report->getType());
     $array = array();
     foreach ($report as $child) {
         $array[] = $child;
     }
     $this->assertEquals(2, count($array));
     list($first, $second) = $array;
     $this->assertFalse($first->hasChildren());
     $this->assertEquals('info31', (string) $first);
     $this->assertEquals(common_report_Report::TYPE_INFO, $first->getType());
     foreach ($first as $child) {
         $this->fail('Should not contain children');
     }
     $this->assertFalse($second->hasChildren());
     $this->assertEquals('error31', (string) $second);
     $this->assertEquals(common_report_Report::TYPE_ERROR, $second->getType());
     foreach ($second as $child) {
         $this->fail('Should not contain children');
     }
     $this->assertFalse($report->contains(common_report_Report::TYPE_SUCCESS));
     $this->assertTrue($report->contains(common_report_Report::TYPE_INFO));
     $this->assertTrue($report->contains(common_report_Report::TYPE_ERROR));
 }
 public function export($options = array())
 {
     if (!$this->containsItem()) {
         $report = parent::export($options);
         if (!$report->containsError()) {
             $this->exportManifest($options);
         }
         return $report;
     }
     return \common_report_Report::createSuccess();
 }
Exemplo n.º 23
0
 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;
 }
 public function export($formValues, $destPath)
 {
     if (isset($formValues['filename']) && isset($formValues['uri'])) {
         try {
             /** @var TestExporter $exporterService */
             $exporterService = $this->getServiceManager()->get(TestMetadataExporter::SERVICE_ID);
             $file = $exporterService->export($formValues['uri']);
             return $this->output($file);
         } catch (ExtractorException $e) {
             return \common_report_Report::createFailure('Selected object does not have any item to export.');
         }
     }
 }
 /**
  * (non-PHPdoc)
  * @see \oat\oatbox\action\Action::__invoke()
  */
 public function __invoke($params)
 {
     \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDeliveryRdf');
     if (count($params) != 2) {
         return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('Usage: %s DELIVERY_CLASS_URI OUTPUT_DIRECTORY', __CLASS__));
     }
     $deliveryClassUri = array_shift($params);
     $deliveryClass = new \core_kernel_classes_Class($deliveryClassUri);
     $dir = array_shift($params);
     if (!file_exists($dir) && !mkdir($dir)) {
         return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('Directory %s doesn\'t exist', $dir));
     }
     $dir = rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     $report = new \common_report_Report(\common_report_Report::TYPE_SUCCESS, __('Exporting %s', $deliveryClass->getLabel()));
     foreach ($deliveryClass->getInstances(true) as $delivery) {
         $destFile = $dir . \tao_helpers_File::getSafeFileName($delivery->getLabel()) . '.zip';
         $tmpFile = Assembler::exportCompiledDelivery($delivery);
         \tao_helpers_File::move($tmpFile, $destFile);
         $report->add(new \common_report_Report(\common_report_Report::TYPE_SUCCESS, __('Exported %1$s to %2$s', $delivery->getLabel(), $destFile)));
     }
     return $report;
 }
Exemplo n.º 26
0
 /**
  * @param string $actionIdentifier fully qualified action class name
  * @param array $params Params to be passed to action's __invoke method
  * @return Report
  */
 public function runAction($actionIdentifier, array $params = [])
 {
     try {
         $action = $this->actionService->resolve($actionIdentifier);
     } catch (\common_ext_ManifestNotFoundException $e) {
         $action = new Help(null);
     } catch (ResolutionException $e) {
         $parts = explode('/', $actionIdentifier);
         $extId = $parts[0];
         $action = new Help($extId);
     }
     if ($action instanceof ServiceLocatorAwareInterface) {
         $action->setServiceLocator($this->getServiceLocator());
     }
     try {
         $report = call_user_func($action, $params);
     } catch (\Exception $e) {
         $report = new Report(Report::TYPE_ERROR, __('An exception occured while running "%s"', $actionIdentifier));
         $report->add(new Report(Report::TYPE_ERROR, $e->getMessage()));
     }
     return $report;
 }
Exemplo n.º 27
0
 public function testJsonUnserialize()
 {
     $root = new common_report_Report(common_report_Report::TYPE_WARNING, 'test message3');
     $sub1 = new common_report_Report(common_report_Report::TYPE_INFO, 'info31');
     $sub2 = new common_report_Report(common_report_Report::TYPE_ERROR, 'error31');
     $subsub = new common_report_Report(common_report_Report::TYPE_SUCCESS, 'success31');
     // make report tree
     $sub1->add([$subsub]);
     $root->add([$sub1, $sub2]);
     $json = json_encode($root, JSON_PRETTY_PRINT);
     $report = common_report_Report::jsonUnserialize($json);
     $this->assertTrue($report->hasChildren());
     $this->assertEquals('test message3', (string) $report);
     $this->assertEquals(common_report_Report::TYPE_WARNING, $report->getType());
     $array = array();
     foreach ($report as $child) {
         $array[] = $child;
     }
     $this->assertEquals(2, count($array));
     list($first, $second) = $array;
     $this->assertTrue($first->hasChildren());
     $this->assertEquals('info31', (string) $first);
     $this->assertEquals(common_report_Report::TYPE_INFO, $first->getType());
     foreach ($first as $child) {
         $this->assertEquals('success31', (string) $child);
         $this->assertEquals(common_report_Report::TYPE_SUCCESS, $child->getType());
     }
     $this->assertFalse($second->hasChildren());
     $this->assertEquals('error31', (string) $second);
     $this->assertEquals(common_report_Report::TYPE_ERROR, $second->getType());
     foreach ($second as $child) {
         $this->fail('Should not contain children');
     }
     $this->assertTrue($report->contains(common_report_Report::TYPE_SUCCESS));
     $this->assertTrue($report->contains(common_report_Report::TYPE_INFO));
     $this->assertTrue($report->contains(common_report_Report::TYPE_ERROR));
 }
Exemplo n.º 28
0
 public function __invoke($params)
 {
     try {
         $persistenceId = isset($params[0]) ? $params[0] : 'default';
         $persistence = \common_persistence_Manager::getPersistence($persistenceId);
     } catch (\common_Exception $e) {
         $report = new Report(Report::TYPE_INFO, __('Usage: InitRdsQueue PERSISTENCE_ID'));
         $report->add(new Report(Report::TYPE_ERROR, __('Persistence "%s" could not be loaded', $persistenceId)));
         return $report;
     }
     $schemaManager = $persistence->getDriver()->getSchemaManager();
     $schema = $schemaManager->createSchema();
     $fromSchema = clone $schema;
     try {
         $queueTable = $schema->createtable(RdsQueue::QUEUE_TABLE_NAME);
         $queueTable->addOption('engine', 'MyISAM');
         $queueTable->addColumn(RdsQueue::QUEUE_ID, "string", array("notnull" => true, "length" => 255));
         $queueTable->addColumn(RdsQueue::QUEUE_STATUS, "string", array("notnull" => true, "length" => 50));
         $queueTable->addColumn(RdsQueue::QUEUE_ADDED, "string", array("notnull" => true));
         $queueTable->addColumn(RdsQueue::QUEUE_UPDATED, "string", array("notnull" => true));
         $queueTable->addColumn(RdsQueue::QUEUE_OWNER, "string", array("notnull" => false, "length" => 255));
         $queueTable->addColumn(RdsQueue::QUEUE_TASK, "string", array("notnull" => true, "length" => 4000));
         $queueTable->addColumn(RdsQueue::QUEUE_REPORT, "text", array("default" => null, "notnull" => false));
         $queueTable->setPrimaryKey(array(RdsQueue::QUEUE_ID));
         $queries = $persistence->getPlatform()->getMigrateSchemaSql($fromSchema, $schema);
         foreach ($queries as $query) {
             $persistence->exec($query);
         }
     } catch (SchemaException $e) {
         \common_Logger::i('Database Schema already up to date.');
     }
     $queue = new RdsQueue(array(RdsQueue::OPTION_PERSISTENCE => $persistenceId));
     $queue->setServiceLocator($this->getServiceLocator());
     $this->getServiceLocator()->register(Queue::CONFIG_ID, $queue);
     return new \common_report_Report(\common_report_Report::TYPE_SUCCESS, __('Setup rds queue successfully using persistence "%s"', $persistenceId));
 }
 public function __invoke($params)
 {
     $run = false;
     if (!empty($params) && $params[0] === 'run') {
         $run = true;
     }
     \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem');
     $fs = \taoItems_models_classes_ItemsService::singleton()->getDefaultFileSource();
     $itemUpdater = new ItemFixTextReaderDefaultValue($fs->getPath());
     $res = $itemUpdater->update($run);
     if ($run) {
         return \common_report_Report::createSuccess('Item fixed ' . count($res));
     } else {
         return \common_report_Report::createInfo('Item to be fixed ' . count($res));
     }
 }
 /**
  * After form submitting, export data & output file
  *
  * @param array $formValues
  * @param string $destPath
  * @return \common_report_Report|void
  * @throws \common_Exception
  * @throws \common_exception_BadRequest
  */
 public function export($formValues, $destPath)
 {
     if (isset($formValues['filename']) && isset($formValues['classUri'])) {
         $classToExport = $this->getClassToExport($formValues['classUri']);
         if ($classToExport->exists()) {
             try {
                 /** @var ItemExporter $exporterService */
                 $exporterService = $this->getServiceManager()->get(SimpleExporter::SERVICE_ID);
                 $file = $exporterService->export($this->getInstances($classToExport), true);
                 return $this->output($file);
             } catch (ExtractorException $e) {
                 return \common_report_Report::createFailure('Selected object does not have any item to export.');
             }
         }
     }
     return;
 }