Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Wikipedia: Mediawiki-CVS

SVN: [114905] trunk/extensions/PageTriage

 

 

Wikipedia mediawiki-cvs RSS feed   Index | Next | Previous | View Threaded


bsitu at svn

Apr 13, 2012, 5:22 PM

Post #1 of 1 (65 views)
Permalink
SVN: [114905] trunk/extensions/PageTriage

https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114905

Revision: 114905
Author: bsitu
Date: 2012-04-14 00:22:52 +0000 (Sat, 14 Apr 2012)
Log Message:
-----------
add cron job to update user metadata

Modified Paths:
--------------
trunk/extensions/PageTriage/includes/ArticleMetadata.php
trunk/extensions/PageTriage/includes/PageTriage.php
trunk/extensions/PageTriage/includes/PageTriageUtil.php

Added Paths:
-----------
trunk/extensions/PageTriage/cron/
trunk/extensions/PageTriage/cron/updateUserMetadata.php

Added: trunk/extensions/PageTriage/cron/updateUserMetadata.php
===================================================================
--- trunk/extensions/PageTriage/cron/updateUserMetadata.php (rev 0)
+++ trunk/extensions/PageTriage/cron/updateUserMetadata.php 2012-04-14 00:22:52 UTC (rev 114905)
@@ -0,0 +1,90 @@
+<?php
+
+$IP = getenv( 'MW_INSTALL_PATH' );
+if ( $IP === false ) {
+ $IP = dirname( __FILE__ ) . '/../../..';
+}
+require_once( "$IP/maintenance/Maintenance.php" );
+
+/**
+ * A maintenance script that updates expired user metadata
+ */
+class updateUserMetadata extends Maintenance {
+
+ /**
+ * Max number of article to process at a time
+ * @var int
+ */
+ protected $batchSize = 500;
+
+ /**
+ * Database Object
+ */
+ protected $dbr;
+ protected $dbw;
+
+ public function __construct() {
+ parent::__construct();
+ $this->mDescription = "Update the user metadata in pagetriage_page_tags table";
+ }
+
+ protected function init() {
+ $this->dbr = wfGetDB( DB_SLAVE );
+ }
+
+ public function execute() {
+ $this->init();
+ $this->output( "Started processing... \n" );
+
+ // Make the start time really old
+ $startTime = wfTimestamp( TS_UNIX ) - 60 * 60 * 24 * 365 * 10;
+ $count = $this->batchSize;
+ $startId = 0;
+
+ while ( $count === $this->batchSize ) {
+ $count = 0;
+ $startTime = $this->dbr->addQuotes( $this->dbr->timestamp( $startTime ) );
+
+ // Data should expire in a day, keep this inside loop so
+ // it's update to second
+ $expiration = wfTimestamp( TS_UNIX ) - 60 * 60 * 24;
+ $res = $this->dbr->select(
+ array( 'pagetriage_page' ),
+ array( 'ptrp_page_id', 'ptrp_created' ),
+ array(
+ '(ptrp_created > ' . $startTime . ') OR
+ (ptrp_created = ' . $startTime . ' AND ptrp_page_id > ' . $startId . ')',
+ 'ptrp_tags_updated < ' . $this->dbr->addQuotes( $this->dbr->timestamp( $expiration ) )
+ ),
+ __METHOD__,
+ array( 'LIMIT' => $this->batchSize, 'ORDER BY' => 'ptrp_created, ptrp_page_id' )
+ );
+
+ $pageId = array();
+ foreach ( $res as $row ) {
+ $pageId[] = $row->ptrp_page_id;
+ $count++;
+ }
+
+ if ( $pageId ) {
+ // update the startTime with the last row
+ $startTime = wfTimestamp( TS_UNIX, $row->ptrp_created );
+ $startId = $row->ptrp_page_id;
+
+ $acp = ArticleCompileProcessor::newFromPageId( $pageId );
+ if ( $acp ) {
+ $acp->registerComponent( 'UserData' );
+ $acp->compileMetadata();
+ }
+
+ $this->output( "processed $count \n" );
+ wfWaitForSlaves();
+ }
+ }
+
+ $this->output( "Completed \n" );
+ }
+}
+
+$maintClass = "updateUserMetadata";
+require_once( DO_MAINTENANCE );


Property changes on: trunk/extensions/PageTriage/cron/updateUserMetadata.php
___________________________________________________________________
Added: svn:eol-style
+ native

Modified: trunk/extensions/PageTriage/includes/ArticleMetadata.php
===================================================================
--- trunk/extensions/PageTriage/includes/ArticleMetadata.php 2012-04-14 00:09:58 UTC (rev 114904)
+++ trunk/extensions/PageTriage/includes/ArticleMetadata.php 2012-04-14 00:22:52 UTC (rev 114905)
@@ -407,10 +407,12 @@
}
$dbw->replace( 'pagetriage_page_tags', array( 'ptrpt_page_id', 'ptrpt_tag_id' ), $row, __METHOD__ );
}
+ $pt = new PageTriage( $pageId );
+ $row = array( 'ptrp_tags_updated' => $dbw->timestamp( wfTimestampNow() ) );
if ( isset( $data['deleted'] ) ) {
- $pt = new PageTriage( $pageId );
- $pt->setDeleted( $data['deleted'] ? '1' : '0' );
+ $row['ptrp_deleted'] = $data['deleted'] ? '1' : '0';
}
+ $pt->update( $row );
$dbw->commit();
}
}

Modified: trunk/extensions/PageTriage/includes/PageTriage.php
===================================================================
--- trunk/extensions/PageTriage/includes/PageTriage.php 2012-04-14 00:09:58 UTC (rev 114904)
+++ trunk/extensions/PageTriage/includes/PageTriage.php 2012-04-14 00:22:52 UTC (rev 114905)
@@ -5,8 +5,9 @@
// database property
protected $mPageId;
protected $mReviewed;
- protected $mTimestamp;
+ protected $mCreated;
protected $mDeleted;
+ protected $mTagsUpdated;

// additional property
protected $mLoaded;
@@ -110,22 +111,23 @@
}

/**
- * Set the deleted status
- */
- public function setDeleted( $deleted ) {
- if ( $deleted === '1' ) {
- $this->mDeleted = '1';
- } else {
- $this->mDeleted = '0';
+ * Update the database record
+ * @param $row array key => value pair to be updated
+ * Todo: ptrpt_reviewed should not updated from this function, add exception to catch this
+ * or find a better solution
+ */
+ public function update( $row ) {
+ if ( !$row ) {
+ return;
}
-
+
$dbw = wfGetDB( DB_MASTER );
$dbw->update(
'pagetriage_page',
- array( 'ptrp_deleted' => $this->mDeleted ),
+ $row,
array( 'ptrp_page_id' => $this->mPageId ),
__METHOD__
- );
+ );
}

/**
@@ -141,7 +143,7 @@

$res = $dbr->selectRow(
array( 'pagetriage_page' ),
- array( 'ptrp_reviewed', 'ptrp_created', 'ptrp_deleted' ),
+ array( 'ptrp_reviewed', 'ptrp_created', 'ptrp_deleted', 'ptrp_tags_updated' ),
array( 'ptrp_page_id' => $this->mPageId ),
__METHOD__
);
@@ -151,8 +153,9 @@
}

$this->mReviewed = $res->ptrp_reviewed;
- $this->mTimestamp = $res->ptrp_created;
+ $this->mCreated = $res->ptrp_created;
$this->mDeleted = $res->ptrp_deleted;
+ $this->mTagsUpdated = wfTimestamp( TS_UNIX, $res->ptrp_tags_updated );
$this->mLoaded = true;
return true;
}
@@ -208,6 +211,23 @@
$dbw->commit();
}

+ /**
+ * Set the tags updated timestamp
+ */
+ public static function bulkSetTagsUpdated( $pageIds ) {
+ $dbw = wfGetDB( DB_MASTER );
+
+ $now = wfTimestampNow();
+ $dbw->update(
+ 'pagetriage_page',
+ array( 'ptrp_tags_updated' => $dbw->timestamp( $now ) ),
+ array( 'ptrp_page_id' => $pageIds ),
+ __METHOD__
+ );
+
+ return $now;
+ }
+
}

class PageTriageMissingRevisionException extends MWException {}
\ No newline at end of file

Modified: trunk/extensions/PageTriage/includes/PageTriageUtil.php
===================================================================
--- trunk/extensions/PageTriage/includes/PageTriageUtil.php 2012-04-14 00:09:58 UTC (rev 114904)
+++ trunk/extensions/PageTriage/includes/PageTriageUtil.php 2012-04-14 00:22:52 UTC (rev 114905)
@@ -315,11 +315,14 @@
}

$dbw = wfGetDB( DB_MASTER );
+ $dbw->start();
$dbw->update(
'pagetriage_page_tags',
array( 'ptrpt_value' => $status ),
array( 'ptrpt_page_id' => $pageIds, 'ptrpt_tag_id' => $tags['user_block_status'] )
);
+ PageTriage::bulkSetTagsUpdated( $pageIds );
+ $dbw->commit();

$metadata = new ArticleMetadata( $pageIds );
$metadata->updateMetadataInCache( array( 'user_block_status' => $status ) );


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS [at] lists
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Wikipedia mediawiki-cvs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.