|
From: Gerrit R. <ri...@us...> - 2001-11-08 11:01:20
|
Update of /cvsroot/phpwiki/phpwiki/lib/WikiDB/backend
In directory usw-pr-cvs1:/tmp/cvs-serv23113/lib/WikiDB/backend
Modified Files:
cvs.php
Log Message:
extended the functionality of the cvs backend, extended the unit test
for the backend. have yet to start on th
Index: cvs.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/WikiDB/backend/cvs.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** cvs.php 2001/10/01 21:55:54 1.2
--- cvs.php 2001/11/08 11:01:16 1.3
***************
*** 54,60 ****
* set this to false and check out the
* document base beforehand
! * . debug_file ==> file name where debug information should be set.
* If file doesn't exist then it's created, if this
! * is empty, then no debugging is done.
* . pgsrc ==> directory name where the default wiki pages are stored.
* This is only required if the backend is to create a
--- 54,60 ----
* set this to false and check out the
* document base beforehand
! * . debug_file ==> file name where debug information should be sent.
* If file doesn't exist then it's created, if this
! * is empty, then debugging is turned off.
* . pgsrc ==> directory name where the default wiki pages are stored.
* This is only required if the backend is to create a
***************
*** 145,149 ****
// the metadata information about a page is stored in the
// CVS directory of the document root in serialized form. The
! // file always has the name _$pagename.
$metaFile = $this->_docDir . "/CVS/_" . $pagename;
--- 145,149 ----
// the metadata information about a page is stored in the
// CVS directory of the document root in serialized form. The
! // file always has the name, i.e. '_$pagename'.
$metaFile = $this->_docDir . "/CVS/_" . $pagename;
***************
*** 179,184 ****
* exist.
*/
! function update_pagedata($pagename, $newdata)
{
// retrieve the meta data
$metaData = $this->get_pagedata( $pagename );
--- 179,190 ----
* exist.
*/
! function update_pagedata($pagename, $newdata = array() )
{
+ // check argument
+ if ( ! is_array( $newdata ) ) {
+ trigger_error("update_pagedata: Argument 'newdata' was not array",
+ E_USER_WARNING);
+ }
+
// retrieve the meta data
$metaData = $this->get_pagedata( $pagename );
***************
*** 193,197 ****
$metaData[CMD_VERSION] = "1";
! if ( ! isset($newdata[$CONTENT])) {
$metaData[CMD_CONTENT] = "";
} else {
--- 199,203 ----
$metaData[CMD_VERSION] = "1";
! if ( ! isset($newdata[CMD_CONTENT])) {
$metaData[CMD_CONTENT] = "";
} else {
***************
*** 217,222 ****
}
! // update the page data, if required
! if ( isset( $metaData[CMD_CONTENT] ) ) {
$this->_writePage( $pagename, $newdata[CMD_CONTENT] );
}
--- 223,229 ----
}
! // update the page data, if required. Use newdata because it could
! // be empty and thus unset($metaData[CMD_CONTENT]).
! if ( isset( $newdata[CMD_CONTENT] ) ) {
$this->_writePage( $pagename, $newdata[CMD_CONTENT] );
}
***************
*** 225,231 ****
unset( $metaData[CMD_CONTENT] );
$metaData[CMD_LAST_MODIFIED] = time();
- $this->_writeMetaInfo( $pagename, $metaData );
! $this->_commitPage( $pagename, serialize( $metaData ) );
}
--- 232,238 ----
unset( $metaData[CMD_CONTENT] );
$metaData[CMD_LAST_MODIFIED] = time();
! $metaData[CMD_VERSION] = $this->_commitPage( $pagename, $metaData );
! $this->_writeMetaInfo( $pagename, $metaData );
}
***************
*** 234,238 ****
$metaData = $this->get_pagedata( $pagename );
if ( $metaData ) {
! // the version number is everything about the '1.'
return $metaData[CMD_VERSION];
} else {
--- 241,245 ----
$metaData = $this->get_pagedata( $pagename );
if ( $metaData ) {
! // the version number is everything after the '1.'
return $metaData[CMD_VERSION];
} else {
***************
*** 249,258 ****
/**
! * the version parameter is assumed to be everything about the '1.'
* in the CVS versioning system.
*/
function get_versiondata($pagename, $version, $want_content = false)
{
! $this->_cvsDebug( "get_versiondata: [$pagename] [$version] [$want_content]" );
$filedata = "";
--- 256,266 ----
/**
! * the version parameter is assumed to be everything after the '1.'
* in the CVS versioning system.
*/
function get_versiondata($pagename, $version, $want_content = false)
{
! $this->_cvsDebug( "get_versiondata: [$pagename] "
! . "[$version] [$want_content]" );
$filedata = "";
***************
*** 285,289 ****
// shift log data until we get to the 'revision X.X' line
// FIXME: ensure that we don't enter an endless loop here
! while ( !ereg( "^revision ([^ ]+)$", $logdata[0], $revInfo ) ) {
array_shift( $logdata );
}
--- 293,297 ----
// shift log data until we get to the 'revision X.X' line
// FIXME: ensure that we don't enter an endless loop here
! while ( !ereg( "^revision 1.([0-9]+)$", $logdata[0], $revInfo ) ) {
array_shift( $logdata );
}
***************
*** 293,297 ****
// version information is incorrect
! $rVal[CMD_VERSION] = ereg_replace( "^1[.]", "", $revInfo[1] );
$rVal[CMD_CONTENT] = $filedata;
--- 301,305 ----
// version information is incorrect
! $rVal[CMD_VERSION] = $revInfo[1];
$rVal[CMD_CONTENT] = $filedata;
***************
*** 305,309 ****
/**
* This returns false if page was not deleted or could not be deleted
! * else true is returned.
*/
function delete_page($pagename)
--- 313,317 ----
/**
* This returns false if page was not deleted or could not be deleted
! * else return true.
*/
function delete_page($pagename)
***************
*** 322,327 ****
$this->_removePage( $pagename );
- $this->_cvsDebug( "CvsRemoveOutput [$cmdRemoveOutput]" );
-
return true;
}
--- 330,333 ----
***************
*** 375,379 ****
// FIXME: this ignores the include_defaulted parameter.
return new Cvs_Backend_Array_Iterator(
! $this->_getAllFileNamesInDir( $this->_docDir ));
}
--- 381,385 ----
// FIXME: this ignores the include_defaulted parameter.
return new Cvs_Backend_Array_Iterator(
! $this->_getAllFileNamesInDir( $this->_docDir ));
}
***************
*** 382,392 ****
if ( $fullsearch ) {
return new Cvs_Backend_Full_Search_Iterator(
! $this->_getAllFileNamesInDir( $this->_docDir ),
! $search,
! $this->_docDir );
} else {
return new Cvs_Backend_Title_Search_Iterator(
! $this->_getAllFileNamesInDir( $this->_docDir ),
! $search);
}
}
--- 388,398 ----
if ( $fullsearch ) {
return new Cvs_Backend_Full_Search_Iterator(
! $this->_getAllFileNamesInDir( $this->_docDir ),
! $search,
! $this->_docDir );
} else {
return new Cvs_Backend_Title_Search_Iterator(
! $this->_getAllFileNamesInDir( $this->_docDir ),
! $search);
}
}
***************
*** 420,431 ****
}
function check()
{
}
function rebuild()
{
}
!
//
// ..-.-..-.-..-.-.. .--..-......-.--. --.-....----.....
--- 426,468 ----
}
+ /**
+ * What we do here is take a listing of the documents directory and
+ * check that each page has metadata file. If not, then a metadata
+ * file is created for the page.
+ *
+ * This can happen if rebuild() was called and someone has added
+ * files to the CVS repository not via PhpWiki. These files are
+ * added to the document directory but without any metadata files.
+ */
function check()
{
+ // TODO:
+ // TODO: test this .... i.e. add test to unit test file.
+ // TODO:
+ $page_names = $this->_getAllFileNamesInDir($this->_docDir);
+ $meta_names = $this->_getAllFileNamesInDir($this->_docDir . "/CVS");
+
+ array_walk( $meta_names, '_strip_leading_underscore' );
+ reset( $meta_names );
+ $no_meta_files = array_diff( $page_names, $meta_names );
+
+ array_walk( $no_meta_files, '_create_meta_file', $this );
+
+ return true;
}
+ /**
+ * Do an update of the CVS repository
+ */
function rebuild()
{
+ // TODO:
+ // TODO: test this .... i.e. add test to unit test file.
+ // TODO:
+ $cmdLine = sprintf( "cd %s; cvs update -d 2>&1", $this->_docDir );
+ $this->_execCommand( $cmdLine, $cmdOutput, true );
+ return true;
}
!
//
// ..-.-..-.-..-.-.. .--..-......-.--. --.-....----.....
***************
*** 434,442 ****
// ..-.-..-.-..-.-.. .--..-......-.--. --.-....----.....
//
!
function _writeMetaInfo( $pagename, $hashInfo )
{
$this->_writeFileWithPath( $this->_docDir . "/CVS/_" . $pagename,
! serialize( $hashInfo ) );
}
function _writePage( $pagename, $content )
--- 471,489 ----
// ..-.-..-.-..-.-.. .--..-......-.--. --.-....----.....
//
! function _create_meta_file( $page_name, $key, &$backend )
! {
! $backend->_cvsDebug( "Creating meta file for [$page_name]" );
! $backend->update_pagedata( $page_name, array() );
! }
!
! function _strip_leading_underscore( &$item )
! {
! $item = ereg_replace( "^_", "", $item );
! }
!
function _writeMetaInfo( $pagename, $hashInfo )
{
$this->_writeFileWithPath( $this->_docDir . "/CVS/_" . $pagename,
! serialize( $hashInfo ) );
}
function _writePage( $pagename, $content )
***************
*** 452,461 ****
$this->_execCommand( $cmdLine, $cmdRemoveOutput, true );
}
! function _commitPage( $pagename, $commitMsg = "no_message" )
{
$cmdLine = sprintf( "cd %s; cvs commit -m \"%s\" %s 2>&1",
! $this->_docDir, escapeshellcmd( $commitMsg ),
$pagename );
$this->_execCommand( $cmdLine, $cmdOutput, true );
}
function _addPage( $pagename )
--- 499,533 ----
$this->_execCommand( $cmdLine, $cmdRemoveOutput, true );
}
!
! /**
! * this returns the new version number of the file.
! */
! function _commitPage( $pagename, &$meta_data )
{
$cmdLine = sprintf( "cd %s; cvs commit -m \"%s\" %s 2>&1",
! $this->_docDir,
! escapeshellcmd( serialize( $meta_data ) ),
$pagename );
$this->_execCommand( $cmdLine, $cmdOutput, true );
+
+ $cmdOutput = implode( "\n", $cmdOutput );
+ $revInfo = array();
+ ereg( "\nnew revision: 1[.]([0-9]+); previous revision: ", $cmdOutput,
+ $revInfo );
+
+ $this->_cvsDebug( "CP: revInfo 0: $revInfo[0]" );
+ $this->_cvsDebug( "CP: $cmdOutput" );
+ if ( isset( $revInfo[1] ) ) {
+ $this->_cvsDebug( "CP: got revision information" );
+ return $revInfo[1];
+ } else {
+ ereg( "\ninitial revision: 1[.]([0-9]+)", $cmdOutput, $revInfo );
+ if ( isset( $revInfo[1] ) ) {
+ $this->_cvsDebug( "CP: is initial release" );
+ return 1;
+ }
+ $this->_cvsDebug( "CP: returning old version" );
+ return $meta_data[CMD_VERSION];
+ }
}
function _addPage( $pagename )
***************
*** 511,514 ****
--- 583,587 ----
chmod( $path, $mode );
}
+
/**
* The lord giveth, and the lord taketh.
***************
*** 521,531 ****
if (!$locked) {
! $this->_cvsError("Unable to delete file, lock was not obtained.",
! __LINE__, $filename, EM_NOTICE_ERRORS );
}
! if ( ($rVal = unlink( $filename )) == 0 ) {
! /* if successful, then do nothing */
! } else {
$this->_cvsDebug( "[$filename] --> Unlink returned [$rVal]" );
}
--- 594,603 ----
if (!$locked) {
! $this->_cvsError("Unable to delete file, "
! . "lock was not obtained.",
! __LINE__, $filename, EM_NOTICE_ERRORS );
}
! if ( ($rVal = unlink( $filename )) != 0 ) {
$this->_cvsDebug( "[$filename] --> Unlink returned [$rVal]" );
}
***************
*** 597,604 ****
exec( $cmdLine, $cmdOutput, $cmdReturnVal );
if ( $exitOnNonZero && ($cmdReturnVal != 0) ) {
- $this->_cvsError("Command failed [$cmdLine], Return value: $cmdReturnVal",
- __LINE__ );
$this->_cvsDebug( "Command failed [$cmdLine], Output: [" .
! join("\n",$cmdOutput) . "]" );
}
$this->_cvsDebug( "Done execution [" . join("\n", $cmdOutput ) . "]" );
--- 669,677 ----
exec( $cmdLine, $cmdOutput, $cmdReturnVal );
if ( $exitOnNonZero && ($cmdReturnVal != 0) ) {
$this->_cvsDebug( "Command failed [$cmdLine], Output: [" .
! join("\n",$cmdOutput) . "]" );
! $this->_cvsError("Command failed [$cmdLine], "
! . "Return value: $cmdReturnVal",
! __LINE__ );
}
$this->_cvsDebug( "Done execution [" . join("\n", $cmdOutput ) . "]" );
|