/**
  * Gets the last build for a project.
  * 
  * Loads it from its serialized form
  *
  * @param Xinc_Project $project
  * @throws Xinc_Build_Exception_Unserialization
  * @throws Xinc_Build_Exception_NotFound
  * @return Xinc_Build_Interface
  */
 public static function getLastBuild(Xinc_Project $project)
 {
     $lastBuildTime = Xinc_Build_History::getLastBuildTime($project);
     //$lastBuildTime = $buildHistoryArr[count($buildHistoryArr) - 1];
     return self::getBuild($project, $lastBuildTime);
 }
Exemple #2
0
 public function getGraphs()
 {
     $project = new Xinc_Project();
     $project->setName($this->projectName);
     $contents = array();
     $lastBuildTime = Xinc_Build_History::getLastBuildTime($project);
     $cacheFile = $this->tmpDir . DIRECTORY_SEPARATOR . 'xinc_statistics_' . $this->projectName;
     if (file_exists($cacheFile) && filemtime($cacheFile) == $lastBuildTime) {
         // we have a cached version
         header('Xinc-Cache: ' . $lastBuildTime);
         return readfile($cacheFile);
     } else {
         try {
             $baseBuildData = array();
             if (file_exists($cacheFile)) {
                 $cachedLastBuildTime = filemtime($cacheFile);
                 $historyBuilds = $this->getHistoryBuildsByTimestamp($project, $cachedLastBuildTime + 1);
             } else {
                 $historyBuilds = $this->getHistoryBuilds($project, 0);
             }
         } catch (Exception $e1) {
             $historyBuilds = array();
         }
         if (isset($this->extensions['STATISTIC_GRAPH'])) {
             $i = 0;
             foreach ($this->extensions['STATISTIC_GRAPH'] as $extension) {
                 if ($extension instanceof Xinc_Plugin_Repos_Gui_Statistics_Graph) {
                     $baseBuildData = $this->loadGraphData($project, $extension->getId());
                     if (!is_array($baseBuildData)) {
                         $baseBuildData = array();
                     }
                     $data = $extension->buildDataSet($project, $historyBuilds, $baseBuildData);
                     $this->storeGraphData($project, $extension->getId(), $data);
                     $contents[] = $extension->generate($data, array('#1c4a7e', '#bb5b3d'));
                     $i++;
                     if ($i % 2 == 0) {
                         $contents[] = '<br/>';
                     }
                 }
             }
         }
         $contents = implode("\n", $contents);
         file_put_contents($cacheFile, $contents);
         touch($cacheFile, $lastBuildTime);
     }
     return $contents;
 }
Exemple #3
0
 public function handleEvent($eventId)
 {
     $this->projectName = $_GET['project'];
     if (isset($_GET['timestamp'])) {
         $this->buildTimeStamp = $_GET['timestamp'];
     }
     $this->project = new Xinc_Project();
     $this->project->setName($this->projectName);
     switch ($eventId) {
         case Xinc_Gui_Event::PAGE_LOAD:
             $handler = Xinc_Gui_Handler::getInstance();
             $statusDir = $handler->getStatusDir();
             if ($this->buildTimeStamp != null) {
                 $fullStatusDir = Xinc_Build_History::getBuildDir($this->project, $this->buildTimeStamp);
             } else {
                 $fullStatusDir = Xinc_Build_History::getLastBuildDir($this->project);
                 $this->buildTimeStamp = Xinc_Build_History::getLastBuildTime($this->project);
             }
             //$statusFile = $fullStatusDir . DIRECTORY_SEPARATOR . 'build.ser';
             $this->build = Xinc_Build::unserialize($this->project, $this->buildTimeStamp, Xinc_Gui_Handler::getInstance()->getStatusDir());
             $timezone = $this->build->getConfigDirective('timezone');
             if ($timezone !== null) {
                 Xinc_Timezone::set($timezone);
             }
             $detailDir = $fullStatusDir;
             /**
              * get History Builds
              */
             //$this->historyBuilds = $this->getHistoryBuilds($statusDir);
             /**
              * Generate the build selector on the right
              */
             $this->_generateBuildsView();
             /**
              * Overview info tab
              */
             $this->_generateSummaryView();
             /**
              * Generate the tab for the log messages
              */
             $this->_generateLogView();
             /**
              * Generate the external tabs that were registered through a hook
              */
             $this->_generateExternalExtensions();
             include Xinc_Data_Repository::getInstance()->getWeb('templates' . DIRECTORY_SEPARATOR . 'dashboard' . DIRECTORY_SEPARATOR . 'detail' . DIRECTORY_SEPARATOR . 'projectDetail.phtml');
             break;
         default:
             break;
     }
     /**
      * restore to system timezone
      */
     $xincTimezone = Xinc_Gui_Handler::getInstance()->getConfigDirective('timezone');
     if ($xincTimezone !== null) {
         Xinc_Timezone::set($xincTimezone);
     } else {
         Xinc_Timezone::reset();
     }
 }