This repository was archived by the owner on Jan 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathfixRunresultCorruption.php
More file actions
57 lines (50 loc) · 1.49 KB
/
fixRunresultCorruption.php
File metadata and controls
57 lines (50 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* fixRunresultCorruption.php
*
* @author Timo Tijhof
* @since 1.0.0
* @package TestSwarm
*/
define( 'SWARM_ENTRY', 'SCRIPT' );
require_once __DIR__ . '/../inc/init.php';
class FixRunresultCorruptionScript extends MaintenanceScript {
protected function init() {
$this->setDescription(
'Scan runresults and run_useragent tables for data that was corrupted. In particular runresults with status=4 (Client Lost) that were not unlinked from run_useragent (as CleanupAction should do).'
);
}
protected function execute() {
$db = $this->getContext()->getDB();
$corrupt = 0;
$this->out( "Scanning..." );
$resultRows = $db->getRows('SELECT id FROM runresults WHERE status=4;');
if ( $resultRows ) {
foreach ( $resultRows as $resultRow ) {
$runRow = $db->getOne( str_queryf( 'SELECT 1 FROM run_useragent WHERE results_id=%u;', $resultRow->id ) );
if ( $runRow ) {
$corrupt++;
$this->outRaw( "Result #{$resultRow->id}" );
// See also CleanupAction::doAction
$executed = $db->query(str_queryf(
"UPDATE run_useragent
SET
status = 0,
results_id = NULL
WHERE results_id = %u;",
$resultRow->id
));
if ( $executed ) {
$this->outRaw( " ... Fixed!\n" );
} else {
$this->outRaw( " ... Failed!\n" );
}
$this->out( "..." );
}
}
}
$this->out( "Found {$corrupt} instances of corrupted data." );
}
}
$script = FixRunresultCorruptionScript::newFromContext( $swarmContext );
$script->run();