| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
use MediaWiki\Installer\DatabaseUpdater; |
| 23 |
use Wikimedia\Rdbms\IMaintainableDatabase; |
| 24 |
|
| 25 |
class DbTestRecorder extends TestRecorder { |
| 26 |
|
| 27 |
public $version; |
| 28 |
|
| 29 |
private $db; |
| 30 |
|
| 31 |
private $curRun; |
| 32 |
|
| 33 |
public function __construct( $db ) { |
| 34 |
$this->db = $db; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public function start() { |
| 42 |
$this->db->begin( __METHOD__ ); |
| 43 |
|
| 44 |
if ( !$this->db->tableExists( 'testrun', __METHOD__ ) |
| 45 |
|| !$this->db->tableExists( 'testitem', __METHOD__ ) |
| 46 |
) { |
| 47 |
print "WARNING> `testrun` table not found in database. Trying to create table.\n"; |
| 48 |
$updater = DatabaseUpdater::newForDB( $this->db ); |
| 49 |
$this->db->sourceFile( $updater->patchPath( $this->db, 'patch-testrun.sql' ) ); |
| 50 |
echo "OK, resuming.\n"; |
| 51 |
} |
| 52 |
|
| 53 |
$this->db->newInsertQueryBuilder() |
| 54 |
->insertInto( 'testrun' ) |
| 55 |
->row( [ |
| 56 |
'tr_date' => $this->db->timestamp(), |
| 57 |
'tr_mw_version' => $this->version, |
| 58 |
'tr_php_version' => PHP_VERSION, |
| 59 |
'tr_db_version' => $this->db->getServerVersion(), |
| 60 |
'tr_uname' => php_uname() |
| 61 |
] ) |
| 62 |
->caller( __METHOD__ ) |
| 63 |
->execute(); |
| 64 |
$this->curRun = $this->db->insertId(); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public function record( ParserTestResult $result ) { |
| 73 |
$desc = $result->getDescription(); |
| 74 |
$this->db->newInsertQueryBuilder() |
| 75 |
->insertInto( 'testitem' ) |
| 76 |
->row( [ |
| 77 |
'ti_run' => $this->curRun, |
| 78 |
'ti_name' => $desc, |
| 79 |
'ti_success' => $result->isSuccess() ? 1 : 0, |
| 80 |
] ) |
| 81 |
->caller( __METHOD__ ) |
| 82 |
->execute(); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public function end() { |
| 89 |
$this->db->commit( __METHOD__ ); |
| 90 |
} |
| 91 |
} |