With some prompting from Nischay Nahata, I found the answer I was looking
for.  Instead of the exec($refreshcmd) line, it was as simple as running a
SMWUpdateJob:
    $updatejob = new SMWUpdateJob( $t );
    $updatejob->run();
The index variable is now $t instead of $index, and I saved each whole
Title object rather than just the ArticleID, so the other line that needed
an update was:
    $sdpfPagesToRefresh[] = $titletoupdate;

This works great.  I've put up a permanent test page on my wiki
<http://ropewiki.com/index.php/Test_dependence_remote> if anyone else wants
to look at the page structure that causes this problem, and how
#semanticdependent solves that problem.  This isn't a solution that will
work for all cases, but it works well in mine.

Thanks,
Ben


On Thu, Jun 12, 2014 at 5:59 PM, Benjamin Pelletier <bjpcalt...@gmail.com>
wrote:

> 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