[pmwiki-devel] UpdatePage() and warnings

Crisses crisses at kinhost.org
Tue Nov 7 13:03:52 CST 2006


On Nov 7, 2006, at 1:33 PM, Petko Yotov wrote:

> On Tuesday 07 November 2006 15:16, you wrote:
>> On Sat, Nov 04, 2006 at 01:23:59AM +0100, Petko Yotov wrote:
>>> I am using pmwiki-2.2.0-beta15 an I am trying to copy a page  
>>> content into
>>> another page. I always get these errors:
>>>
>>> Warning: array_keys() [function.array-keys]: The first argument  
>>> should be
>>> an array in .../pmwiki.php on line 1458
>>>
>>> Warning: array_values() [function.array-values]: The argument  
>>> should be
>>> an array in .../pmwiki.php on line 1459
>>>
>>> Warning: preg_replace() [function.preg-replace]: Empty regular  
>>> expression
>>> in .../pmwiki.php on line 1459
>>>
>>> Here is my function (adapted from
>>> http://www.pmwiki.org/wiki/Cookbook/DebuggingForCookbookAuthors ):
>>>
>>> function CopyPageText($sourcename, $targetname)
>>> {
>>>     $source = RetrieveAuthPage($sourcename,"edit");
>>>     if (!$source) { return; }
>>>
>>>     $dest = RetrieveAuthPage($targetname,"edit");
>>>     if (!$dest) { return; }
>>>
>>>    $newdest = $dest;
>>>    $newdest['text'] .= "\n".$source['text'];
>>>
>>>    UpdatePage($targetname, $dest, $newdest);
>>> }
>>> 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).
>>
>> Pm
> Hello,
>
> 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?
>
> Thanks,
> Petko

If you saw my other post about this subject, what you want to do is  
delay the calling of this code until later.

#1 Move it all into a function.
#2 figure out a method of delay.

If you want this to run automatically, I suggest you do something  
like the following in your cookbook module:

$stamp = intval(@filemtime("$WorkDir/.textcopied"));
$now = time();
if($now - $stamp > 60*60*24)
{
register_shutdown_function("SwapPages", getcwd())
}

function SwapPages($dir = NULL) {
// disable for testing!!
//            ignore_user_abort();
         if ($dir) { flush(); chdir($dir); }
	foreach($MyListOfPages as $mypage)
	{
		CopyPageText($mypage, 'Main.INBOX');
	}
	touch("$WorkDir/.textcopied");
...
}

And make sure you look at all of PM's notes to Caveman about how to  
properly execute register_shutdown_function.

The nice thing about this is that the user won't have to wait a long  
time for their browser to reload.

Be careful about testing before you disable user abort, however.

Crisses
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/pmwiki-devel/attachments/20061107/ec8a5150/attachment.html 


More information about the pmwiki-devel mailing list