* Fixed notice when accessing special page without read permission and whitelist...
[lhc/web/wiklou.git] / maintenance / createNullLinksRows.php
1 <?
2
3 require( 'commandLine.inc' );
4
5 $db_master = wfGetDB( DB_MASTER );
6 $db_slave = wfGetDB( DB_SLAVE );
7
8 ## Do pagelinks update
9
10 echo "Updating pagelinks with null rows.\n";
11
12 $count = 0;
13
14 list( $page, $pagelinks ) = $db_slave->tableNamesN( 'page', 'pagelinks' );
15
16 $pl_query = "SELECT page_id
17 FROM $page
18 LEFT JOIN $pagelinks ON page_id=pl_from
19 WHERE pl_from IS NULL";
20
21 $res = $db_slave->query( $pl_query, 'createNullLinksRows' );
22
23 $buffer = array();
24
25 while ($row = $db_slave->fetchObject( $res ))
26 {
27 $buffer[] = array( 'pl_from' => $row->page_id, 'pl_namespace' => 0, 'pl_title' => '' );
28
29 $count++;
30
31 if (count($buffer) > 100)
32 {
33 #Batch-insert
34
35 echo "$count pages..\n";
36
37 $db_master->insert( 'pagelinks', $buffer, 'createNullLinksRows', array('IGNORE') );
38
39 wfWaitForSlaves(10);
40
41 $buffer = array();
42 }
43 }
44
45 # Insert the rest
46
47 echo "$count pages..\n";
48
49 $db_master->insert( 'pagelinks', $buffer, 'createNullLinksRows', array('IGNORE') );
50
51 wfWaitForSlaves(10);
52
53 ## Do categorylinks update
54
55 $buffer = array();
56
57 echo "Updating categorylinks with null rows.\n";
58
59 list( $page, $categorylinks ) = $db_slave->tableNamesN( 'page', 'categorylinks' );
60
61 $pl_query = "SELECT page_id
62 FROM $page
63 LEFT JOIN $categorylinks ON page_id=cl_from
64 WHERE cl_from IS NULL";
65
66 $res = $db_slave->query( $pl_query, 'createNullLinksRows' );
67
68 $buffer = array();
69
70 while ($row = $db_slave->fetchObject( $res ))
71 {
72 $buffer[] = array( 'cl_from' => $row->page_id, 'cl_to' => 0, 'cl_sortkey' => '' );
73
74 if (count($buffer) > 100)
75 {
76 #Batch-insert
77
78 echo "$count pages..\n";
79
80 $db_master->insert( 'categorylinks', $buffer, 'createNullLinksRows', array('IGNORE') );
81
82 wfWaitForSlaves(10);
83
84 $buffer = array();
85 }
86 }
87
88 echo "$count pages..\n";
89
90 $db_master->insert( 'categorylinks', $buffer, 'createNullLinksRows', array('IGNORE') );
91
92 $buffer = array();
93
94 echo "Done!\n";