59 $delete = $this->hasOption(
'delete' );
60 $all = $this->hasOption(
'all' );
61 $dbw = $this->getPrimaryDB();
62 $this->beginTransaction( $dbw, __METHOD__ );
64 $res = $dbw->newSelectQueryBuilder()
65 ->select(
'page_title' )
67 ->where( [
'page_namespace' => $ns ] )
68 ->caller( __METHOD__ )->fetchResultSet();
72 foreach ( $res as $row ) {
74 $title = Title::makeTitle( $ns, $row->page_title );
75 $id = $title->getArticleID();
78 $revs = $dbw->newSelectQueryBuilder()
81 ->where( [
'rev_page' => $id ] )
82 ->caller( __METHOD__ )->fetchFieldValues();
83 $count = count( $revs );
86 if ( $all || $count == 1 ) {
87 # echo $title->getPrefixedText(), "\t", $count, "\n";
88 $this->output(
"delete: " . $title->getPrefixedText() .
"\n" );
93 $dbw->newDeleteQueryBuilder()
94 ->deleteFrom(
'page' )
95 ->where( [
'page_id' => $id ] )
96 ->caller( __METHOD__ )->execute();
97 $this->commitTransaction( $dbw, __METHOD__ );
100 $child = $this->runChild( NukePage::class,
'nukePage.php' );
101 '@phan-var NukePage $child';
102 $child->deleteRevisions( $revs );
106 $this->output(
"skip: " . $title->getPrefixedText() .
"\n" );
109 $this->commitTransaction( $dbw, __METHOD__ );
111 if ( $n_deleted > 0 ) {
112 $this->purgeRedundantText(
true );
114 # update statistics - better to decrement existing count, or just count
116 $pages = $dbw->newSelectQueryBuilder()
117 ->select(
'ss_total_pages' )
118 ->from(
'site_stats' )
119 ->caller( __METHOD__ )->fetchField();
120 $pages -= $n_deleted;
121 $dbw->newUpdateQueryBuilder()
122 ->update(
'site_stats' )
123 ->set( [
'ss_total_pages' => $pages ] )
124 ->where( [
'ss_row_id' => 1 ] )
125 ->caller( __METHOD__ )
130 $this->output(
"To update the database, run the script with the --delete option.\n" );