Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 43 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| SetCargoGanttData | |
0.00% |
0 / 38 |
|
0.00% |
0 / 2 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 33 |
|
0.00% |
0 / 1 |
72 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This script populates the Cargo _ganttData DB table (and possibly other |
| 5 | * auxiliary tables) for all pages in the wiki. |
| 6 | * |
| 7 | * Usage: |
| 8 | * php setCargoGanttData.php --delete --replacement |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along |
| 21 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 23 | * http://www.gnu.org/copyleft/gpl.html |
| 24 | * |
| 25 | * @author Yaron Koren |
| 26 | * @ingroup Maintenance |
| 27 | */ |
| 28 | |
| 29 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
| 30 | require_once getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'; |
| 31 | } else { |
| 32 | require_once __DIR__ . '/../../../maintenance/Maintenance.php'; |
| 33 | } |
| 34 | |
| 35 | use MediaWiki\Title\Title; |
| 36 | |
| 37 | $maintClass = SetCargoGanttData::class; |
| 38 | |
| 39 | class SetCargoGanttData extends Maintenance { |
| 40 | |
| 41 | public function __construct() { |
| 42 | parent::__construct(); |
| 43 | |
| 44 | $this->requireExtension( 'Cargo' ); |
| 45 | $this->addDescription( "Stores a set of data for each page in the Gantt namespace (defined by Flex Diagrams), for use within Cargo queries." ); |
| 46 | $this->addOption( "delete", "Delete the Gantt data DB table(s)", false, false ); |
| 47 | $this->addOption( 'replacement', 'Put all new data into a replacement table, to be switched in later' ); |
| 48 | } |
| 49 | |
| 50 | public function execute() { |
| 51 | $createReplacement = $this->hasOption( 'replacement' ); |
| 52 | $ganttDataTable = $createReplacement ? '_ganttData__NEXT' : '_ganttData'; |
| 53 | |
| 54 | $dbr = CargoUtils::getMainDBForRead(); |
| 55 | $res = $dbr->select( 'cargo_tables', [ 'field_tables', 'field_helper_tables' ], |
| 56 | [ 'main_table' => $ganttDataTable ], __METHOD__ ); |
| 57 | |
| 58 | $numRows = $res->numRows(); |
| 59 | if ( $numRows > 0 ) { |
| 60 | $row = $res->fetchRow(); |
| 61 | $fieldTables = unserialize( $row['field_tables'] ); |
| 62 | $fieldHelperTables = unserialize( $row['field_helper_tables'] ); |
| 63 | SpecialDeleteCargoTable::deleteTable( $ganttDataTable, $fieldTables, $fieldHelperTables ); |
| 64 | } |
| 65 | |
| 66 | if ( $this->getOption( "delete" ) ) { |
| 67 | if ( $numRows > 0 ) { |
| 68 | $this->output( "\n Deleted Gantt data table(s).\n" ); |
| 69 | } else { |
| 70 | $this->output( "\n No Gantt data tables found; exiting.\n" ); |
| 71 | } |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | $tableSchema = CargoGanttData::getTableSchema(); |
| 76 | $tableSchemaString = $tableSchema->toDBString(); |
| 77 | |
| 78 | $cdb = CargoUtils::getDB(); |
| 79 | $dbw = CargoUtils::getMainDBForWrite(); |
| 80 | CargoUtils::createCargoTableOrTables( $cdb, $dbw, $ganttDataTable, $tableSchema, $tableSchemaString, 0 ); |
| 81 | |
| 82 | $pages = $dbr->select( 'page', [ 'page_id' ], 'page_namespace = ' . FD_NS_GANTT, __METHOD__ ); |
| 83 | |
| 84 | foreach ( $pages as $page ) { |
| 85 | $title = Title::newFromID( $page->page_id ); |
| 86 | if ( $title == null ) { |
| 87 | continue; |
| 88 | } |
| 89 | CargoGanttData::storeGanttValues( $title, $createReplacement ); |
| 90 | $this->output( wfTimestamp( TS_DB ) . ' Stored Gantt data for page "' . $title->getFullText() . "\".\n" ); |
| 91 | } |
| 92 | |
| 93 | $this->output( "\n Finished populating Gantt data table(s).\n" ); |
| 94 | |
| 95 | $user = User::newSystemUser( 'Maintenance script', [ 'steal' => true ] ); |
| 96 | if ( $numRows >= 0 ) { |
| 97 | CargoUtils::logTableAction( 'recreatetable', $ganttDataTable, $user ); |
| 98 | } else { |
| 99 | CargoUtils::logTableAction( 'createtable', $ganttDataTable, $user ); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | } |
| 104 | |
| 105 | require_once RUN_MAINTENANCE_IF_MAIN; |