/** * @actionNote This action takes no parameters. */ public function doAction() { $context = $this->getContext(); $browserInfo = $context->getBrowserInfo(); $db = $context->getDB(); $conf = $context->getConf(); $request = $context->getRequest(); $resetTimedoutRuns = 0; // Get clients that are considered disconnected (not responding to the latest pings). // Then mark the runresults of its active runs as timed-out, and reset those runs so // they become available again for different clients in GetrunAction. $rows = $db->getRows(str_queryf("SELECT\n\t\t\t\trunresults.id as id\n\t\t\tFROM\n\t\t\t\trunresults\n\t\t\tINNER JOIN clients ON runresults.client_id = clients.id\n\t\t\tWHERE runresults.status = 1\n\t\t\tAND clients.updated < %s;", swarmdb_dateformat(Client::getMaxAge($context)))); if ($rows) { foreach ($rows as $row) { // Reset the run $ret = $db->query(str_queryf("UPDATE run_useragent\n\t\t\t\t\tSET\n\t\t\t\t\t\tstatus = 0,\n\t\t\t\t\t\tresults_id = NULL\n\t\t\t\t\tWHERE results_id = %u;", $row->id)); // If the previous UPDATE query failed for whatever // reason, don't do the below query as that will lead // to data corruption (results with state LOST must never // be referenced from run_useragent.results_id). if ($ret) { // Update status of the result $ret = $db->query(str_queryf("UPDATE runresults\n\t\t\t\t\t\tSET status = %s\n\t\t\t\t\t\tWHERE id = %u;", ResultAction::$STATE_LOST, $row->id)); } if ($ret) { $resetTimedoutRuns++; } } } $this->setData(array("resetTimedoutRuns" => $resetTimedoutRuns)); }
/** * @param string $sortField * @param string $sortDir * @param string $include * @param string|bool $name */ protected function getOverview($sortField, $sortDir, $include, $name) { $context = $this->getContext(); $db = $context->getDB(); $sortDirQuery = strtoupper($sortDir); $sortFieldQuery = "ORDER BY {$sortField} {$sortDirQuery}"; $whereClause = array(); if ($include === 'active') { $whereClause[] = 'updated >= ' . swarmdb_dateformat(Client::getMaxAge($context)); } if ($name) { $whereClause[] = 'name = \'' . $db->strEncode($name) . '\''; } if (count($whereClause)) { $whereClause = 'WHERE ' . implode(' AND ', $whereClause); } else { $whereClause = ''; } $rows = $db->getRows("SELECT\n\t\t\t\tname,\n\t\t\t\tMAX(updated) as updated\n\t\t\tFROM\n\t\t\t\tclients\n\t\t\t{$whereClause}\n\t\t\tGROUP BY name\n\t\t\t{$sortFieldQuery};"); $results = array(); if ($rows) { foreach ($rows as $row) { $result = array('name' => $row->name, 'viewUrl' => swarmpath("clients/{$row->name}"), 'clientIDs' => array()); $this->addTimestampsTo($result, $row->updated, 'updated'); $results[$row->name] = $result; } } return $results; }
/** * @actionParam string browserSet: Show useragents from a specific * browserset only. * @actionParam bool onlyactive: If true, only user agents that * have online clients and/or pending runs are included. * If both "browserSet" and "onlyactive" are used, the overlaping * subset will be output. */ public function doAction() { $context = $this->getContext(); $conf = $context->getConf(); $db = $context->getDB(); $request = $context->getRequest(); $showOnlyactive = $request->getBool('onlyactive'); $filterBrowserSet = $request->getVal('browserSet', false); $data = array('userAgents' => array()); $browserIndex = BrowserInfo::getBrowserIndex(); $browserSetByUaId = array(); foreach ($conf->browserSets as $browserSet => $browsers) { foreach ($browsers as $browser) { $browserSetByUaId[$browser] = $browserSet; } } foreach ($browserIndex as $uaID => $uaData) { if ($filterBrowserSet && $browserSetByUaId[$uaID] !== $filterBrowserSet) { continue; } // Count online clients with this UA $clients = $db->getOne(str_queryf('SELECT COUNT(id) FROM clients WHERE useragent_id = %s AND updated >= %s', $uaID, swarmdb_dateformat(Client::getMaxAge($context)))); $clients = intval($clients); // Count active runs for this UA $activeRuns = $db->getOne(str_queryf('SELECT COUNT(*) FROM run_useragent WHERE useragent_id = %s AND status = 1;', $uaID)); $activeRuns = intval($activeRuns); // Count pending runs for this UA $pendingRuns = $db->getOne(str_queryf('SELECT COUNT(*) FROM run_useragent WHERE useragent_id = %s AND status = 0 AND completed = 0;', $uaID)); $pendingRuns = intval($pendingRuns); // Count past runs that can still be re-run to // possibly fix non-passing results $pendingReRuns = $db->getOne(str_queryf('SELECT COUNT(*) FROM run_useragent WHERE useragent_id = %s AND status = 0 AND completed > 0;', $uaID)); $pendingReRuns = intval($pendingReRuns); if (!$clients && !$activeRuns && !$pendingRuns && !$pendingReRuns) { if ($showOnlyactive || !isset($browserSetByUaId[$uaID])) { continue; } } $data['userAgents'][$uaID] = array('data' => $uaData, 'stats' => array('onlineClients' => $clients, 'activeRuns' => $activeRuns, 'pendingRuns' => $pendingRuns, 'pendingReRuns' => $pendingReRuns)); } // Make sure they are sorted nicely uasort($data['userAgents'], function ($a, $b) { return strnatcasecmp($a['data']->displayInfo['title'], $b['data']->displayInfo['title']); }); $this->setData($data); }