• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP swarmdb_dateformat函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中swarmdb_dateformat函数的典型用法代码示例。如果您正苦于以下问题:PHP swarmdb_dateformat函数的具体用法?PHP swarmdb_dateformat怎么用?PHP swarmdb_dateformat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了swarmdb_dateformat函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: purgeData

    protected function purgeData($timestamp, $batchSize)
    {
        $date = swarmdb_dateformat($timestamp);
        // Based on ManageProjectScript::delete()
        $stats = array();
        $db = $this->getContext()->getDB();
        while (true) {
            $jobRows = $db->getRows(str_queryf('SELECT id
				FROM jobs
				WHERE created < %s
				LIMIT %u;', $date, $batchSize));
            if (!$jobRows) {
                // Done
                break;
            }
            $jobIDs = array_map(function ($row) {
                return $row->id;
            }, $jobRows);
            $this->out('...deleting ' . count($jobIDs) . ' jobs');
            $action = WipejobAction::newFromContext($this->getContext());
            $result = $action->doWipeJobs('delete', $jobIDs, $batchSize);
            $this->mergeStats($stats, $result);
        }
        // TODO: Purge rows from clients table for clients that are no
        // longer active and don't have 0 runresults after the purge.
        foreach ($stats as $key => $val) {
            $this->out("deleted {$key} rows: {$val}");
        }
        $this->out('');
        $this->out('Done!');
    }
开发者ID:jquery,项目名称:testswarm,代码行数:31,代码来源:purge.php


示例2: doAction

 /**
  * @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));
 }
开发者ID:TestArmada,项目名称:admiral,代码行数:34,代码来源:CleanupAction.php


示例3: doAction

 /**
  * @actionNote This action takes no parameters.
  */
 public function doAction()
 {
     $browserInfo = $this->getContext()->getBrowserInfo();
     $db = $this->getContext()->getDB();
     $conf = $this->getContext()->getConf();
     $request = $this->getContext()->getRequest();
     // Get runs that were given to a client (status=1),
     // but haven't pinged back when they should.
     $maxage = time() - $conf->client->runTimeout - $conf->client->saveRetryMax * ($conf->client->saveReqTimeout + $conf->client->saveRetrySleep);
     $rows = $db->getRows(str_queryf("SELECT\n\t\t\t\tid,\n\t\t\t\tresults_id\n\t\t\tFROM\n\t\t\t\trun_useragent\n\t\t\tWHERE status = 1\n\t\t\tAND   updated < %s;", swarmdb_dateformat($maxage)));
     $resetTimedoutRuns = 0;
     // For clients that have stopped pinging,
     // assume disconnection (browser crashed, network lost, closed browser, ..)
     // @todo: Incorrect, the above query finds runs that have timed out.
     // Not dead runs from no longer connected clients, both should be checked.
     // The latter involves 3 cross-checks. Get runresults entry. Get client_id.
     // Get clients entry. Check updated property against pingTime+pingTimeMargin (see UserAction/SwarmstateAction).
     // Make 2 arrays of runUaIds and runresultsIds and unique them before the if(). Change if to if-count()
     if ($rows) {
         $resetTimedoutRuns = count($rows);
         foreach ($rows as $row) {
             $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 id = %u;", $row->id));
             // Record runresults status as having timed-out (status=3)
             $db->query(str_queryf("UPDATE runresults\n\t\t\t\t\tSET status = %s\n\t\t\t\t\tWHERE id = %u;", ResultAction::$STATE_LOST, $row->results_id));
         }
     }
     $this->setData(array("resetTimedoutRuns" => $resetTimedoutRuns));
 }
开发者ID:rhodblinkbox,项目名称:testswarm,代码行数:31,代码来源:CleanupAction.php


示例4: doAction

 /**
  * @actionNote This action takes no parameters.
  */
 public function doAction()
 {
     $browserInfo = $this->getContext()->getBrowserInfo();
     $db = $this->getContext()->getDB();
     $request = $this->getContext()->getRequest();
     // Get runs that were given to a client (status=1),
     // but haven't responded with a save (status=2) within 5 minutes.
     $rows = $db->getRows(str_queryf("SELECT\n\t\t\t\trun_id,\n\t\t\t\tclient_id,\n\t\t\t\tuseragent_id\n\t\t\tFROM\n\t\t\t\trun_client, clients\n\t\t\tWHERE run_client.updated < %s\n\t\t\tAND   clients.id = run_client.client_id\n\t\t\tAND   run_client.status = 1;", swarmdb_dateformat(strtotime('5 minutes ago'))));
     $resetTimedoutRuns = 0;
     if ($rows) {
         $resetTimedoutRuns = count($rows);
         foreach ($rows as $row) {
             // Undo runcount and reset status
             $db->query(str_queryf("UPDATE\n\t\t\t\t\t\trun_useragent\n\t\t\t\t\tSET\n\t\t\t\t\t\truns = runs - 1,\n\t\t\t\t\t\tstatus = 0\n\t\t\t\t\tWHERE run_id = %u\n\t\t\t\t\tAND   useragent_id = %s;", $row->run_id, $row->useragent_id));
             // Remove run_client entry,
             // after 5 minutes we'll assume the client crashed, refreshed, closed the browser
             // or something else...
             $db->query(str_queryf("DELETE FROM\n\t\t\t\t\t\trun_client\n\t\t\t\t\tWHERE run_id = %u\n\t\t\t\t\tAND   client_id = %u;", $row->run_id, $row->client_id));
         }
     }
     // Reset runs that race-condition deleted themselves
     $db->query("UPDATE\n\t\t\t\trun_useragent\n\t\t\tSET\n\t\t\t\truns = 0,\n\t\t\t\tcompleted = 0,\n\t\t\t\tstatus = 0\n\t\t\tWHERE runs = max\n\t\t\tAND   NOT EXISTS (\n\t\t\t\tSELECT *\n\t\t\t\tFROM run_client, clients\n\t\t\t\tWHERE run_client.run_id = run_useragent.run_id\n\t\t\t\tAND   run_client.client_id = clients.id\n\t\t\t\tAND   clients.useragent_id = run_useragent.useragent_id\n\t\t\t);");
     $resetRaceConditionDeleted = $db->getAffectedRows();
     $this->setData(array("resetTimedoutRuns" => $resetTimedoutRuns, "resetRaceConditionDeleted" => $resetRaceConditionDeleted));
 }
开发者ID:appendto,项目名称:testswarm,代码行数:28,代码来源:CleanupAction.php


示例5: loadNew

    protected function loadNew()
    {
        $browserInfo = $this->context->getBrowserInfo();
        $db = $this->context->getDB();
        $request = $this->context->getRequest();
        // If the useragent isn't known, abort with an error message
        if (!$browserInfo->isInSwarmUaIndex()) {
            throw new SwarmException('Your browser is not needed by this swarm.');
        }
        $clientName = $request->getVal('item', 'anonymous');
        if (!$clientName) {
            // The UI javascript injects a default value and if the field is missing
            // the above WebRequest#getVal fallback catches it. But if the field
            // was submitted with an empty string, then just ignore it and go to anonymous as well.
            // We don't want to hold back potential swarm joiners.
            $clientName = 'anonymous';
        }
        if (!self::isValidName($clientName)) {
            throw new SwarmException('Invalid client name. Names should be no longer than 128 characters.');
        }
        // Insert in a new record for the client and get its ID
        $db->query(str_queryf('INSERT INTO clients (name, useragent_id, useragent, ip, updated, created)
			VALUES(%s, %s, %s, %s, %s, %s);', $clientName, $browserInfo->getSwarmUaID(), $browserInfo->getRawUA(), $request->getIP(), swarmdb_dateformat(SWARM_NOW), swarmdb_dateformat(SWARM_NOW)));
        $this->clientRow = $db->getRow(str_queryf('SELECT * FROM clients WHERE id = %u LIMIT 1;', $db->getInsertId()));
    }
开发者ID:TestArmada,项目名称:admiral,代码行数:25,代码来源:Client.php


示例6: doAction

    /**
     * @actionMethod POST: Required.
     * @actionParam int job_id
     * @actionParam string type: one of 'delete', 'reset'.
     * @actionAuth: Required.
     */
    public function doAction()
    {
        $db = $this->getContext()->getDB();
        $request = $this->getContext()->getRequest();
        $jobID = $request->getInt('job_id');
        $wipeType = $request->getVal('type');
        if (!$jobID || !$wipeType) {
            $this->setError('missing-parameters');
            return;
        }
        if (!in_array($wipeType, array('delete', 'reset'))) {
            $this->setError('invalid-input', 'Invalid wipeType');
            return;
        }
        $projectID = $db->getOne(str_queryf('SELECT
				project_id
			FROM jobs
			WHERE id = %u;', $jobID));
        if (!$projectID) {
            $this->setError('invalid-input', 'Job not found');
            return;
        }
        // Check authentication
        if (!$this->doRequireAuth($projectID)) {
            return;
        }
        $runRows = $db->getRows(str_queryf('SELECT id
			FROM runs
			WHERE job_id = %u;', $jobID));
        if ($runRows) {
            foreach ($runRows as $runRow) {
                if ($wipeType === 'delete') {
                    $db->query(str_queryf('DELETE
						FROM run_useragent
						WHERE run_id = %u;', $runRow->id));
                } elseif ($wipeType === 'reset') {
                    $db->query(str_queryf('UPDATE run_useragent
						SET
							status = 0,
							completed = 0,
							results_id = NULL,
							updated = %s
						WHERE run_id = %u;', swarmdb_dateformat(SWARM_NOW), $runRow->id));
                }
            }
        }
        // This should be outside the if for $runRows, because jobs
        // can sometimes be created without any runs (by accidently).
        // Those should be deletable as well, thus this has to be outside the loop.
        // Also, no need to do this in a loop, just delete them all in one query.
        if ($wipeType === 'delete') {
            $db->query(str_queryf('DELETE
				FROM runs
				WHERE job_id = %u;', $jobID));
            $db->query(str_queryf('DELETE
				FROM jobs
				WHERE id = %u;', $jobID));
        }
        $this->setData(array('jobID' => $jobID, 'type' => $wipeType, 'result' => 'ok'));
    }
开发者ID:TestArmada,项目名称:admiral,代码行数:66,代码来源:WipejobAction.php


示例7: loadNew

 protected function loadNew()
 {
     $browserInfo = $this->context->getBrowserInfo();
     $db = $this->context->getDB();
     $request = $this->context->getRequest();
     // If the useragent isn't known, abort with an error message
     if (!$browserInfo->isInSwarmUaIndex()) {
         throw new SwarmException("Your browser is not suported in this TestSwarm " . "(useragent string: {$browserInfo->getRawUA()}).");
     }
     // Running a client doesn't require being logged in
     $username = $request->getSessionData("username", $request->getVal("item"));
     if (!$username) {
         throw new SwarmException("Username required.");
     }
     // Figure out what the user's ID number is
     $userRow = $db->getRow(str_queryf("SELECT * FROM users WHERE name = %s LIMIT 1;", $username));
     // If the user doesn't have one, create a new user row for this name
     if (!$userRow || !$userRow->id) {
         $db->query(str_queryf("INSERT INTO users (name, updated, created) VALUES(%s, %s, %s);", $username, swarmdb_dateformat(SWARM_NOW), swarmdb_dateformat(SWARM_NOW)));
         $userRow = $db->getRow(str_queryf("SELECT * FROM users WHERE id = %u LIMIT 1;", $db->getInsertId()));
     }
     // Insert in a new record for the client and get its ID
     $db->query(str_queryf("INSERT INTO clients (user_id, useragent_id, useragent, ip, updated, created)\n\t\t\tVALUES(%u, %s, %s, %s, %s, %s);", $userRow->id, $browserInfo->getSwarmUaID(), $browserInfo->getRawUA(), $request->getIP(), swarmdb_dateformat(SWARM_NOW), swarmdb_dateformat(SWARM_NOW)));
     $this->clientRow = $db->getRow(str_queryf("SELECT * FROM clients WHERE id = %u LIMIT 1;", $db->getInsertId()));
     $this->userRow = $userRow;
 }
开发者ID:appendto,项目名称:testswarm,代码行数:26,代码来源:Client.php


示例8: doAction

 /**
  * @requestParam browserSet string: Show useragents from a specific
  * browserset only.
  * @requestParam onlyactive bool: 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()
 {
     $conf = $this->getContext()->getConf();
     $db = $this->getContext()->getDB();
     $request = $this->getContext()->getRequest();
     $showOnlyactive = $request->hasKey("onlyactive");
     $filterBrowserSet = $request->getVal("browserSet", false);
     $data = array("userAgents" => array());
     $uaIndex = BrowserInfo::getSwarmUAIndex();
     foreach ($uaIndex as $uaID => $uaData) {
         if ($filterBrowserSet && isset($conf->browserSets->{$filterBrowserSet}) && !in_array($uaID, $conf->browserSets->{$filterBrowserSet})) {
             continue;
         }
         // Count online clients with this UA
         $clients = $db->getOne(str_queryf("SELECT\n\t\t\t\t\tCOUNT(id)\n\t\t\t\tFROM clients\n\t\t\t\tWHERE useragent_id = %s\n\t\t\t\tAND   updated > %s", $uaID, swarmdb_dateformat(strtotime('1 minute ago'))));
         $clients = intval($clients);
         // Count pending runs for this UA
         $pendingRuns = $db->getOne(str_queryf("SELECT\n\t\t\t\t\tCOUNT(*)\n\t\t\t\tFROM run_useragent\n\t\t\t\tWHERE useragent_id = %s\n\t\t\t\tAND   status = 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\n\t\t\t\t\tCOUNT(*)\n\t\t\t\tFROM run_useragent\n\t\t\t\tWHERE useragent_id = %s\n\t\t\t\tAND   runs < max\n\t\t\t\tAND   completed > 0;", $uaID));
         $pendingReRuns = intval($pendingReRuns);
         if ($showOnlyactive && !$clients && !$pendingRuns && !$pendingReRuns) {
             continue;
         }
         $data["userAgents"][$uaID] = array("data" => $uaData, "stats" => array("onlineClients" => $clients, "pendingRuns" => $pendingRuns, "pendingReRuns" => $pendingReRuns));
     }
     $this->setData($data);
 }
开发者ID:appendto,项目名称:testswarm,代码行数:38,代码来源:SwarmstateAction.php


示例9: doAction

 /**
  * @actionMethod POST: Required.
  * @actionParam client_id int
  * @actionParam run_token string
  * @actionParam run_id int
  * @actionParam fail int
  * @actionParam error int
  * @actionParam total int
  * @actionParam results string: HTML snapshot of the test results page.
  */
 public function doAction()
 {
     $browserInfo = $this->getContext()->getBrowserInfo();
     $conf = $this->getContext()->getConf();
     $db = $this->getContext()->getDB();
     $request = $this->getContext()->getRequest();
     if (!$request->wasPosted()) {
         $this->setError("requires-post");
         return;
     }
     $runToken = $request->getVal("run_token");
     if ($conf->client->requireRunToken && !$runToken) {
         $this->setError("invalid-input", "This TestSwarm does not allow unauthorized clients to join the swarm.");
         return;
     }
     $clientID = $request->getInt("client_id");
     if (!$clientID) {
         $this->setError("invalid-input");
         return;
     }
     // Create a Client object that verifies client id, user agent and run token.
     // Also updates the client 'alive' timestamp.
     // Throws exception (caught higher up) if stuff is invalid.
     $client = Client::newFromContext($this->getContext(), $runToken, $clientID);
     $runID = $request->getInt("run_id");
     $fail = $request->getInt("fail");
     $error = $request->getInt("error");
     $total = $request->getInt("total");
     $results = gzencode($request->getVal("results", ""));
     $db->query(str_queryf("UPDATE\n\t\t\t\trun_client\n\t\t\tSET\n\t\t\t\tstatus = 2,\n\t\t\t\tfail = %u,\n\t\t\t\terror = %u,\n\t\t\t\ttotal = %u,\n\t\t\t\tresults = %s,\n\t\t\t\tupdated = %s\n\t\t\tWHERE client_id = %u\n\t\t\tAND   run_id = %u\n\t\t\tLIMIT 1;", $fail, $error, $total, $results, swarmdb_dateformat(SWARM_NOW), $clientID, $runID));
     if (mysql_affected_rows() > 0) {
         // If we're 100% passing we don't need any more runs
         // Clear out other entries from other browsers for the same run
         // that were bad, since we now have a good one.
         if ($total > 0 && $fail === 0 && $error === 0) {
             $rows = $db->getRows(str_queryf("SELECT client_id\n\t\t\t\t\tFROM\n\t\t\t\t\t\trun_client, clients\n\t\t\t\t\tWHERE run_id = %u\n\t\t\t\t\tAND   client_id != %u\n\t\t\t\t\tAND   (total <= 0 OR error > 0 OR fail > 0)\n\t\t\t\t\tAND   clients.id = client_id\n\t\t\t\t\tAND   clients.useragent_id = %s;", $runID, $clientID, $client->getClientRow()->useragent_id));
             if ($rows) {
                 foreach ($rows as $row) {
                     $db->query(str_queryf("DELETE\n\t\t\t\t\t\t\tFROM run_client\n\t\t\t\t\t\t\tWHERE run_id = %u\n\t\t\t\t\t\t\tAND   client_id = %u;", $runID, $row->client_id));
                 }
             }
             $db->query(str_queryf("UPDATE\n\t\t\t\t\t\trun_useragent\n\t\t\t\t\tSET\n\t\t\t\t\t\truns = max,\n\t\t\t\t\t\tcompleted = completed + 1,\n\t\t\t\t\t\tstatus = 2,\n\t\t\t\t\t\tupdated = %s\n\t\t\t\t\tWHERE useragent_id = %s\n\t\t\t\t\tAND   run_id = %u\n\t\t\t\t\tLIMIT 1;", swarmdb_dateformat(SWARM_NOW), $browserInfo->getSwarmUaID(), $runID));
         } else {
             // Clear out old runs that timed out.
             if ($total > 0) {
                 $rows = $db->getRows(str_queryf("SELECT\n\t\t\t\t\t\t\tclient_id\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\trun_client\n\t\t\t\t\t\tWHERE run_id = %u\n\t\t\t\t\t\tAND   client_id != %u\n\t\t\t\t\t\tAND   total <= 0;", $runID, $clientID));
                 if ($rows) {
                     foreach ($rows as $row) {
                         $db->query(str_queryf("DELETE\n\t\t\t\t\t\t\t\tFROM run_client\n\t\t\t\t\t\t\t\tWHERE run_id = %u\n\t\t\t\t\t\t\t\tAND   client_id = %u;", $runID, $row->client_id));
                     }
                 }
             }
             $db->query(str_queryf("UPDATE\n\t\t\t\t\t\trun_useragent\n\t\t\t\t\tSET\n\t\t\t\t\t\tcompleted = completed + 1,\n\t\t\t\t\t\tstatus = IF(completed + 1 < max, 1, 2),\n\t\t\t\t\t\tupdated = %s\n\t\t\t\t\tWHERE useragent_id = %s\n\t\t\t\t\tAND   run_id = %u\n\t\t\t\t\tLIMIT 1;", swarmdb_dateformat(SWARM_NOW), $browserInfo->getSwarmUaID(), $runID));
         }
     }
     $this->setData("ok");
 }
开发者ID:appendto,项目名称:testswarm,代码行数:67,代码来源:SaverunAction.php


示例10: doAction

    public function doAction()
    {
        $db = $this->getContext()->getDB();
        $request = $this->getContext()->getRequest();
        $runID = $request->getInt("run_id");
        $clientID = $request->getInt("client_id");
        $useragentID = $request->getVal("useragent_id");
        if (!$runID || !$clientID) {
            $this->setError("missing-parameters");
            return;
        }
        $jobID = (int) $db->getOne(str_queryf('SELECT job_id FROM runs WHERE id = %u;', $runID));
        if (!$jobID) {
            $this->setError("invalid-input", "Run {$runID} not found.");
            return;
        }
        $jobOwner = $db->getOne(str_queryf('SELECT
				users.name as user_name
			FROM jobs, users
			WHERE jobs.id = %u
			AND   users.id = jobs.user_id
			LIMIT 1;', $jobID));
        if (!$jobOwner) {
            $this->setError("invalid-input", "Job {$jobID} not found.");
            return;
        }
        // Check authentication
        $userId = $this->doRequireAuth($jobOwner);
        if (!$userId) {
            return;
        }
        $runJobID = (int) $db->getOne(str_queryf('SELECT job_id
			FROM runs
			WHERE id = %u;', $runID));
        if ($runJobID !== $jobID) {
            $this->setError("invalid-input", "Run {$runID} does not belong to job {$jobID}.");
            return;
        }
        $clientUseragentID = $db->getOne(str_queryf('SELECT useragent_id
			FROM clients
			WHERE id = %u;', $clientID));
        if ($clientUseragentID !== $useragentID) {
            $this->setError("invalid-input", "Client {$clientID} does not run useragent {$useragentID}");
            return;
        }
        $db->query(str_queryf('UPDATE
				run_useragent
			SET
				status = 0,
				completed = 0,
				results_id = NULL,
				updated = %s
			WHERE run_id = %u
			AND   useragent_id = %s;', swarmdb_dateformat(SWARM_NOW), $runID, $useragentID));
        $this->setData(array("jobID" => $jobID, "runID" => $runID, "clientID" => $clientID, "useragentID" => $useragentID, "result" => "ok"));
    }
开发者ID:rosssclafani,项目名称:testswarm,代码行数:56,代码来源:WiperunAction.php


示例11: doAction

 /**
  * @actionMethod POST: Required.
  * @actionParam int job_id
  * @actionParam string type: one of 'delete', 'reset'
  */
 public function doAction()
 {
     $db = $this->getContext()->getDB();
     $request = $this->getContext()->getRequest();
     if (!$request->wasPosted()) {
         $this->setError("requires-post");
         return;
     }
     $jobID = $request->getInt("job_id");
     $wipeType = $request->getVal("type");
     if (!$jobID || !$wipeType) {
         $this->setError("missing-parameters");
         return;
     }
     if (!in_array($wipeType, array("delete", "reset", "cancel"))) {
         $this->setError("invalid-input");
         return;
     }
     $jobOwner = $db->getOne(str_queryf("SELECT\n\t\t\t\tusers.name as user_name\n\t\t\tFROM jobs, users\n\t\t\tWHERE jobs.id = %u\n\t\t\tAND   users.id = jobs.user_id\n\t\t\tLIMIT 1;", $jobID));
     if (!$jobOwner) {
         // Job row by this ID didn't exist
         $this->setError("invalid-input");
         return;
     }
     // Check authentication
     if ($request->getSessionData("auth") !== "yes" || $request->getSessionData("username") !== $jobOwner) {
         $this->setError("requires-auth");
         return;
     }
     $runRows = $db->getRows(str_queryf("SELECT id\n\t\t\tFROM runs\n\t\t\tWHERE job_id = %u;", $jobID));
     if ($runRows) {
         foreach ($runRows as $runRow) {
             switch ($wipeType) {
                 case "delete":
                     $db->query(str_queryf("DELETE\n\t\t\t\t\t\t\tFROM run_useragent\n\t\t\t\t\t\t\tWHERE run_id = %u;", $runRow->id));
                     break;
                 case "reset":
                     $db->query(str_queryf("UPDATE run_useragent\n\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\tstatus = 0,\n\t\t\t\t\t\t\t\tcompleted = 0,\n\t\t\t\t\t\t\t\tresults_id = NULL,\n\t\t\t\t\t\t\t\tupdated = %s\n\t\t\t\t\t\t\tWHERE run_id = %u;", swarmdb_dateformat(SWARM_NOW), $runRow->id));
                     break;
                 case "cancel":
                     $db->query(str_queryf("UPDATE run_useragent\n\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\tstatus = 3,\n\t\t\t\t\t\t\t\tupdated = %s\n\t\t\t\t\t\t\tWHERE run_id = %u \n\t\t\t\t\t\t\t\tAND status = 0;", swarmdb_dateformat(SWARM_NOW), $runRow->id));
                     break;
             }
         }
     }
     // This should be outside the if for $runRows, because jobs
     // can sometimes be created without any runs (by accidently).
     // Those should be deletable as well, thus this has to be outside the loop.
     // Also, no  need to do this in a loop, just delete them all in one query.
     if ($wipeType === "delete") {
         $db->query(str_queryf("DELETE\n\t\t\t\tFROM runs\n\t\t\t\tWHERE job_id = %u;", $jobID));
         $db->query(str_queryf("DELETE\n\t\t\t\tFROM jobs\n\t\t\t\tWHERE id = %u;", $jobID));
     }
     $this->setData(array("jobID" => $jobID, "type" => $wipeType, "result" => "ok"));
 }
开发者ID:rhodblinkbox,项目名称:testswarm,代码行数:60,代码来源:WipejobAction.php


示例12: doAction

 /**
  * @actionMethod POST: Required.
  * @actionParam string jobName: May contain HTML.
  * @actionParam int runMax
  * @actionParam array runNames
  * @actionParam array runUrls
  * @actionParam array browserSets
  * @actionAuth: Required.
  */
 public function doAction()
 {
     $conf = $this->getContext()->getConf();
     $db = $this->getContext()->getDB();
     $request = $this->getContext()->getRequest();
     $projectID = $this->doRequireAuth();
     if (!$projectID) {
         return;
     }
     $jobId = $request->getInt("job_id");
     $testName = $request->getVal("test_name");
     $uaId = $request->getVal("ua_id");
     $db->query(str_queryf("LOCK TABLES runs WRITE;"));
     $runId = $db->getOne(str_queryf('SELECT
   id
   FROM
   runs
   WHERE job_id = %u
   AND   name = %s
   ORDER BY id DESC
   LIMIT 1;', $jobId, $testName));
     if (!$runId) {
         // Create this run
         $isInserted = $db->query(str_queryf("INSERT INTO runs (job_id, name, url, created)\n        VALUES(%u, %s, %s, %s);", $jobId, $testName, "http://localhost", swarmdb_dateformat(SWARM_NOW)));
         $runId = $db->getInsertId();
     }
     $db->query(str_queryf("UNLOCK TABLES;"));
     if (!$runId) {
         $this->setError("internal-error", "Could not get or create run id");
         return;
     }
     $db->query(str_queryf("LOCK TABLES clients WRITE;"));
     $clientId = $db->getOne(str_queryf('SELECT
   id
   FROM
   clients
   WHERE useragent_id = %s
   LIMIT 1;', $uaId));
     if (!$clientId) {
         $isNew = true;
         $isInserted = $db->query(str_queryf("INSERT INTO clients (name, useragent_id, useragent, ip, updated, created)\n        VALUES(%s, %s, %s, %s, %s, %s);", $uaId, $uaId, "SauceLabs", "123.456.789.000", swarmdb_dateformat(SWARM_NOW), swarmdb_dateformat(SWARM_NOW)));
         $clientId = $db->getInsertId();
     }
     $db->query(str_queryf("UNLOCK TABLES;"));
     $resultInserted = $db->query(str_queryf('INSERT INTO runresults
   (run_id, client_id, status, store_token, updated, created)
   VALUES(%u, %u, 1, %s, %s, %s);', $runId, $clientId, 0, swarmdb_dateformat(SWARM_NOW), swarmdb_dateformat(SWARM_NOW)));
     $runresultsId = $db->getInsertId();
     $isInserted = $db->query(str_queryf("INSERT INTO run_useragent (run_id, useragent_id, max, results_id, updated, created)\n      VALUES(%u, %s, %u, %u, %s, %s);", $runId, $uaId, 1, $runresultsId, swarmdb_dateformat(SWARM_NOW), swarmdb_dateformat(SWARM_NOW)));
     $newRunUAId = $db->getInsertId();
     $this->setData(array("resultsId" => $runresultsId, "runUAId" => $newRunUAId));
 }
开发者ID:TestArmada,项目名称:admiral,代码行数:61,代码来源:StarttestAction.php


示例13: doAction

    /**
     * @requestParam browserSet string: Show useragents from a specific
     * browserset only.
     * @requestParam onlyactive bool: 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()
    {
        $conf = $this->getContext()->getConf();
        $db = $this->getContext()->getDB();
        $request = $this->getContext()->getRequest();
        $showOnlyactive = $request->getBool('onlyactive');
        $filterBrowserSet = $request->getVal('browserSet', false);
        $data = array('userAgents' => array());
        $uaIndex = BrowserInfo::getSwarmUAIndex();
        foreach ($uaIndex as $uaID => $uaData) {
            if ($filterBrowserSet && isset($conf->browserSets->{$filterBrowserSet}) && !in_array($uaID, $conf->browserSets->{$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(time() - ($conf->client->pingTime + $conf->client->pingTimeMargin))));
            $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 ($showOnlyactive && !$clients && !$activeRuns && !$pendingRuns && !$pendingReRuns) {
                continue;
            }
            $data['userAgents'][$uaID] = array('data' => $uaData, 'stats' => array('onlineClients' => $clients, 'activeRuns' => $activeRuns, 'pendingRuns' => $pendingRuns, 'pendingReRuns' => $pendingReRuns));
        }
        $this->setData($data);
    }
开发者ID:rosssclafani,项目名称:testswarm,代码行数:59,代码来源:SwarmstateAction.php


示例14: doWipeJobs

    public function doWipeJobs($wipeType, array $jobIDs, $batchSize = 100)
    {
        $db = $this->getContext()->getDB();
        $stats = array('jobs' => 0, 'runs' => 0, 'run_useragent' => 0, 'runresults' => 0);
        $allRunRows = $db->getRows(str_queryf('SELECT id
			FROM runs
			WHERE job_id IN %l;', $jobIDs));
        if ($allRunRows) {
            $chunks = array_chunk($allRunRows, $batchSize);
            foreach ($chunks as $runRows) {
                $runIDs = array_map(function ($row) {
                    return $row->id;
                }, $runRows);
                if ($wipeType === 'delete') {
                    $db->query(str_queryf('DELETE
						FROM run_useragent
						WHERE run_id in %l;', $runIDs));
                } elseif ($wipeType === 'reset') {
                    $db->query(str_queryf('UPDATE run_useragent
						SET
							status = 0,
							completed = 0,
							results_id = NULL,
							updated = %s
						WHERE run_id in %l;', swarmdb_dateformat(SWARM_NOW), $runIDs));
                }
                $stats['run_useragent'] += $db->getAffectedRows();
                if ($wipeType === 'delete') {
                    $db->query(str_queryf('DELETE
						FROM runresults
						WHERE run_id in %l;', $runIDs));
                    $stats['runresults'] += $db->getAffectedRows();
                }
            }
        }
        // This should be outside the if for $allRunRows, because jobs
        // can sometimes be created without any runs (by accident).
        // Those should be deletable as well, thus this has to be outside the loop.
        // Also, no need to do this in a loop, just delete them all in one query.
        if ($wipeType === 'delete') {
            $db->query(str_queryf('DELETE
				FROM runs
				WHERE job_id IN %l;', $jobIDs));
            $stats['runs'] += $db->getAffectedRows();
            $db->query(str_queryf('DELETE
				FROM jobs
				WHERE id IN %l;', $jobIDs));
            $stats['jobs'] += $db->getAffectedRows();
        }
        return $stats;
    }
开发者ID:jquery,项目名称:testswarm,代码行数:51,代码来源:WipejobAction.php


示例15: doAction

 /**
  * @requestParam "item" integer: job id
  * @requestParam "type" string: one of 'delete', 'reset'
  */
 public function doAction()
 {
     $db = $this->getContext()->getDB();
     $request = $this->getContext()->getRequest();
     if (!$request->wasPosted()) {
         $this->setError("requires-post");
         return;
     }
     $jobID = $request->getInt("job_id");
     $wipeType = $request->getVal("type");
     if (!$jobID || !$wipeType) {
         $this->setError("missing-parameters");
         return;
     }
     if (!in_array($wipeType, array("delete", "reset"))) {
         $this->setError("invalid-input");
         return;
     }
     $jobOwner = $db->getOne(str_queryf("SELECT\n\t\t\t\tusers.name as user_name\n\t\t\tFROM jobs, users\n\t\t\tWHERE jobs.id = %u\n\t\t\tAND   users.id = jobs.user_id\n\t\t\tLIMIT 1;", $jobID));
     if (!$jobOwner) {
         // Job row by this ID didn't exist
         $this->setError("invalid-input");
         return;
     }
     // Check authentication
     if ($request->getSessionData("auth") !== "yes" || $request->getSessionData("username") !== $jobOwner) {
         $this->setError("requires-auth");
         return;
     }
     $runRows = $db->getRows(str_queryf("SELECT\n\t\t\t\tid\n\t\t\tFROM\n\t\t\t\truns\n\t\t\tWHERE runs.job_id = %u;", $jobID));
     // Put this outside the if for runRows,
     // otherwise bogus jobs with 0 runs can't be deleted
     if ($wipeType === "delete") {
         $db->query(str_queryf("DELETE\n\t\t\t\tFROM run_client\n\t\t\t\tWHERE run_id in (\n\t\t\t\t\tSELECT id\n\t\t\t\t\tFROM runs\n\t\t\t\t\tWHERE job_id = %u\n\t\t\t\t);", $jobID));
         $db->query(str_queryf("DELETE\n\t\t\t\tFROM run_useragent\n\t\t\t\tWHERE run_id in (\n\t\t\t\t\tSELECT id\n\t\t\t\t\tFROM runs\n\t\t\t\t\tWHERE job_id = %u\n\t\t\t\t);", $jobID));
         $db->query(str_queryf("DELETE\n\t\t\t\tFROM runs\n\t\t\t\tWHERE job_id = %u;", $jobID));
         $db->query(str_queryf("DELETE\n\t\t\t\tFROM jobs\n\t\t\t\tWHERE id = %u;", $jobID));
     }
     if ($runRows) {
         foreach ($runRows as $runRow) {
             $db->query(str_queryf("DELETE\n\t\t\t\t\tFROM run_client\n\t\t\t\t\tWHERE run_id = %u;", $runRow->id));
             if ($wipeType === "delete") {
                 $db->query(str_queryf("DELETE\n\t\t\t\t\t\tFROM run_useragent\n\t\t\t\t\t\tWHERE run_id = %u;", $runRow->id));
             } elseif ($wipeType === "reset") {
                 $db->query(str_queryf("UPDATE run_useragent\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\truns = 0,\n\t\t\t\t\t\t\tcompleted = 0,\n\t\t\t\t\t\t\tstatus = 0,\n\t\t\t\t\t\t\tupdated = %s\n\t\t\t\t\t\tWHERE run_id = %u;", swarmdb_dateformat(SWARM_NOW), $runRow->id));
             }
         }
     }
     $this->setData(array("jobID" => $jobID, "type" => $wipeType, "result" => "ok"));
 }
开发者ID:appendto,项目名称:testswarm,代码行数:54,代码来源:WipejobAction.php


示例16: doAction

 /**
  * @actionMethod GET: Required.
  * @actionParam int run_id
  * @actionParam string type: one of 'specStart', 'timeoutCheck'
  */
 public function doAction()
 {
     $request = $this->getContext()->getRequest();
     $runID = $request->getInt("run_id");
     $type = $request->getVal("type");
     if (!$runID || !$type) {
         $this->setError("missing-parameters");
         return;
     }
     if (!in_array($type, array("specStart", "timeoutCheck"))) {
         $this->setError("invalid-input");
         return;
     }
     $now = time();
     $db = $this->getContext()->getDB();
     $result = "";
     switch ($type) {
         case "specStart":
             if (!$request->wasGetted()) {
                 $this->setError("requires-get");
                 return;
             }
             $beatRate = $request->getInt("beatRate");
             $fail = $request->getInt("fail");
             $error = $request->getInt("error");
             $total = $request->getInt("total");
             if (!$beatRate) {
                 $this->setError("missing-parameters");
                 return;
             }
             $expected_update = $now + $beatRate;
             $db->query(str_queryf("UPDATE runresults\n\t\t\t\t\tSET\n\t\t\t\t\t\tfail = %u,\n\t\t\t\t\t\terror = %u,\n\t\t\t\t\t\ttotal = %u,\n\t\t\t\t\t\texpected_update = %s,\n\t\t\t\t\t\tupdated = %s\n\t\t\t\t\tWHERE run_id = %u\n\t\t\t\t\tAND status = 1\n\t\t\t\t\tAND ( expected_update IS NULL OR expected_update < %u );", $fail, $error, $total, swarmdb_dateformat($expected_update), swarmdb_dateformat($now), $runID, swarmdb_dateformat($expected_update)));
             $result = "ok";
             break;
         case "timeoutCheck":
             if (!$request->wasPosted()) {
                 $this->setError("requires-post");
                 return;
             }
             $timeoutMargin = 10;
             // 10 seconds margin
             $timestamp = $now + $timeoutMargin;
             // Check if run is timedout. Null expected_update stands for not timedout.
             $isTimedout = (bool) $db->getOne(str_queryf("SELECT IF(expected_update IS NULL, false, expected_update > %u)\n\t\t\t\t\tFROM runresults\n\t\t\t\t\tWHERE run_id = %u;", swarmdb_dateformat($timestamp), $runID));
             $result = array("testTimedout" => $isTimedout ? 'true' : 'false');
             break;
     }
     $this->setData($result);
 }
开发者ID:rhodblinkbox,项目名称:testswarm,代码行数:54,代码来源:RunnerAction.php


示例17: doAction

 public function doAction()
 {
     $db = $this->getContext()->getDB();
     $request = $this->getContext()->getRequest();
     if (!$request->wasPosted()) {
         $this->setError("requires-post");
         return;
     }
     $runID = $request->getInt("run_id");
     $clientID = $request->getInt("client_id");
     $useragentID = $request->getVal("useragent_id");
     if (!$runID || !$clientID) {
         $this->setError("missing-parameters");
         return;
     }
     $jobID = (int) $db->getOne(str_queryf("SELECT job_id FROM runs WHERE id = %u;", $runID));
     if (!$jobID) {
         $this->setError("invalid-input", "Run {$runID} not found.");
         return;
     }
     $jobOwner = $db->getOne(str_queryf("SELECT\n\t\t\t\tusers.name as user_name\n\t\t\tFROM jobs, users\n\t\t\tWHERE jobs.id = %u\n\t\t\tAND   users.id = jobs.user_id\n\t\t\tLIMIT 1;", $jobID));
     if (!$jobOwner) {
         $this->setError("invalid-input", "Job {$jobID} not found.");
         return;
     }
     // Check authentication
     if ($request->getSessionData("auth") !== "yes" || $request->getSessionData("username") !== $jobOwner) {
         $this->setError("requires-auth");
         return;
     }
     $runJobID = (int) $db->getOne(str_queryf("SELECT job_id\n\t\t\tFROM runs\n\t\t\tWHERE id 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP swarmpath函数代码示例发布时间:2022-05-23
下一篇:
PHP swapshuffle函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap