Navigation Menu

Skip to content

Commit

Permalink
fix gpPageSet.strip
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.toolserver.org/svnroot/daniel/duesenstuff/trunk/gpClient@544 9f2c43bc-b3c0-43f4-b155-41619b16f219
  • Loading branch information
Daniel Kinzler committed Dec 21, 2011
1 parent 424b97b commit 36a19c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 53 deletions.
39 changes: 13 additions & 26 deletions php/gpMediaWiki.php
Expand Up @@ -176,7 +176,7 @@ public static function new_slave_connection( $command, $cwd = null, $env = null
return new gpMediaWikiGlue( new gpSlaveTransport($command, $cwd, $env) );
}

public function condition_sql( $where, $assume_literals = true ) {
public function condition_sql( $where, $assume_literals = true, $inverse = false ) {
if ( is_array($where) ) {
if ( isset( $where[0] ) ) { #indexed array
$where = '(' . implode(') AND (', $where) . ')';
Expand All @@ -188,9 +188,9 @@ public function condition_sql( $where, $assume_literals = true ) {
$where .= '(';
$where .= $k;

if ( is_array($v) ) $where .= ( $inverse ? " not in " : " in " ) . $this->glue->as_list( $v );
if ( is_array($v) ) $where .= ( $inverse ? " not in " : " in " ) . $this->as_list( $v );
elseif ( is_string($v) && !$assume_literals ) $where .= ( $inverse ? " != " : " = " ) . $v; # field reference or quoted literal
else $where .= ( $inverse ? " != " : " = " ) . $this->glue->as_literal( $v );
else $where .= ( $inverse ? " != " : " = " ) . $this->as_literal( $v );

$where .= ')';
}
Expand Down Expand Up @@ -240,26 +240,13 @@ public function get_table() {
}

public function create_table( ) {
$table = $this->table;
$t = "";

if ( !$table || $table === '?' ) {
$table = "gp_temp_" . $this->glue->next_id();
$t = " TEMPORARY ";
}

$sql = "CREATE $t TABLE " . $table;
$sql .= "(";
$sql .= $this->table_obj->get_field_definitions();
$sql .= ")";

$this->query($sql);

$this->table = $table;
$this->table_obj->set_name( $this->table );
$this->table_id_obj->set_name( $this->table );
#TODO: port this solution using make_temp_table to python!
$this->table_obj = $this->glue->make_temp_table( $this->table_obj );

return $table;
$this->table = $this->table_obj->get_name();
$this->table_id_obj->set_name( $this->table );

return $this->table;

}

Expand Down Expand Up @@ -447,7 +434,7 @@ public function remove_page_id( $id ) {
}

public function strip_namespace( $ns, $inverse = false ) {
$where = $this->namespace_field . ' = ' . (int)$ns;
$where = array( $this->namespace_field => $ns );
return $this->strip( $where, null, $inverse );
}

Expand Down Expand Up @@ -502,7 +489,7 @@ public function retian_larger( $size ) { #TODO: port to python!
}

public function strip( $where, $join = null, $inverse = false ) { #TODO: port to python!
if ( $where ) $where = $this->glue->condition_sql($where);
if ( $where ) $where = $this->glue->condition_sql($where, true, $inverse);

if ( is_array($join) ) {
if ( isset( $join[0] ) ) { #indexed array
Expand All @@ -521,8 +508,8 @@ public function strip( $where, $join = null, $inverse = false ) { #TODO: port to
}

if ( $join ) {
$sql = 'DELETE FROM TTT ';
$sql .= ' USING ' . $this->table . ' AS TTT ';
$sql = 'DELETE FROM T ';
$sql .= ' USING ' . $this->table . ' AS T ';
$sql .= $join;
} else {
$sql = 'DELETE FROM ' . $this->table;
Expand Down
31 changes: 4 additions & 27 deletions php/test/gpMediaWiki.test.php
Expand Up @@ -378,7 +378,7 @@ public function testAddPageSet() {
$cheese->dispose();
}

public function testDeleteWhere() {
public function testStrip() {
$this->makeWikiStructure();
$this->gp->add_arcs_from_category_structure();

Expand All @@ -388,7 +388,7 @@ public function testDeleteWhere() {
$set->add_pages_in("topics", null, 5);

//-----------------------------------------------------------
$set->delete_where( "where page_namespace = " . NS_CATEGORY );
$set->strip( "page_namespace = " . NS_CATEGORY );

$a = $set->capture();
$expected = array(array(1111, NS_MAIN, "Lager"),
Expand All @@ -397,35 +397,12 @@ public function testDeleteWhere() {

$this->assertEquals($expected, $a );

#TODO: test joins
#TODO: test $where and $join as array, both indexed and assoc
//-----------------------------------------------------------
$set->dispose();
}

public function testDeleteUsing() {
$this->makeWikiStructure();
$this->gp->add_arcs_from_category_structure();

$set = new gpPageSet($this->gp);
$set->create_table();

$set->add_pages_in("topics", null, 5);

//-----------------------------------------------------------
$sql = " JOIN " . $this->gp->wiki_table("templatelinks") . " as X ";
$sql .= " ON T.page_id = X.tl_from ";
$sql .= " WHERE X.tl_namespace = " . NS_TEMPLATE;
$sql .= " AND X.tl_title = " . $this->gp->quote_string("Yuck");

$set->delete_using( $sql );

$a = $set->capture(NS_MAIN);
$expected = array(array(1112, NS_MAIN, "Pils"));

$this->assertEquals($expected, $a );

//-----------------------------------------------------------
$set->dispose();
}

public function testStripNamespace() {
$this->makeWikiStructure();
Expand Down

0 comments on commit 36a19c3

Please sign in to comment.