I'm trying to write an own maintenance script.
I want to update a custom column in the page
table using the age of the page. Therefor I have to query revision.rev_timestamp
.
But
foreach( $res as $row ) { $page_id = $row->page_id; $res = $db->select("revision", "rev_timestamp", "rev_page = $page_id", "ORDER BY `rev_timestamp` ASC LIMIT 1", __METHOD__); //timestamp of page creation date $mySQLtimestamp = $db->fetchObject( $res ); ...
Gives me the error: "Catchable fatal error: Object of class stdClass could not be converted to string"
public function execute() { $db = wfGetDB( DB_MASTER ); $start = $db->selectField( 'page', 'MIN(page_id)', false, __METHOD__ ); if( !$start ) { $this->error( "Nothing to do.", true ); } $end = $db->selectField( 'page', 'MAX(page_id)', false, __METHOD__ ); # Do remaining chunk $end += $this->mBatchSize - 1; $blockStart = $start; $blockEnd = $start + $this->mBatchSize - 1; while( $blockEnd <= $end ) { $this->output( "...doing page_id from $blockStart to $blockEnd\n" ); $cond = "page_id BETWEEN $blockStart AND $blockEnd; $res = $db->select('page', array('page_id', 'page_custom', 'page_counter', 'page_namespace', 'page_title'), $cond, __METHOD__ ); foreach( $res as $row ) { $page_id = $row->page_id; $res = $db->select("revision", "rev_timestamp", "rev_page = $page_id", "ORDER BY `rev_timestamp` ASC LIMIT 1", __METHOD__); //timestamp of page creation date $mySQLtimestamp = $db->fetchObject( $res ); #$mySQLtimestamp returns: Catchable fatal error: Object of class stdClass could not be converted to string $namespace = $row->page_namespace; $pagetitle = $row->page_title; $fooVal = someFunction($namespace, $pagetitle); #update page_custom using $fooVal and $mySQLtimestamp } $blockStart += $this->mBatchSize - 1; $blockEnd += $this->mBatchSize - 1; wfWaitForSlaves( 5 ); } $this->output( "...Done!\n" ); }
How can this be fixed?