예제 #1
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;
 }
예제 #2
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));
 }
 /**
  * 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;
 }
예제 #4
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;
 }
 /**
  * (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;
 }
예제 #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 integer $intend the intend of the message.
  * @return string The HTML output of $report.
  */
 public static function renderToCommandline(common_report_Report $report, $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
     }
     $output = "[" . $color . 'm' . ($intend > 0 ? str_repeat(' ', $intend) : '') . $report->getMessage() . "" . PHP_EOL;
     foreach ($report as $child) {
         $output .= self::renderToCommandline($child, $intend + 2);
     }
     return $output;
 }
예제 #7
0
 /**
  * Returns a report
  * 
  * @param common_report_Report $report
  */
 protected function returnReport(common_report_Report $report, $refresh = true)
 {
     if ($refresh) {
         $data = $report->getdata();
         if ($report->getType() == common_report_Report::TYPE_SUCCESS && !is_null($data) && $data instanceof \core_kernel_classes_Resource) {
             $this->setData('message', $report->getMessage());
             $this->setData('selectNode', tao_helpers_Uri::encode($data->getUri()));
             $this->setData('reload', true);
             return $this->setView('form.tpl', 'tao');
         }
     }
     $this->setData('report', $report);
     $this->setView('report.tpl', 'tao');
 }
 /**
  * 
  * @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;
 }
 protected function onAfterImport(common_report_Report $report)
 {
     if (common_report_Report::TYPE_SUCCESS == $report->getType()) {
         $this->getEventManager()->trigger(new TestImportEvent($report));
     }
 }