Like many SMW users, I'm having trouble with a feature of my SMW where a
page's property value is set based on a query of other pages.  I know
that's a Bad Thing <https://bugzilla.wikimedia.org/show_bug.cgi?id=22751>,
but it's extremely useful and there aren't any good alternatives*.  Here's
the setup: page A sets Local Property equal to {{#show:B|?Remote
Property#-}}.  Page B gets edited to change Remote Property.  Now, page A's
Local Property is still the old value despite the fact that if page A
contains {{#show:B|?Remote Property}}, it will display the new value.
 There is nothing a normal user can do to get page A's Local Property to
update except editing page A.

There is one thing that successfully updates Local Property though --
running SMW_refreshData.php on page A.  So, to solve my problem, all I have
to do is run that script whenever page B is edited.  It turns out this is
easy in my case because page B will always have a certain Template, so I
just created a ParserFunction that notes dependencies (in the form
{{#semanticdependent:A}}), and then runs the script for each of these
dependencies upon PageContentSaveComplete of page B.  This actually
works**, but exec'ing a php file...ugly!  *What SMW classes/methods should
I look up to reproduce what the script is doing*, but without the crazy
exec statement?  Any other suggestions welcome also, of course.

== Footnotes ==
*The application is a user rating system.  When a user rates a page, it
creates a Votes:PageName/UserName page with properties for the page being
rated, the rating given, and the rater.  The original page, through a
template, automatically computes its average rating and assigns that rating
to a property.  This rating is important information and is displayed on
large queries.  If the query has 200 results, this method uses just 1
query.  If I had to subquery the average rating of each page in the
results, that would be 201 queries.  The latter seems to be unacceptable
from a performance standpoint.

**Ok, almost works.  I don't know when SMW saves its properties to the
database, but it must be after PageContentSaveComplete because the code
below actually updates Local Property to the previous value of Remote
Property.  Local Property does actually get updated (that doesn't happen
via any other method except editing page A), but it doesn't take the newest
value of page B's Remote Property.

== Simplified code (in custom extension) ==
$sdpfPagesToRefresh = array();
function SemanticDependencyPageContentSaveComplete( <...> )
  global $sdpfPagesToRefresh;
  foreach ($sdpfPagesToRefresh as $index) {
    $refreshcmd = "php " . getcwd() .
"/extensions/SemanticMediaWiki/maintenance/SMW_refreshData.php -s " .
$index . " -n 0";
    exec($refreshcmd);
  }
  return true;
}

function SemanticDependencyRenderParserFunction( $parser ) {
  $titletoupdate = Title::newFromText( func_get_arg(1) );
  global $sdpfPagesToRefresh;
  $sdpfPagesToRefresh[] = $titletoupdate->getArticleID();
  return "";
}
------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems
_______________________________________________
Semediawiki-devel mailing list
Semediawiki-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel

Reply via email to