Пример #1
0
    /**
     * Iterate over all run rows and aggregate the runs and user agents.
     * @return Array List of runs and userAgents.
     */
    public static function getDataFromRunRows(TestSwarmContext $context, $runRows)
    {
        $db = $context->getDB();
        $userAgentIDs = array();
        $runs = array();
        foreach ($runRows as $runRow) {
            $runInfo = array('id' => $runRow->id, 'name' => $runRow->name, 'url' => $runRow->url);
            $runUaRuns = array();
            // Get list of useragents that this run is scheduled for
            $runUaRows = $db->getRows(str_queryf('SELECT
					status,
					useragent_id,
					results_id
				FROM
					run_useragent
				WHERE run_useragent.run_id = %u;', $runRow->id));
            if ($runUaRows) {
                foreach ($runUaRows as $runUaRow) {
                    // Add UA ID to the list. After we've collected
                    // all the UA IDs we'll perform one query for all of them
                    // to gather the info from the useragents table
                    $userAgentIDs[] = $runUaRow->useragent_id;
                    if (!$runUaRow->results_id) {
                        $runUaRuns[$runUaRow->useragent_id] = array('runStatus' => 'new');
                    } else {
                        $runresultsRow = $db->getRow(str_queryf('SELECT
								id,
								client_id,
								status,
								total,
								fail,
								error
							FROM runresults
							WHERE id = %u;', $runUaRow->results_id));
                        if (!$runresultsRow) {
                            $this->setError('data-corrupt');
                            return;
                        }
                        $runUaRuns[$runUaRow->useragent_id] = array('useragentID' => $runUaRow->useragent_id, 'clientID' => $runresultsRow->client_id, 'failedTests' => $runresultsRow->fail, 'totalTests' => $runresultsRow->total, 'errors' => $runresultsRow->error, 'runStatus' => self::getRunresultsStatus($runresultsRow), 'runResultsUrl' => swarmpath('result/' . $runUaRow->results_id), 'runResultsLabel' => $runresultsRow->status != ResultAction::$STATE_FINISHED ? '' : ($runresultsRow->error > 0 ? $runresultsRow->error : ($runresultsRow->fail > 0 ? $runresultsRow->fail : $runresultsRow->total)));
                    }
                }
                uksort($runUaRuns, array($context->getBrowserInfo(), 'sortUaId'));
                $runs[] = array('info' => $runInfo, 'uaRuns' => $runUaRuns);
            }
        }
        // Get information for all encounted useragents
        $browserIndex = BrowserInfo::getBrowserIndex();
        $userAgents = array();
        foreach ($userAgentIDs as $uaID) {
            if (!isset($browserIndex->{$uaID})) {
                // If it isn't in the index anymore, it means it has been removed from the browserSets
                // configuration. Use a generic fallback object;
                $userAgents[$uaID] = BrowserInfo::makeGenericUaData($uaID);
            } else {
                $userAgents[$uaID] = (array) $browserIndex->{$uaID};
            }
        }
        uasort($userAgents, 'BrowserInfo::sortUaData');
        return array('runs' => $runs, 'userAgents' => $userAgents);
    }