예제 #1
0
 public function handleEvent($eventId)
 {
     switch ($eventId) {
         case Xinc_Gui_Event::PAGE_LOAD:
             $query = urldecode($_SERVER['REQUEST_URI']);
             $this->features = $this->extensions['PROJECT_FEATURE'];
             $handler = Xinc_Gui_Handler::getInstance();
             $statusDir = $handler->getStatusDir();
             $dir = opendir($statusDir);
             while ($file = readdir($dir)) {
                 $project = array();
                 $fullfile = $statusDir . DIRECTORY_SEPARATOR . $file;
                 if (!in_array($file, array('.', '..')) && is_dir($fullfile)) {
                     $project['name'] = $file;
                     $statusfile = $fullfile . DIRECTORY_SEPARATOR . 'build.ser';
                     //$xincProject = $fullfile . DIRECTORY_SEPARATOR . '.xinc';
                     if (file_exists($statusfile)) {
                         //$ini = parse_ini_file($statusfile, true);
                         $project = new Xinc_Project();
                         $project->setName($file);
                         try {
                             $object = Xinc_Build_Repository::getLastBuild($project);
                             $this->builds->add($object);
                         } catch (Exception $e) {
                         }
                     } else {
                         if (file_exists($xincProject)) {
                             $project['build.status'] = -10;
                             $project['build.time'] = 0;
                             $project['build.label'] = '';
                             $this->projects[] = $project;
                         }
                     }
                     $this->menu = '';
                     if (isset($this->extensions['MAIN_MENU'])) {
                         if (is_array($this->extensions['MAIN_MENU'])) {
                             foreach ($this->extensions['MAIN_MENU'] as $extension) {
                                 $this->menu .= call_user_func_array($extension, array($this, 'Dashboard'));
                             }
                         }
                     }
                 }
             }
             if (preg_match('/\\/dashboard\\/projects.*/', $query)) {
                 include_once Xinc_Data_Repository::getInstance()->getWeb('templates' . DIRECTORY_SEPARATOR . 'dashboard' . DIRECTORY_SEPARATOR . 'projects.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();
     }
 }
예제 #2
0
 public function getItem(Xinc_Project $project)
 {
     //$this->_extensions = $this->_widget->getExtensions();
     $numberOfGraphs = 3;
     $graphHeight = 250;
     $statisticsMenu = new Xinc_Plugin_Repos_Gui_Menu_Extension_Item('statistics-' . $project->getName(), 'Statistics - ' . $project->getName(), './statistics/?project=' . $project->getName(), 'Statistics', '', true, false);
     return $statisticsMenu;
 }
예제 #3
0
 public function handleEvent($eventId)
 {
     $query = $_SERVER['REQUEST_URI'];
     $projectName = isset($_REQUEST['project']) ? $_REQUEST['project'] : null;
     $buildTime = isset($_REQUEST['buildtime']) ? $_REQUEST['buildtime'] : null;
     if (empty($projectName) || empty($buildTime)) {
         die('Could not find phpunit test results');
     }
     $project = new Xinc_Project();
     $project->setName($projectName);
     try {
         $build = Xinc_Build::unserialize($project, $buildTime, Xinc_Gui_Handler::getInstance()->getStatusDir());
         $buildLabel = $build->getLabel();
         $timezone = $build->getConfigDirective('timezone');
         if ($timezone !== null) {
             Xinc_Timezone::set($timezone);
         } else {
             $xincTimezone = Xinc_Gui_Handler::getInstance()->getConfigDirective('timezone');
             if ($xincTimezone !== null) {
                 Xinc_Timezone::set($xincTimezone);
             } else {
                 Xinc_Timezone::set(Xinc_Gui_Handler::getInstance()->getSystemTimezone());
             }
         }
         $sourceFile = $build->getInternalProperties()->get('phpunit.file');
         if ($sourceFile != null && file_exists($sourceFile) && class_exists('XSLTProcessor')) {
             $xslFile = Xinc_Data_Repository::getInstance()->getPlugins('resources' . DIRECTORY_SEPARATOR . 'phpunit' . DIRECTORY_SEPARATOR . 'details.xsl');
             try {
                 $outputFileName = Xinc_Ini::getInstance()->get('tmp_dir', 'xinc') . DIRECTORY_SEPARATOR . 'phpunit_details_' . $projectName . '_' . $buildTime;
             } catch (Exception $e) {
                 Xinc_Logger::getInstance()->error('Cannot get xinc.ini configuration');
                 $outputFileName = 'phpunit_details_' . $projectName . '_' . $buildTime;
             }
             if (file_exists($outputFileName)) {
                 $details = file_get_contents($outputFileName);
             } else {
                 $details = $this->_transformResults($sourceFile, $xslFile, $outputFileName);
             }
             //$click = 'openMenuTab(\'phpunit-'.$projectName.'-'.$buildTimestamp.'\',\'PHPUnit - '.$projectName.'\',\''.$url.'\',null,false,false,\'auto\');';
             $title = 'PHPUnit Test Results';
             $buildTimeString = date('Y-m-d H:i:s', $build->getBuildTime()) . '-' . Xinc_Timezone::get();
             $content = str_replace(array('{title}', '{details}', '{projectName}', '{buildLabel}', '{buildTime}'), array($title, $details, $projectName, $buildLabel, $buildTimeString), $details);
         } else {
             $content = false;
         }
         Xinc_Timezone::reset();
         echo $content;
     } catch (Exception $e) {
         echo "Could not find phpunit test results";
     }
 }
예제 #4
0
 public function testLogging()
 {
     $project = new Xinc_Project();
     $name = 'test ' . rand(21213, 123213);
     $project->setName($name);
     $message = 'info ' . rand(3123123, 123123213);
     $project->info($message);
     $this->assertTrue(strpos(Xinc_StreamLogger::getLastLogMessage(), $message) !== false, 'Last message should contain message');
     $message = 'debug ' . rand(3123123, 123123213);
     $project->debug($message);
     $this->assertTrue(strpos(Xinc_StreamLogger::getLastLogMessage(), $message) !== false, 'Last message should contain message');
     $message = 'warn ' . rand(3123123, 123123213);
     $project->warn($message);
     $this->assertTrue(strpos(Xinc_StreamLogger::getLastLogMessage(), $message) !== false, 'Last message should contain message');
     $message = 'error ' . rand(3123123, 123123213);
     $project->error($message);
     $this->assertTrue(strpos(Xinc_StreamLogger::getLastLogMessage(), $message) !== false, 'Last message should contain message');
     Xinc_Logger::getInstance()->setLogLevel(Xinc_Logger::LOG_LEVEL_VERBOSE);
     $message = 'verbose ' . rand(3123123, 123123213);
     ob_start();
     $project->verbose($message);
     $contents = ob_get_clean();
     $lastMsg = Xinc_StreamLogger::getLastLogMessage();
     Xinc_Logger::getInstance()->setLogLevel(Xinc_Logger::LOG_LEVEL_DEBUG);
     $this->assertTrue(strpos($lastMsg, $message) !== false, 'Last message should contain message');
     //$this->assertEquals($lastMsg, $contents,
     //                 'Last message should contain message');
 }
 public function setUp()
 {
     if (!defined('DS')) {
         define('DS', DIRECTORY_SEPARATOR);
     }
     $project = new Xinc_Project();
     $project->setName('SimpleProject');
     $plugin = new Xinc_Plugin_Repos_Documentation();
     $build = new Xinc_Build(new Xinc_Engine_Sunrise(), $project);
     $this->sharedFixture = array();
     $this->sharedFixture[0] = $build;
     $this->sharedFixture[1] = $plugin;
     $docDir = Xinc::getInstance()->getStatusDir() . DS . 'SimpleProject' . DS . 'docs';
     $this->sharedFixture[2] = $docDir;
     $docSubDir = $docDir . DS . 'sub';
     mkdir($docDir);
     mkdir($docSubDir);
     file_put_contents($docDir . DS . 'test.html', 'test');
     file_put_contents($docSubDir . DS . 'index.html', 'index');
 }
예제 #6
0
 protected function _generateChildren()
 {
     $builds = new Xinc_Build_Iterator();
     $handler = Xinc_Gui_Handler::getInstance();
     $statusDir = $handler->getStatusDir();
     $dir = opendir($statusDir);
     while ($file = readdir($dir)) {
         $fullfile = $statusDir . DIRECTORY_SEPARATOR . $file;
         if (!in_array($file, array('.', '..')) && is_dir($fullfile)) {
             $statusfile = $fullfile . DIRECTORY_SEPARATOR . 'build.ser';
             if (file_exists($statusfile)) {
                 $project = new Xinc_Project();
                 $project->setName($file);
                 try {
                     $object = Xinc_Build_Repository::getLastBuild($project);
                     $builds->add($object);
                 } catch (Exception $e) {
                 }
             }
         }
     }
     $projects = array();
     while ($builds->hasNext()) {
         $build = $builds->next();
         /**
          * Do we have children?
          */
         $children = array();
         foreach ($this->_subMenus as $subExtension) {
             $item = $subExtension->getItem($build->getProject());
             if (!$item instanceof Xinc_Plugin_Repos_Gui_Menu_Extension_Item) {
                 continue;
             }
             $children[] = $item->generate();
         }
         $item = new Xinc_Plugin_Repos_Gui_Menu_Extension_Item('project-' . $build->getProject()->getName() . '-' . $build->getBuildTime(), $build->getLabel() . ' - ' . $build->getProject()->getName(), './dashboard/detail?project=' . $build->getProject()->getName() . '&timestamp=' . $build->getBuildTime(), $build->getProject()->getName(), '', false, count($children) > 0 ? false : true, $children);
         $projects[] = $item->generate();
     }
     return implode(',', $projects);
 }
예제 #7
0
 public function handleEvent($eventId)
 {
     $query = urldecode($_SERVER['REQUEST_URI']);
     preg_match("/\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*)/", $query, $matches);
     if (count($matches) != 6) {
         echo "Could not find artifact";
         return;
     }
     $projectName = $matches[3];
     $buildTime = $matches[4];
     $file = $matches[5];
     $project = new Xinc_Project();
     $project->setName($projectName);
     try {
         $build = Xinc_Build::unserialize($project, $buildTime, Xinc_Gui_Handler::getInstance()->getStatusDir());
         $statusDir = Xinc_Build_History::getBuildDir($project, $buildTime);
         $statusDir .= DIRECTORY_SEPARATOR . Xinc_Plugin_Repos_Artifacts::ARTIFACTS_DIR . DIRECTORY_SEPARATOR;
         /**
          * Replace multiple / slashes with just one
          */
         $fileName = $statusDir . $file;
         $fileName = preg_replace('/\\' . DIRECTORY_SEPARATOR . '+/', DIRECTORY_SEPARATOR, $fileName);
         $realfile = realpath($fileName);
         if ($realfile != $fileName) {
             echo "Could not find artifact";
         } else {
             if (file_exists($fileName)) {
                 $contentType = $this->mime_content_type2($fileName);
                 if (!empty($contentType)) {
                     header("Content-Type: " . $contentType);
                 }
                 readfile($fileName);
             } else {
                 echo "Could not find artifact";
             }
         }
     } catch (Exception $e) {
         echo "Could not find any artifacts";
     }
 }
예제 #8
0
 public function email(Xinc_Project $project, $to, $subject, $message, $from = 'Xinc')
 {
     if (empty($from)) {
         $from = $this->_defaultFrom;
     }
     $project->info('Executing email publisher with content ' . "\nTo: " . $to . "\nSubject: " . $subject . "\nMessage: " . $message . "\nFrom: " . $from);
     /** send the email */
     @(include_once 'Mail.php');
     if (class_exists('Mail')) {
         return $this->_sendPearMail($from, $to, $subject, $message);
     } else {
         $res = mail($to, $subject, $message, "From: {$from}\r\n");
         if ($res) {
             $project->info('Email sent successfully');
             return true;
         } else {
             $project->error('Email could not be sent');
             return false;
             //$project->setStatus(Xinc_Build_Interface::FAILED);
         }
     }
 }
예제 #9
0
 /**
  * Constructor, generates an Exception Message
  *
  * @param Xinc_Project $project
  * @param integer      $buildTime
  */
 public function __construct(Xinc_Project $project, $buildTime)
 {
     parent::__construct('Build  "' . $project->getName() . '" ' . 'with timestamp ' . $buildTime . ' was not found.');
 }
예제 #10
0
 /**
  * Load the requested artifacts file and output it to the browser
  *
  * @param array $params
  */
 private function _getDeliverableFile($params)
 {
     /**$projectName = $params['p'];
        $buildTime = $params['buildtime'];
        $file = $params['file'];*/
     $query = urldecode($_SERVER['REQUEST_URI']);
     preg_match("/\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*)/", $query, $matches);
     if (count($matches) != 8) {
         echo "Could not find deliverable";
         die;
     }
     $projectName = $matches[5];
     $buildTime = $matches[6];
     // if buildtime==latest, get latest build
     // latest
     // Xinc_Build_History::get()
     $file = $matches[7];
     $file = str_replace('/', DIRECTORY_SEPARATOR, $file);
     $project = new Xinc_Project();
     $project->setName($projectName);
     try {
         /**$build = Xinc_Build::unserialize($project,
            $buildTime,
            Xinc_Gui_Handler::getInstance()->getStatusDir());*/
         if ($buildTime == 'latest-successful') {
             $build = Xinc_Build_Repository::getLastSuccessfulBuild($project);
             $statusDir = Xinc_Build_History::getLastSuccessfulBuildDir($project);
         } else {
             if ($buildTime == 'latest') {
                 $build = Xinc_Build_Repository::getLastBuild($project);
                 $statusDir = Xinc_Build_History::getLastBuildDir($project);
             } else {
                 $build = Xinc_Build_Repository::getBuild($project, $buildTime);
                 $statusDir = Xinc_Build_History::getBuildDir($project, $buildTime);
             }
         }
         $statusDir .= DIRECTORY_SEPARATOR . Xinc_Plugin_Repos_Deliverable::DELIVERABLE_DIR . DIRECTORY_SEPARATOR;
         /**
          * Replace multiple / slashes with just one
          */
         $fileName = $statusDir . $file;
         $fileName = preg_replace('/\\' . DIRECTORY_SEPARATOR . '+/', DIRECTORY_SEPARATOR, $fileName);
         $realfile = realpath($fileName);
         if ($realfile != $fileName) {
             // check if we have an alias name
             $deliverables = $build->getInternalProperties()->get('deliverables');
             if (is_array($deliverables)) {
                 $aliasTest = basename($file);
                 if (isset($deliverables['aliases']) && isset($deliverables['aliases'][$aliasTest])) {
                     $aliasFile = $deliverables['deliverables'][$deliverables['aliases'][$aliasTest]];
                     if (file_exists($aliasFile) && is_file($aliasFile)) {
                         return $this->_outputDeliverable($aliasFile);
                     }
                 }
             }
             echo "Could not find artifact";
             die;
         } else {
             if (file_exists($fileName) && is_file($realfile)) {
                 return $this->_outputDeliverable($fileName);
             } else {
                 echo "Could not find deliverable";
                 die;
             }
         }
     } catch (Exception $e) {
         echo "Could not find any deliverable";
         die;
     }
 }
예제 #11
0
 /**
  * Constructor, generates an Exception Message
  *
  * @param Xinc_Project $project
  * @param integer      $buildTime
  */
 public function __construct(Xinc_Project $project, $buildTime)
 {
     parent::__construct('Build of "' . $project->getName() . '" ' . ' with timestamp: ' . $buildTime . ' could not be serialized.');
 }
예제 #12
0
 public function testGet()
 {
     $projectName = md5(time());
     $notAProjectName = 'test';
     $project = new Xinc_Project();
     $project->setName($projectName);
     try {
         $this->sharedFixture->register($projectName, $project);
         $this->assertTrue(true, 'No exception thrown');
         $gotBackProject = $this->sharedFixture->get($projectName);
         $this->assertEquals($gotBackProject, $project, 'Projects should be equal');
     } catch (Xinc_Registry_Exception $re) {
         $this->assertFalse(true, 'Unexpected registry exception while ' . 'registering a Xinc_Project:' . $re->getMessage());
     } catch (Exception $e) {
         $this->assertFalse(true, 'Unexpected exception while ' . 'registering a Xinc_Project:' . $re->getMessage());
     }
     try {
         $this->sharedFixture->register($projectName, $project);
         $this->assertTrue(true, 'No exception thrown');
         $gotBackProject = $this->sharedFixture->get($notAProjectName);
         $this->assertFalse(true, 'No exception thrown');
     } catch (Xinc_Registry_Exception $re) {
         $this->assertTrue(true, 'Expected registry exception while ' . 'registering a Xinc_Project:' . $re->getMessage());
     } catch (Exception $e) {
         $this->assertFalse(true, 'Unexpected exception while ' . 'registering a Xinc_Project:' . $e->getMessage());
     }
 }
예제 #13
0
 public function generateStatisticsMenu(Xinc_Project $project)
 {
     $numberOfGraphs = count($this->extensions['STATISTIC_GRAPH']);
     $graphHeight = 350;
     $statisticsMenu = new Xinc_Plugin_Repos_Gui_Menu_Extension_Item('statistics-' . $project->getName(), 'Statistics', './statistics/?project=' . $project->getName(), 'Statistics - ' . $project->getName(), '', true, false);
     return $statisticsMenu;
 }
예제 #14
0
 /**
  * Load the requested artifacts file and output it to the browser
  *
  * @param array $params
  */
 private function _getDocumentationFile($params)
 {
     /**$projectName = $params['p'];
        $buildTime = $params['buildtime'];
        $file = $params['file'];*/
     $query = urldecode($_SERVER['REQUEST_URI']);
     preg_match("/\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*)/", $query, $matches);
     if (count($matches) != 8) {
         echo "Could not find documentation 1";
         die;
     }
     $projectName = $matches[5];
     $buildTime = $matches[6];
     // if buildtime==latest, get latest build
     // latest
     // Xinc_Build_History::get()
     $file = $matches[7];
     //$file = urldecode($file);
     $file = str_replace('/', DIRECTORY_SEPARATOR, $file);
     $project = new Xinc_Project();
     $project->setName($projectName);
     try {
         /**$build = Xinc_Build::unserialize($project,
            $buildTime,
            Xinc_Gui_Handler::getInstance()->getStatusDir());*/
         if ($buildTime == 'latest-successful') {
             $build = Xinc_Build_Repository::getLastSuccessfulBuild($project);
             $statusDir = Xinc_Build_History::getLastSuccessfulBuildDir($project);
         } else {
             if ($buildTime == 'latest') {
                 $build = Xinc_Build_Repository::getLastBuild($project);
                 $statusDir = Xinc_Build_History::getLastBuildDir($project);
             } else {
                 $build = Xinc_Build_Repository::getBuild($project, $buildTime);
                 $statusDir = Xinc_Build_History::getBuildDir($project, $buildTime);
             }
         }
         $statusDir .= DIRECTORY_SEPARATOR . Xinc_Plugin_Repos_Documentation::DOCUMENTATION_DIR . DIRECTORY_SEPARATOR;
         /**
          * Replace multiple / slashes with just one
          */
         $fileName = $statusDir . $file;
         $fileName = preg_replace('/\\' . DIRECTORY_SEPARATOR . '+/', DIRECTORY_SEPARATOR, $fileName);
         $realfile = realpath($fileName);
         if ($realfile != $fileName) {
             echo "Could not find documentation 2";
             die;
         } else {
             if (file_exists($fileName) && is_file($realfile)) {
                 return $this->_outputDoc($fileName);
             } else {
                 echo "Could not find documentation 3";
                 die;
             }
         }
     } catch (Exception $e) {
         echo "Could not find any documentation";
         die;
     }
 }
예제 #15
0
 /**
  * Get history of all the builds for a project
  *
  * @param string $projectName
  * @param integer $start
  * @param integer $limit
  *
  * @return stdClass
  */
 private function _getHistoryBuilds($projectName, $start, $limit = null)
 {
     $statusDir = Xinc_Gui_Handler::getInstance()->getStatusDir();
     $historyFile = $statusDir . DIRECTORY_SEPARATOR . $projectName . '.history';
     $project = new Xinc_Project();
     $project->setName($projectName);
     $buildHistoryArr = unserialize(file_get_contents($historyFile));
     $totalCount = count($buildHistoryArr);
     if ($limit == null) {
         $limit = $totalCount;
     }
     $buildHistoryArr = array_slice($buildHistoryArr, $start, $limit, true);
     $builds = array();
     foreach ($buildHistoryArr as $buildTimestamp => $buildFileName) {
         try {
             $buildObject = Xinc_Build::unserialize($project, $buildTimestamp, Xinc_Gui_Handler::getInstance()->getStatusDir());
             $builds[] = array('buildtime' => $buildObject->getBuildTime(), 'label' => $buildObject->getLabel());
         } catch (Exception $e) {
             // TODO: Handle
         }
     }
     $builds = array_reverse($builds);
     $object = new stdClass();
     $object->totalcount = $totalCount;
     $object->builds = $builds;
     //return new Xinc_Build_Iterator($builds);
     return $object;
 }
예제 #16
0
 private function _getHistoryBuilds($projectName, $start, $limit = null)
 {
     $project = new Xinc_Project();
     $project->setName($projectName);
     try {
         $buildHistoryArr = Xinc_Build_History::getFromTo($project, $start, $limit);
         $totalCount = Xinc_Build_History::getCount($project);
         $builds = array();
         foreach ($buildHistoryArr as $buildTimestamp => $buildFileName) {
             try {
                 //echo $buildTimestamp . ' - '. $buildFileName . "<br>";
                 //Xinc_Build_Repository::getBuild($project, $buildTimestamp);
                 //$buildObject = Xinc_Build::unserialize($project,
                 //                                       $buildTimestamp,
                 //                                       Xinc_Gui_Handler::getInstance()->getStatusDir());
                 $buildObject = Xinc_Build_Repository::getBuild($project, $buildTimestamp);
                 $timezone = $buildObject->getConfigDirective('timezone');
                 if ($timezone !== null) {
                     Xinc_Timezone::set($timezone);
                 }
                 $builds[] = array('buildtime' => date('Y-m-d H:i:s', $buildObject->getBuildTime()), 'timezone' => Xinc_Timezone::get(), 'buildtimeRaw' => $buildObject->getBuildTime(), 'label' => $buildObject->getLabel(), 'status' => $buildObject->getStatus());
                 /**
                  * restore to system timezone
                  */
                 $xincTimezone = Xinc_Gui_Handler::getInstance()->getConfigDirective('timezone');
                 if ($xincTimezone !== null) {
                     Xinc_Timezone::set($xincTimezone);
                 } else {
                     Xinc_Timezone::reset();
                 }
             } catch (Exception $e) {
                 // TODO: Handle
             }
         }
         //$builds = array_reverse($builds);
     } catch (Exception $e) {
         $builds = array();
         $totalCount = 0;
     }
     $object = new stdClass();
     $object->totalcount = $totalCount;
     $object->builds = $builds;
     //return new Xinc_Build_Iterator($builds);
     return $object;
 }
예제 #17
0
 /**
  * deletes a build from the history
  *
  * @param string $projectName
  * @param mixed $timestamp Either the integer unix timestamp 
  *             or timeformat: "YYYY-MM-DD HH:MI:SS-TZ"
  */
 public static function deleteBuild($projectName, $timestamp)
 {
     Xinc_Logger::getInstance()->setLogLevel(0);
     $project = new Xinc_Project();
     $project->setName($projectName);
     $metaFileArr = self::_loadMetaData($project->getName());
     $testTimestamp = (int) $timestamp;
     if ($testTimestamp . "" != $timestamp) {
         /**
          * try and see if we have a string
          * in format: YYYY-MM-DD HH:MI:SS-TIMEZONE
          */
         $timeParts = split('-', $timestamp);
         $timeYear = $timeParts[0];
         $timeMonth = $timeParts[1];
         list($timeDay, $timeTime) = split(' ', $timeParts[2]);
         $timeZone = $timeParts[3];
         $timestamp = strtotime("{$timeYear}-{$timeMonth}-{$timeDay} {$timeTime} {$timeZone}");
     }
     if (!isset($metaFileArr['meta'])) {
         self::_migrate($project->getName(), $metaFileArr);
         $metaFileArr = self::_loadMetaData($project->getName());
     }
     $writeMetaFile = false;
     foreach ($metaFileArr['parts'] as $idx => $part) {
         if ($part['from'] <= $timestamp && $part['to'] >= $timestamp) {
             /**
              * this is the meta file we need
              */
             $partNo = $part['no'];
             $partArr = self::_readPartFile($project->getName(), $partNo);
             $newArr = array();
             $found = false;
             $deleteDir = null;
             $beforeTimestamp = null;
             $afterTimestamp = null;
             $lastTimeStamp = null;
             foreach ($partArr as $compareTimestamp => $serialFileName) {
                 if ($compareTimestamp == $timestamp) {
                     /**
                      * we delete by not adding it again
                      */
                     $found = true;
                     $deleteDir = dirname($serialFileName);
                     $beforeTimestamp = $lastTimeStamp;
                     $metaFileArr['parts'][$idx]['count'] = $metaFileArr['parts'][$idx]['count'] - 1;
                     $writeMetaFile = true;
                 } else {
                     if ($found && $afterTimestamp == null) {
                         $afterTimestamp = $compareTimestamp;
                     }
                     $newArr[$compareTimestamp] = $serialFileName;
                 }
                 $lastTimeStamp = $compareTimestamp;
             }
             //var_dump($deleteDir);
             //die;
             if ($found) {
                 try {
                     /**
                      * if this is the only build, we need to delete the part from meta
                      */
                     if ($timestamp == $part['from'] && $timestamp == $part['to']) {
                         unset($metaFileArr['lastSuccessfulBuild']);
                         unset($metaFileArr['parts'][$idx]);
                         $writeMetaFile = true;
                     } else {
                         if ($timestamp == $part['from']) {
                             if (isset($afterTimestamp)) {
                                 $metaFileArr['parts'][$idx]['from'] = $afterTimestamp;
                                 $writeMetaFile = true;
                             }
                         } else {
                             if ($timestamp == $part['to']) {
                                 if (isset($beforeTimestamp)) {
                                     $metaFileArr['parts'][$idx]['to'] = $beforeTimestamp;
                                     $writeMetaFile = true;
                                 }
                             }
                         }
                     }
                     if ($timestamp == $metaFileArr['lastSuccessfulBuild']['buildtime']) {
                         /**
                          * we need to find the last successful build, before this build
                          */
                         $reverseMetaArr = array_reverse($metaFileArr['parts'], true);
                         foreach ($metaFileArr['parts'] as $idx => $part) {
                             if ($part['no'] == $partNo) {
                                 $testPartArr = $newArr;
                             } else {
                                 $testPartArr = self::_readPartFile($project->getName(), $partNo);
                             }
                             $testPartArr = array_reverse($testPartArr, true);
                             foreach ($testPartArr as $testCompareTimestamp => $testSerialFileName) {
                                 if (file_exists($testSerialFileName)) {
                                     try {
                                         $testPart = Xinc_Build::unserialize($project, $testCompareTimestamp, self::_getStatusDir());
                                     } catch (Exception $e) {
                                         //var_dump($e);
                                     }
                                     if ($testPart->getStatus() == Xinc_Build_Interface::PASSED) {
                                         $metaFileArr['lastSuccessfulBuild']['buildtime'] = $testCompareTimestamp;
                                         $metaFileArr['lastSuccessfulBuild']['filename'] = $testSerialFileName;
                                         $writeMetaFile = true;
                                         break;
                                     }
                                 }
                             }
                         }
                         //die;
                     }
                     self::_writePartFile($project->getName(), $partNo, $newArr);
                     Xinc_Logger::getInstance()->info('Successfully written modified metadata');
                     if ($writeMetaFile) {
                         self::_writeMetaData($projectName, $metaFileArr);
                         Xinc_Logger::getInstance()->info('Successfully written modified meta superdata');
                     }
                     $deleteDir = realpath($deleteDir);
                     $statusDir = self::_getStatusDir();
                     $statusDir = realpath($statusDir);
                     /**
                      * make sure we are only deleting inside the status dir
                      */
                     if (substr($deleteDir, 0, strlen($statusDir)) == $statusDir && strlen($deleteDir) > strlen($statusDir)) {
                         exec('rm -Rf ' . $deleteDir, $output, $res);
                     } else {
                         $res = -1;
                     }
                     //$res = 1;
                     if ($res != 0) {
                         Xinc_Logger::getInstance()->error('Could not delete build directory: ' . $deleteDir);
                         return false;
                     } else {
                         Xinc_Logger::getInstance()->info('Successfully deleted build directory: ' . $deleteDir);
                         return true;
                     }
                 } catch (Exception $e) {
                     Xinc_Logger::getInstance()->error('Could not write modified metadata');
                 }
                 break;
             }
             return false;
         }
     }
 }
예제 #18
0
 /**
  * Get a list of all builds of a project
  *
  * @param string $projectName
  * @param integer $start
  * @param integer $limit
  *
  * @return stdClass
  */
 private function _getLogMessagesArr($projectName, $buildTime, $start, $limit = null)
 {
     $statusDir = Xinc_Gui_Handler::getInstance()->getStatusDir();
     $historyFile = $statusDir . DIRECTORY_SEPARATOR . $projectName . '.history';
     $project = new Xinc_Project();
     $project->setName($projectName);
     $totalCount = 0;
     try {
         $build = Xinc_Build::unserialize($project, $buildTime, $statusDir);
         $timezone = $build->getConfigDirective('timezone');
         if ($timezone !== null) {
             Xinc_Timezone::set($timezone);
         }
         $detailDir = Xinc_Build_History::getBuildDir($project, $buildTime);
         $logXmlFile = $detailDir . DIRECTORY_SEPARATOR . 'buildlog.xml';
         if (file_exists($logXmlFile)) {
             /**
              * Add fopen() to the function to just get the loglines
              * that we need.
              * the bigger the logfiles get, the more this gets a
              * performance problem
              */
             $xmlStr = '';
             $pos = 0;
             $fh = fopen($logXmlFile, 'r');
             $xmlStr = fgets($fh);
             $xmlStr .= fgets($fh);
             $tagOpen = false;
             while ($pos < $start && ($message = $this->_getNextMessage($fh)) !== false) {
                 $pos++;
                 $totalCount++;
             }
             if ($limit != null) {
                 $addClosingTag = true;
                 while ($pos < $start + $limit && ($message = $this->_getNextMessage($fh)) !== false) {
                     $xmlStr .= $message;
                     $pos++;
                     $totalCount++;
                 }
                 $xmlStr .= '</build>';
             } else {
                 while (($message = $this->_getNextMessage($fh)) !== false) {
                     $xmlStr .= $message;
                     $totalCount++;
                     $pos++;
                 }
                 $xmlStr .= '</build>';
             }
             $tagOpen = false;
             $tagClosed = false;
             while (($message = $this->_getNextMessage($fh)) !== false) {
                 $totalCount++;
                 $pos++;
             }
             fclose($fh);
             $logXml = new SimpleXMLElement($xmlStr);
         } else {
             $logXml = new SimpleXmlElement('<log/>');
         }
         $totalCount = $pos;
         //count($logXml->children());
         $i = $pos;
         $logmessages = array();
         $id = $totalCount - $start;
         foreach ($logXml->children() as $logEntry) {
             $attributes = $logEntry->attributes();
             $logmessages[] = array('id' => $id--, 'date' => (string) $attributes->timestamp, 'stringdate' => date('Y-m-d H:i:s', (int) $attributes->timestamp), 'timezone' => Xinc_Timezone::get(), 'priority' => (string) $attributes->priority, 'message' => base64_decode($logEntry));
         }
         /**
          * restore to system timezone
          */
         $xincTimezone = Xinc_Gui_Handler::getInstance()->getConfigDirective('timezone');
         if ($xincTimezone !== null) {
             Xinc_Timezone::set($xincTimezone);
         } else {
             Xinc_Timezone::reset();
         }
         //$logmessages = array_slice($logmessages, $start, $limit, false);
     } catch (Exception $e1) {
         $totalCount = 0;
         $logmessages = array();
     }
     $object = new stdClass();
     $object->totalmessages = $totalCount;
     $object->logmessages = $logmessages;
     //return new Xinc_Build_Iterator($builds);
     return $object;
 }