[pmwiki-devel] [Solved] UpdatePage() and warnings

Petko Yotov 5ko at free.fr
Wed Nov 8 19:21:50 CST 2006


> > 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

The UpdatePage() seems to be working now, with no side effects. Big thanks to 
Pm and Crisses!

If you wonder why such a function, what I am tinkering is a functionnality to 
quickly send a sort of yellow-sticky-notes or links-to-wiki-pages to one of 
31 calendar pages. At midnight, pmwiki grabs the current-day page and moves 
its' content into the INBOX page, so the user can easily see his tasks or 
reminders for that day.

It is not at all finished now, neither I know if it will be as usable and 
effective as I imagine, but if someone is interested, tell me and I will send 
you what I have. (I am using a pmwiki installation for a personal notes/todo 
manager.)

Thanks again for your help!

Take care,
Petko



More information about the pmwiki-devel mailing list