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 | use MediaWiki\Title\Title; |
| 11 | |
| 12 | class CargoPopulateTableJob extends Job { |
| 13 | |
| 14 | /** |
| 15 | * @param Title $title |
| 16 | * @param array $params |
| 17 | */ |
| 18 | public function __construct( $title, array $params = [] ) { |
| 19 | parent::__construct( 'cargoPopulateTable', $title, $params ); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Run a CargoPopulateTable job. |
| 24 | * |
| 25 | * @return bool success |
| 26 | */ |
| 27 | public function run() { |
| 28 | if ( $this->title === null ) { |
| 29 | $this->error = "cargoPopulateTable: Invalid title"; |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | $tableName = $this->params['dbTableName']; |
| 34 | if ( substr( $tableName, 0, 1 ) == '_' ) { |
| 35 | $cdb = CargoUtils::getDB(); |
| 36 | $possibleReplacementTable = $tableName . '__NEXT'; |
| 37 | $createReplacement = $cdb->tableExists( $possibleReplacementTable, __METHOD__ ); |
| 38 | if ( $tableName == '_pageData' ) { |
| 39 | CargoPageData::storeValuesForPage( $this->title, $createReplacement ); |
| 40 | } elseif ( $tableName == '_fileData' ) { |
| 41 | CargoFileData::storeValuesForFile( $this->title, $createReplacement ); |
| 42 | } elseif ( $tableName == '_bpmnData' ) { |
| 43 | CargoBPMNData::storeBPMNValues( $this->title, $createReplacement ); |
| 44 | } elseif ( $tableName == '_ganttData' ) { |
| 45 | CargoGanttData::storeGanttValues( $this->title, $createReplacement ); |
| 46 | } else { |
| 47 | $this->error = "cargoPopulateTable: Invalid table " . $tableName; |
| 48 | return false; |
| 49 | } |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | $page = CargoUtils::makeWikiPage( $this->title ); |
| 54 | |
| 55 | // If it was requested, delete all the existing rows for |
| 56 | // this page in this Cargo table. This is only necessary |
| 57 | // if the table wasn't just dropped and recreated. |
| 58 | if ( $this->params['replaceOldRows'] == true ) { |
| 59 | $cdb = CargoUtils::getDB(); |
| 60 | $cdb->begin( __METHOD__ ); |
| 61 | $cdb->delete( $this->params['dbTableName'], [ '_pageID' => $page->getID() ], __METHOD__ ); |
| 62 | $cdb->commit( __METHOD__ ); |
| 63 | } |
| 64 | |
| 65 | // All we need to do here is set some global variables based |
| 66 | // on the parameters of this job, then parse the page - |
| 67 | // the #cargo_store function will take care of the rest. |
| 68 | try { |
| 69 | CargoStore::$settings['origin'] = 'template'; |
| 70 | CargoStore::$settings['dbTableName'] = $this->params['dbTableName']; |
| 71 | CargoUtils::parsePageForStorage( $this->title, CargoUtils::getContentText( $page->getContent() ) ); |
| 72 | } finally { |
| 73 | // We need to unset this, if the job was called via runJobs.php, so that it doesn't affect other (non-Cargo) |
| 74 | // jobs, like page refreshes. |
| 75 | // This must be done in a 'finally' block so that if parsePageForStorage throws an exception, the flag is |
| 76 | // still cleared. |
| 77 | unset( CargoStore::$settings['origin'] ); |
| 78 | } |
| 79 | |
| 80 | return true; |
| 81 | } |
| 82 | } |