/** * @return void */ public function indexAction() { $out = []; $fullRequest = ['query' => ['bool' => ['must_not' => [['terms' => ['status.name' => ['Closed', 'Rejected', 'Resolved']]], ['terms' => ['project.id' => ['78']]]]]], 'size' => 0, 'filter' => $this->queryFilters(), 'aggregations' => ['year' => ['date_histogram' => ['field' => 'updated_on', 'interval' => 'year'], 'aggregations' => ['month' => ['date_histogram' => ['field' => 'updated_on', 'interval' => 'month'], 'aggregations' => ['status' => ['terms' => ['field' => 'status.name']]]]]]]]; $search = $this->connection->getIndex()->createSearch($fullRequest); $search->addType('issue'); $resultSet = $search->search(); foreach ($resultSet->getAggregations() as $aggregation) { foreach ($aggregation['buckets'] as $bucket) { $dateParts = explode('/', $bucket['key_as_string']); $yearName = $dateParts[0]; // prefill array with 12 index, for 12 month $months = array_fill(0, 12, array()); foreach ($bucket['month']['buckets'] as $month) { $dateParts = explode('/', $month['key_as_string']); $monthName = $dateParts[1]; $stati = []; foreach ($month['status']['buckets'] as $status) { $stati[] = ['name' => $status['key'], 'total' => $status['doc_count']]; } $monthIndex = (int) $monthName - 1; $months[$monthIndex] = ['month' => $monthName, 'total' => $month['doc_count'], 'stati' => $stati]; } $out[] = ['year' => $yearName, 'total' => $bucket['doc_count'], 'months' => $months]; } } $this->view->assignMultiple(['aggs' => $out, 'context' => $this->context]); }
/** * Initializes all client connections to forge and to Elasticsearch * * @param string $mode * @throws \TYPO3\Flow\Exception */ protected function startUp($mode = '') { if ($mode === 'elevated') { $this->redmineClient = new Redmine\Client($this->settings['Redmine']['url'], $this->settings['Redmine']['apiKeyElevated']); } else { $this->redmineClient = new Redmine\Client($this->settings['Redmine']['url'], $this->settings['Redmine']['apiKey']); } $this->connection = new ElasticSearchConnection(); $this->connection->init(); $this->elasticIndex = $this->connection->getIndex(); $this->lockFile = FLOW_PATH_DATA . 'Persistent/WMDB.Forger.lock'; }
/** * @param array $fullRequest */ protected function search(array $fullRequest) { $query = new El\Query($fullRequest); $usedFilters = $this->addFilters(); if ($usedFilters !== false) { $query->setPostFilter($usedFilters); } $resultSet = $this->connection->getIndex()->search($query); $this->totalHits = $resultSet->getTotalHits(); if (intval($this->totalHits) <= intval($this->currentPage * $this->perPage)) { $this->view->assign('endingAtItem', intval($this->totalHits)); } else { $this->view->assign('endingAtItem', $this->currentPage * $this->perPage); } $this->view->assignMultiple(['results' => $resultSet->getResults(), 'pagesToLinkTo' => $this->getPages(), 'currentPage' => $this->currentPage, 'prev' => $this->currentPage - 1, 'next' => $this->currentPage < ceil($this->totalHits / $this->perPage) ? $this->currentPage + 1 : 0, 'totalResults' => $this->totalHits, 'startingAtItem' => $this->currentPage * $this->perPage - ($this->perPage - 1), 'aggregations' => $resultSet->getAggregations(), 'context' => $this->context]); }
/** * */ protected function getAllUsers() { $res = $this->connection->getIndex()->getType('user')->search('', array('size' => 100)); $results = $res->getResults(); foreach ($results as $hit) { $user = $hit->getSource(); $this->users[$user['id']] = $user; } }
/** * @param $searchClosed * @return \Elastica\ResultSet * @throws Exception */ public function doSearch($searchClosed) { $this->connection = new ElasticSearchConnection(); $this->connection->init(); $this->whereClause = new Query\QueryString(); $this->whereClause->setQuery($this->searchTerms); $this->utility = new Util(); if (isset($_GET['page'])) { $this->currentPage = intval($_GET['page']); } $this->fieldMapping = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'WMDB.Forger.SearchTermMapping'); $elasticaQuery = new Query(); if ($searchClosed === 'true') { $elasticaQuery->setQuery($this->whereClause); } else { $boolSearch = new Query\Bool(); $boolSearch->addMust($this->whereClause); $boolSearch->addMustNot(['term' => ['status.name' => 'Closed']]); $boolSearch->addMustNot(['term' => ['status.name' => 'Rejected']]); $boolSearch->addMustNot(['term' => ['status.name' => 'Resolved']]); $elasticaQuery->setQuery($boolSearch); } $elasticaQuery->setSize($this->perPage); $elasticaQuery->setFrom($this->currentPage * $this->perPage - $this->perPage); $usedFilters = $this->addFilters(); if ($usedFilters !== false) { $elasticaQuery->setPostFilter($usedFilters); } $this->addAggregations($elasticaQuery); $elasticaResultSet = $this->connection->getIndex()->search($elasticaQuery); $results = $elasticaResultSet->getResults(); $maxScore = $elasticaResultSet->getMaxScore(); $aggs = $elasticaResultSet->getAggregations(); $this->totalHits = $elasticaResultSet->getTotalHits(); $out = array('pagesToLinkTo' => $this->getPages(), 'currentPage' => $this->currentPage, 'prev' => $this->currentPage - 1, 'next' => $this->currentPage < ceil($this->totalHits / $this->perPage) ? $this->currentPage + 1 : 0, 'totalResults' => $this->totalHits, 'startingAtItem' => $this->currentPage * $this->perPage - ($this->perPage - 1), 'endingAtItem' => $this->currentPage * $this->perPage, 'results' => $results, 'maxScore' => $maxScore, 'aggs' => $aggs); if (intval($this->totalHits) <= intval($out['endingAtItem'])) { $out['endingAtItem'] = intval($this->totalHits); } return $out; }
/** * @param int $issueId * @param $gerritNumber * @param array $expectedStatus */ protected function getTicketStatus($issueId, $gerritNumber, $expectedStatus = array()) { // $this->redmineClient = new Redmine\Client( // $this->settings['Redmine']['url'], // $this->settings['Redmine']['apiKey'] // ); // $res = $this->redmineClient->api('issue')->show($issueId); // if (is_array($res)) { // if(in_array($res['issue']['status']['name'], $unexpectedStatus)) { // GeneralUtility::writeLine('|Issue #'.$issueId.'|'.$res['issue']['subject'].'|https://review.typo3.org/#/c/'.$gerritNumber.'/|', 'yellow'); // } // } else { // $this->counter['noArray']++; // } try { $search = $this->connection->getIndex()->getType('issue'); $doc = $search->getDocument($issueId)->getData(); // \TYPO3\Flow\var_dump($doc); if (!in_array($doc['status']['name'], $expectedStatus)) { /** * Check if another patchset exists */ $hasPatchset = false; $numberOfPatchsets = 0; foreach ($doc['journals'] as $journalEntry) { if (isset($journalEntry['notes']) && strstr($journalEntry['notes'], 'It is available at http://review.typo3.org/') && !strstr($journalEntry['notes'], 'It is available at http://review.typo3.org/' . $gerritNumber)) { $hasPatchset = true; // GeneralUtility::writeLine($journalEntry['notes'], 'green'); } if (isset($journalEntry['notes']) && !strstr($journalEntry['notes'], 'It is available at http://review.typo3.org/' . $gerritNumber)) { $numberOfPatchsets++; } } if (!$hasPatchset && $numberOfPatchsets > 1) { GeneralUtility::writeLine('|Issue #' . $issueId . '|' . $doc['subject'] . '|https://review.typo3.org/#/c/' . $gerritNumber . '/|', 'yellow'); } } else { // GeneralUtility::writeLine($issueId . ' has correct status ', 'green', false); // GeneralUtility::writeLine($doc['status']['name'], 'yellow'); } } catch (El\Exception\NotFoundException $e) { #GeneralUtility::writeLine($e->getMessage(), 'inverseRed'); } }
/** * @param int $issueId * @param $gerritNumber * @param array $expectedStatus */ protected function getTicketStatus($issueId, $gerritNumber, $expectedStatus = array()) { // $this->redmineClient = new Redmine\Client( // $this->settings['Redmine']['url'], // $this->settings['Redmine']['apiKey'] // ); // $res = $this->redmineClient->api('issue')->show($issueId); // if (is_array($res)) { // if(in_array($res['issue']['status']['name'], $unexpectedStatus)) { // } // } else { // $this->counter['noArray']++; // } try { $search = $this->connection->getIndex()->getType('issue'); $doc = $search->getDocument($issueId)->getData(); // \TYPO3\Flow\var_dump($doc); if (!in_array($doc['status']['name'], $expectedStatus)) { /** * Check if another patchset exists */ $hasPatchset = false; $numberOfPatchsets = 0; foreach ($doc['journals'] as $journalEntry) { if (isset($journalEntry['notes']) && strstr($journalEntry['notes'], 'It is available at http://review.typo3.org/') && !strstr($journalEntry['notes'], 'It is available at http://review.typo3.org/' . $gerritNumber)) { $hasPatchset = true; } if (isset($journalEntry['notes']) && !strstr($journalEntry['notes'], 'It is available at http://review.typo3.org/' . $gerritNumber)) { $numberOfPatchsets++; } } if (!$hasPatchset && $numberOfPatchsets > 1) { } } } catch (El\Exception\NotFoundException $e) { } }
/** * @throws \TYPO3\Flow\Exception */ public function __construct() { $this->connection = new Es\ElasticSearchConnection(); $this->connection->init(); }
/** * @return \Elastica\Index * @throws \TYPO3\Flow\Exception */ protected function connectToElastic() { $connection = new ElasticSearch\ElasticSearchConnection(); $connection->init(); return $connection->getIndex(); }
/** * @param int $issueId * @return array|string */ private function findIssue($issueId) { $con = new ElasticSearchConnection(); $con->init(); $index = $con->getIndex(); $forger = $index->getType('issue'); try { $res = $forger->getDocument($issueId); // Need to use an ugly hack // funny noone found that one earlier // \TYPO3\Flow\var_dump($res); $data = $res->getData(); $this->view->assign('issue', ['hit' => ['_source' => $data]]); } catch (\Exception $e) { $data = array('error' => 'Issue #' . $issueId . ' was not found.'); } return $data; }