/**
  * @param CerbereReportActionEvent $event
  */
 public function onReportAction(CerbereReportActionEvent $event)
 {
     $current_dir = getcwd();
     try {
         // Change current directory to the module directory.
         $workingDirectory = $event->getProject()->getWorkingDirectory();
         if (!is_dir($workingDirectory)) {
             throw new \Exception('Missing folder');
         }
         @chdir($workingDirectory);
         $hacked = new HackedProject($event->getProject());
         $result = $hacked->computeReport();
     } catch (\Exception $e) {
         // Todo: log error.
         $result = array();
     }
     $result += array('status' => HackedProject::STATUS_UNCHECKED, 'counts' => array());
     // Restore previous directory.
     chdir($current_dir);
     $report = $event->getReport();
     $options = $event->getOptions();
     // Alter report.
     if (!empty($options['flat'])) {
         $report['hacked_status'] = $result['status'];
         $report['hacked_label'] = HackedProject::getStatusLabel($result['status']);
     } else {
         $report['hacked'] = array('status' => $result['status'], 'status_label' => HackedProject::getStatusLabel($result['status']), 'counts' => $result['counts']);
     }
     $event->setReport($report);
 }
Exemplo n.º 2
0
 /**
  * @inheritDoc
  */
 public function process(array $projects, $options = array())
 {
     if (empty($projects)) {
         return array();
     }
     $reports = array();
     $release_history = new ReleaseHistory();
     /** @var Project $project */
     foreach ($projects as $project) {
         $release_history->prepare($project);
         $event = new CerbereDoActionEvent($this, $project);
         $this->getDispatcher()->dispatch(CerbereEvents::CERBERE_DO_ACTION, $event);
         if ($filename = $project->getFilename()) {
             $current_dir = getcwd();
             // Change current directory to the module directory.
             chdir($project->getWorkingDirectory());
             $hacked = new HackedProject($project);
             $result = $hacked->computeReport();
             $report = array('project' => $project->getProject(), 'type' => $project->getProjectType(), 'version' => $project->getVersion(), 'version_date' => $project->getDatestamp(), 'status' => $result['status'], 'status_label' => HackedProject::getStatusLabel($result['status']), 'modified' => $result['counts']['different'], 'deleted' => $result['counts']['missing']);
             $event = new CerbereReportActionEvent($this, $project, $report);
             $this->getDispatcher()->dispatch(CerbereEvents::CERBERE_REPORT_ACTION, $event);
             $report = $event->getReport();
             $reports[] = $report;
             // Restore current directory.
             chdir($current_dir);
         }
         $event = new CerbereDoneActionEvent($this, $project);
         $this->getDispatcher()->dispatch(CerbereEvents::CERBERE_DONE_ACTION, $event);
     }
     return $reports;
 }