Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
CargoPopulateTableJob | |
0.00% |
0 / 32 |
|
0.00% |
0 / 2 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
run | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
72 |
1 | <?php |
2 | /** |
3 | * Background job to populate the database table for one template using the |
4 | * data from the call(s) to that template in one page. |
5 | * |
6 | * @ingroup Cargo |
7 | * @author Yaron Koren |
8 | */ |
9 | |
10 | class CargoPopulateTableJob extends Job { |
11 | |
12 | /** |
13 | * @param Title $title |
14 | * @param array $params |
15 | */ |
16 | public function __construct( $title, array $params = [] ) { |
17 | parent::__construct( 'cargoPopulateTable', $title, $params ); |
18 | } |
19 | |
20 | /** |
21 | * Run a CargoPopulateTable job. |
22 | * |
23 | * @return bool success |
24 | */ |
25 | public function run() { |
26 | if ( $this->title === null ) { |
27 | $this->error = "cargoPopulateTable: Invalid title"; |
28 | return false; |
29 | } |
30 | |
31 | $tableName = $this->params['dbTableName']; |
32 | if ( substr( $tableName, 0, 1 ) == '_' ) { |
33 | $cdb = CargoUtils::getDB(); |
34 | $possibleReplacementTable = $tableName . '__NEXT'; |
35 | $createReplacement = $cdb->tableExists( $possibleReplacementTable, __METHOD__ ); |
36 | if ( $tableName == '_pageData' ) { |
37 | CargoPageData::storeValuesForPage( $this->title, $createReplacement ); |
38 | } elseif ( $tableName == '_fileData' ) { |
39 | CargoFileData::storeValuesForFile( $this->title, $createReplacement ); |
40 | } elseif ( $tableName == '_bpmnData' ) { |
41 | CargoBPMNData::storeBPMNValues( $this->title, $createReplacement ); |
42 | } elseif ( $tableName == '_ganttData' ) { |
43 | CargoGanttData::storeGanttValues( $this->title, $createReplacement ); |
44 | } else { |
45 | $this->error = "cargoPopulateTable: Invalid table " . $tableName; |
46 | return false; |
47 | } |
48 | return true; |
49 | } |
50 | |
51 | $page = CargoUtils::makeWikiPage( $this->title ); |
52 | |
53 | // If it was requested, delete all the existing rows for |
54 | // this page in this Cargo table. This is only necessary |
55 | // if the table wasn't just dropped and recreated. |
56 | if ( $this->params['replaceOldRows'] == true ) { |
57 | $cdb = CargoUtils::getDB(); |
58 | $cdb->begin( __METHOD__ ); |
59 | $cdb->delete( $this->params['dbTableName'], [ '_pageID' => $page->getID() ], __METHOD__ ); |
60 | $cdb->commit( __METHOD__ ); |
61 | } |
62 | |
63 | // All we need to do here is set some global variables based |
64 | // on the parameters of this job, then parse the page - |
65 | // the #cargo_store function will take care of the rest. |
66 | CargoStore::$settings['origin'] = 'template'; |
67 | CargoStore::$settings['dbTableName'] = $this->params['dbTableName']; |
68 | CargoUtils::parsePageForStorage( $this->title, CargoUtils::getContentText( $page->getContent() ) ); |
69 | |
70 | // We need to unset this, if the job was called via runJobs.php, |
71 | // so that it doesn't affect other (non-Cargo) jobs, like page |
72 | // refreshes. |
73 | unset( CargoStore::$settings['origin'] ); |
74 | |
75 | return true; |
76 | } |
77 | } |