[pmwiki-devel] UpdatePage() and warnings
Patrick R. Michaud
pmichaud at pobox.com
Wed Nov 8 07:46:17 CST 2006
On Tue, Nov 07, 2006 at 07:33:38PM +0100, Petko Yotov wrote:
> > > CopyPageText( 'Main.HomePage', 'Main.WikiSandbox');
> >
> > When is this function being called? It looks to me as
> > though it's being called prior to any of the markup rules
> > being loaded (and UpdatePage() really wants to occur
> > after the markup rules are loaded).
>
> I would like to call it once per day. I have a list of pages to be checked and
> moved into a sort of "Inbox", if their content is outdated. So, there is a
> file "$WorkDir/.textcopied" that is touched after the function call:
>
> (simplified)
>
> $stamp = intval(@filemtime("$WorkDir/.textcopied"));
> $now = time();
> if($now - $stamp > 60*60*24)
> {
> foreach($MyListOfPages as $mypage)
> {
> CopyPageText($mypage, 'Main.INBOX');
> }
> touch("$WorkDir/.textcopied");
> }
>
> That is in a cookbook-type file called from config.php.
>
> So, how can I postpone the UpdatePage() call after the markup rules are
> loaded?
I'd do it using register_shutdown_function, as follows:
$TextCopied = "$WorkDir/.textcopied";
$stamp = @filemtime($TextCopied);
$now = time();
if ($now - $stamp > 60*60*24)
register_shutdown_function('CopyListOfPages', getcwd());
function CopyListOfPages($dir = NULL) {
global $MyListOfPages, $TextCopied;
if ($dir) { flush(); chdir($dir); }
Lock(2);
foreach((array)$MyListOfPages as $mypage)
CopyPageText($mypage, 'Main.INBOX');
touch($TextCopied);
}
Note that in both versions (i.e., both with and without
register_shutdown_function), it's possible that two
or more nearly simultaneous requests can cause the
Main.INBOX page to be updated multiple times. I don't
know if that's a critical issue for you.
Pm
More information about the pmwiki-devel
mailing list