+
+ /**
+ * Drop a field from an existing table
+ *
+ * @param $table String Name of the table to modify
+ * @param $field String Name of the old field
+ * @param $patch String Path to the patch file
+ * @param $fullpath Boolean Whether to treat $patch path as a relative or not
+ */
+ function dropField( $table, $field, $patch, $fullpath = false ) {
+ if ( $this->db->fieldExists( $table, $field ) ) {
+ wfOut( "Table $table contains $field field. Dropping... " );
+ $this->applyPatch( $patch, $fullpath );
+ wfOut( "ok\n" );
+ } else {
+ wfOut( "...$table table does not contain $field field.\n" );
+ }
+ }
+
+ /**
+ * Drop an index from an existing table
+ *
+ * @param $table String: Name of the table to modify
+ * @param $index String: Name of the old index
+ * @param $patch String: Path to the patch file
+ * @param $fullpath Boolean: Whether to treat $patch path as a relative or not
+ */
+ function dropIndex( $table, $index, $patch, $fullpath = false ) {
+ if ( $this->db->indexExists( $table, $index ) ) {
+ wfOut( "Dropping $index from table $table... " );
+ $this->applyPatch( $patch, $fullpath );
+ wfOut( "ok\n" );
+ } else {
+ wfOut( "...$index key doesn't exist.\n" );
+ }
+ }
+
+ /**
+ * Modify an existing field
+ *
+ * @param $table String: name of the table to which the field belongs
+ * @param $field String: name of the field to modify
+ * @param $patch String: path to the patch file
+ * @param $fullpath Boolean: whether to treat $patch path as a relative or not
+ */
+ public function modifyField( $table, $field, $patch, $fullpath = false ) {
+ if ( !$this->db->tableExists( $table ) ) {
+ wfOut( "...$table table does not exist, skipping modify field patch\n" );
+ } elseif ( !$this->db->fieldExists( $table, $field ) ) {
+ wfOut( "...$field field does not exist in $table table, skipping modify field patch\n" );
+ } else {
+ wfOut( "Modifying $field field of table $table..." );
+ $this->applyPatch( $patch, $fullpath );
+ wfOut( "ok\n" );
+ }
+ }
+
+ /**
+ * Purge the objectcache table
+ */
+ protected function purgeCache() {
+ # We can't guarantee that the user will be able to use TRUNCATE,
+ # but we know that DELETE is available to us
+ wfOut( "Purging caches..." );
+ $this->db->delete( 'objectcache', '*', __METHOD__ );
+ wfOut( "done.\n" );
+ }
+
+ /**
+ * Check the site_stats table is not properly populated.
+ */
+ protected function checkStats() {
+ wfOut( "Checking site_stats row..." );
+ $row = $this->db->selectRow( 'site_stats', '*', array( 'ss_row_id' => 1 ), __METHOD__ );
+ if ( $row === false ) {
+ wfOut( "data is missing! rebuilding...\n" );
+ } elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) {
+ wfOut( "missing ss_total_pages, rebuilding...\n" );
+ } else {
+ wfOut( "done.\n" );
+ return;
+ }
+ SiteStatsInit::doAllAndCommit( false );
+ }
+