[pmwiki-users] Perplexing Page Exist problem...

The Editor editor at fast.st
Tue Aug 22 16:44:27 CDT 2006


I am working out one strange twist in the FAST Data project.  Maybe
someone can help me figure it out.

I'll be releasing v0.99 just as soon as this is done.  It includes an
enumerator (for numbered forum threads, or issue tracking, etc), an
option to hide field values, and an append feature perfect for comment
boxes, etc, plus always a few other fixes and stuff.  It's working
great--almost.  And this release will include the last of the
capabilities on my to do list.

The problem is I have two switches, one called SaveData and one called
AppendData.  Both work fine by themselves, and if the datapage exists,
both work fine together. But, if both switches are called on a form
and the datapage does not exist, whichever one comes second overrides
the first.

Both switches are very similar.  Both check to see if the datapage
exists, both parse various data fields and then both saves/appends it,
creating the datapage if it doesn't yet exist.

When whichever switch is second is called (It doesn't matter which is
first or second), it acts as if the page still does not exists, though
the first switch clearly created it .  Anyway, that conditional
failure causes the data saved by the first switch to be overwritten.

Why might the PageExists() function be failing?  Is it an indexing
problem or does this function actually go out and check for the
existence of a page?  I am using PageIndexUpdate("$datapage"); at the
end of both switches, so the page should be reindexed, but perhaps the
two switches are happening too fast--and there's not time to get it
indexed. Is there some way to work around this?

I included the two switches below if it helps, but I'm pretty sure I
have the problem narrowed down to the critical issue.  Thanks again
all!

Cheers,
Caveman

Two switches
			case "SaveData" :
				if (substr($datapage, 0, 4) != "Data") {
		   	   		break;
			    	}
				$data = '';
				$d = explode(",", $value);
				foreach ($d as $f => $v) {
					if (substr($v,0,1) == '-' ) {
						$v = substr($v,1);
						if ($_POST[$v] != "") $data .= "$_POST[$v] %0a%0a";
						}
					else {
						$data .= "$v=\"$_POST[$v]\" %0a%0a";
						}
					}
				if (PageExists("$datapage")) {
					$dr = fopen("$WorkDir/$datapage", "rb");
					$pc = fread($dr, filesize("$WorkDir/$datapage"));
					fclose($dr);
					$dc = explode("(:comment data:) %0a%0a", $pc);
					}
				else {
					$dc = array('','','[[#Data]] %0a%0a');
					}
				$dc[0] ="version=pmwiki-2.1.11 ordered=1 urlencoded=1
text=";
				$dc[1] = $data;
				$pc = "$dc[0](:comment data:) %0a%0a$dc[1](:comment data:)
%0a%0a$dc[2](:comment data:) %0a%0a";
				if ($ds = fopen("$WorkDir/$datapage", "wb")){
					fwrite($ds,"$pc");
					fclose($ds);
					PageIndexUpdate("$datapage");
					}
				break;

			case "AppendData" :
				if (substr($datapage, 0, 4) != "Data") {
		   	   		break;
			    	}
				$data = '';
				$d = explode(",", $value);
				foreach ($d as $f => $v) {
					if (substr($v,0,1) == '-' ) {
						$v = substr($v,1);
						$data .= "$_POST[$v] %0a%0a";
						}
					else {
						$data .= "$v=\"$_POST[$v]\" %0a%0a";
						}
					}
				if (PageExists("$datapage")) {
					$dr = fopen("$WorkDir/$datapage", "rb");
					$pc = fread($dr, filesize("$WorkDir/$datapage"));
					fclose($dr);
					$dc = explode("(:comment data:) %0a%0a", $pc);
					}
				else {
					$dc[1] = "";
					$dc[2] = "[[#Data]] %0a%0a";					
					}
				$dc[0] ="version=pmwiki-2.1.11 ordered=1 urlencoded=1
text=";
				$dc[2] .= $data;
				$pc = "$dc[0](:comment data:) %0a%0a$dc[1](:comment data:)
%0a%0a$dc[2](:comment data:) %0a%0a";
				if ($ds = fopen("$WorkDir/$datapage", "wb")){
					fwrite($ds,"$pc");
					fclose($ds);
					PageIndexUpdate("$datapage");
					}
				break;




More information about the pmwiki-users mailing list