internal package Foswiki::Store
On this page:
- internal package Foswiki::Store
- ClassMethod new()
- ObjectMethod finish()
- StaticMethod cleanUpRevID( $rev ) → $integer
- ObjectMethod readTopic($topicObject, $version) → ($rev, $isLatest)
- ObjectMethod moveAttachment( $oldTopicObject, $oldAttachment, $newTopicObject, $newAttachment )
- ObjectMethod copyAttachment( $oldTopicObject, $oldAttachment, $newTopicObject, $newAttachment )
- ObjectMethod attachmentExists( $topicObject, $att ) → $boolean
- ObjectMethod moveTopic( $oldTopicObject, $newTopicObject, $cUID )
- ObjectMethod moveWeb( $oldWebObject, $newWebObject, $cUID )
- ObjectMethod testAttachment( $topicObject, $attachment, $test ) → $value
- ObjectMethod openAttachment( $topicObject, $attachment, $mode, %opts ) → $text
- ObjectMethod getRevisionHistory ( $topicObject [, $attachment] ) → $iterator
- ObjectMethod getNextRevision ( $topicObject ) → $revision
- ObjectMethod getRevisionDiff ( $topicObject, $rev2, $contextLines ) → \@diffArray
- ObjectMethod getVersionInfo($topicObject, $rev, $attachment) → \%info
- ObjectMethod saveAttachment( $topicObject, $attachment, $stream, $cUID ) → $revNum
- ObjectMethod saveTopic( $topicObject, $cUID, $options ) → $integer
- ObjectMethod repRev( $topicObject, $cUID, %options ) → $rev
- ObjectMethod delRev( $topicObject, $cUID ) → $rev
- ObjectMethod atomicLockInfo( $topicObject ) → ($cUID, $time)
- ObjectMethod atomicLock( $topicObject, $cUID )
- ObjectMethod atomicUnlock( $topicObject )
- ObjectMethod webExists( $web ) → $boolean
- ObjectMethod topicExists( $web, $topic ) → $boolean
- ObjectMethod getApproxRevTime ( $web, $topic ) → $epochSecs
- ObjectMethod eachChange( $web, $time ) → $iterator
- ObjectMethod eachAttachment( $topicObject ) → \$iterator
- ObjectMethod eachTopic( $webObject ) → $iterator
- ObjectMethod eachWeb($webObject, $all ) → $iterator
- ObjectMethod remove( $cUID, $om, $attachment )
- ObjectMethod query($query, $inputTopicSet, $session, \%options) → $outputTopicSet
- ObjectMethod searchInWebMetaData($query, $web, $inputTopicSet, $session, \%options) → $outputTopicSet
- ObjectMethod searchInWebContent($searchString, $web, \@topics, $session, \%options ) → \%map
- ObjectMethod getRevisionAtTime( $topicObject, $time ) → $rev
- ObjectMethod getLease( $topicObject ) → $lease
- ObjectMethod setLease( $topicObject, $length )
- ObjectMethod removeSpuriousLeases( $web )
internal package Foswiki::Store
This class is a pure virtual base class that specifies the interface
between the actual store implementation and the rest of the Foswiki
system.
Subclasses of this class (known as "store implementations") are
responsible for checking for topic existance, access permissions, and
all the other general admin tasks required of a store.
This class knows nothing about how the data is actually stored -
that knowledge is entirely encapsulated in the implementation.
The general contract for methods in the class requires that errors
are signalled using exceptions. Foswiki::AccessControlException is
used for access control exceptions, and Error::Simple for all other
types of error.
Reference implementations of this base class are Foswiki::Store::RcsWrap
and Foswiki::Store::RcsLite (these are both implemented in terms of
VC::Store, which is an abstract implementation of a store based on a
version control system).
Methods of this class and all subclasses should only be called from
Foswiki and Foswiki::Meta. All other system components must delegate
store interactions via Foswiki::Meta.
For readers who are familiar with Foswiki version 1.0.0, this class
describes the interface to the old Foswiki::Store without actually
implementing it.
Note that most methods are passed a Foswiki::Meta object. This pattern is
employed to reinforce the encapsulation of a "path" in a meta object, and
also to allow the store to modify META fields in the object, something it
would be unable to do if passed $web, $topic.
Version numbers are required to be positive, non-zero integers. When
passing in version numbers to the methods of a store implementation, 0,
undef and '' are treated as referring to the latest (most recent)
revision of the object. Version numbers are required to increase (later
version numbers are greater than earlier) but are not required to be
sequential.
ClassMethod new()
Construct a Store module.
ObjectMethod finish()
Break circular references.
StaticMethod cleanUpRevID( $rev ) → $integer
Cleans up (maps) a user-supplied revision ID and converts it to an integer
number that can be incremented to create a new revision number.
This method should be used to sanitise user-provided revision IDs.
Returns 0 if it was unable to determine a valid rev number from the
string passed.
ObjectMethod getWorkArea( $key ) → $directorypath
Gets a private directory uniquely identified by $key. The directory is
intended as a work area for plugins.
The standard is a directory named the same as "key" under
$Foswiki::cfg{WorkingDir}/work_areas
ObjectMethod readTopic($topicObject, $version) → ($rev, $isLatest)
-
$topicObject- Foswiki::Meta object -
$version- revision identifier, or undef
$version is undef, then reads the most recent version.
Returns the version identifier of the topic that was actually read. If
the topic does not exist in the store, or $version refers to a version
that does not exist, then $rev is undef. $isLatest should be set to
perl true if the version loaded (or not loaded) is the latest available
version.
ObjectMethod moveAttachment( $oldTopicObject, $oldAttachment, $newTopicObject, $newAttachment )
-
$oldTopicObject, $oldAttachment- spec of attachment to move - $newTopicObject, $newAttachment= - where to move to
ObjectMethod copyAttachment( $oldTopicObject, $oldAttachment, $newTopicObject, $newAttachment )
-
$oldTopicObject, $oldAttachment- spec of attachment to copy - $newTopicObject, $newAttachment= - where to move to
ObjectMethod attachmentExists( $topicObject, $att ) → $boolean
Determine if the attachment already exists on the given topic
ObjectMethod moveTopic( $oldTopicObject, $newTopicObject, $cUID )
All parameters must be defined and must be untainted.
ObjectMethod moveWeb( $oldWebObject, $newWebObject, $cUID )
Move a web.
ObjectMethod testAttachment( $topicObject, $attachment, $test ) → $value
Performs a type test on the given attachment file.
* $attachment - name of the attachment to test e.g lolcat.gif
* $test - the test to perform e.g. 'r'
The return value is the value that would be returned by the standard
perl file operations, as indicated by $type
* r File is readable by current user (tests Foswiki permissions)
* w File is writable by current user (tests Foswiki permissions)
* e File exists.
* z File has zero size.
* s File has nonzero size (returns size).
* T File is an ASCII text file (heuristic guess).
* B File is a "binary" file (opposite of T).
* M Last modification time (epoch seconds).
* A Last access time (epoch seconds).
Note that all these types should behave as the equivalent standard perl
operator behaves, except M and A which are independent of the script start
time (see perldoc -f -X for more information)
Other standard Perl file tests may also be supported on some store
implementations, but cannot be relied on.
Errors will be signalled by an Error::Simple exception.
ObjectMethod openAttachment( $topicObject, $attachment, $mode, %opts ) → $text
Opens a stream onto the attachment. This method is primarily to
support virtual file systems, and as such access controls are not
checked, plugin handlers are not called, and it does not update the
meta-data in the topicObject.
$mode can be '<', '>' or '>>' for read, write, and append
respectively. %
%opts can take different settings depending on $mode. -
$mode='<'-
version- revision of the object to open e.g.version => 6
-
-
$mode='>'or ='>>'- no options
Error exception.
ObjectMethod getRevisionHistory ( $topicObject [, $attachment] ) → $iterator
-
$topicObject- Foswiki::Meta for the topic -
$attachment- name of an attachment (optional)
ObjectMethod getNextRevision ( $topicObject ) → $revision
-
$topicObject- Foswiki::Meta for the topic
ObjectMethod getRevisionDiff ( $topicObject, $rev2, $contextLines ) → \@diffArray
Get difference between two versions of the same topic. The differences are
computed over the embedded store form.
Return reference to an array of differences -
$topicObject- topic, first revision loaded -
$rev2- second revision -
$contextLines- number of lines of context required
| type | Means |
|---|---|
+ |
Added |
- |
Deleted |
c |
Changed |
u |
Unchanged |
l |
Line Number |
ObjectMethod getVersionInfo($topicObject, $rev, $attachment) → \%info
Get revision info of a topic or attachment. -
$topicObjectTopic object, required -
$revrevision number. If 0, undef, or out-of-range, will get info about the most recent revision. -
$attachment(optional) attachment filename; undef for a topic
| date | in epochSec |
| user | user object |
| version | the revision number |
| comment | comment in the VC system, may or may not be the same as the comment in embedded meta-data |
ObjectMethod saveAttachment( $topicObject, $attachment, $stream, $cUID ) → $revNum
-
$topicObject- Foswiki::Meta for the topic -
$attachment- name of the attachment -
$stream- input stream delivering attachment data -
$cUID- user doing the save
$stream.
Returns the number of the revision saved.
ObjectMethod saveTopic( $topicObject, $cUID, $options ) → $integer
Save a topic or attachment without invoking plugin handlers. -
$topicObject- Foswiki::Meta for the topic -
$cUID- cUID of user doing the saving -
$options- Ref to hash of options
$options may include: -
forcenewrevision- force a new revision even if one isn't needed -
forcedate- force the revision date to be this (epoch secs) -
minor- True if this is a minor change (used in log) -
author- cUID of author of the change
ObjectMethod repRev( $topicObject, $cUID, %options ) → $rev
-
$topicObject- Foswiki::Meta topic object
-
%options- as for saveTopic, with the extra options:-
forcedate- if we want to force the deposited revision to look as much like the revision specified in$revas possible by reusing the original checkin date. -
operation- set to the name of the operation performing the save. This is used only in the log, and is normallycmdorsave. It defaults tosave.
-
ObjectMethod delRev( $topicObject, $cUID ) → $rev
-
$topicObject- Foswiki::Meta topic object -
$cUID- cUID of user doing the deleting
ObjectMethod atomicLockInfo( $topicObject ) → ($cUID, $time)
If there is a lock on the topic, return it.
ObjectMethod atomicLock( $topicObject, $cUID )
-
$topicObject- Foswiki::Meta topic object -
$cUIDcUID of user doing the locking
ObjectMethod atomicUnlock( $topicObject )
-
$topicObject- Foswiki::Meta topic object
getLease)
ObjectMethod webExists( $web ) → $boolean
Test if web exists -
$web- Web name, required, e.g.'Sandbox'
ObjectMethod topicExists( $web, $topic ) → $boolean
Test if topic exists -
$web- Web name, optional, e.g.'Main' -
$topic- Topic name, required, e.g.'TokyoOffice', or"Main.TokyoOffice"
ObjectMethod getApproxRevTime ( $web, $topic ) → $epochSecs
Get an approximate rev time for the latest rev of the topic. This method
is used to optimise searching. Needs to be as fast as possible.
ObjectMethod eachChange( $web, $time ) → $iterator
Get an iterator over the list of all the changes in the given web between
$time and now. $time is a time in seconds since 1st Jan 1970, and is not
guaranteed to return any changes that occurred before (now -
{Store}{RememberChangesFor}). Changes are returned in most-recent-first
order.
ObjectMethod eachAttachment( $topicObject ) → \$iterator
Return an iterator over the list of attachments stored for the given
topic. This will get a list of the attachments actually stored for the
topic, which may be a longer list than the list that comes from the
topic meta-data, which only lists the attachments that are normally
visible to the user.
the iterator iterates over attachment names.
ObjectMethod eachTopic( $webObject ) → $iterator
Get list of all topics in a web as an iterator
ObjectMethod eachWeb($webObject, $all ) → $iterator
Return an iterator over each subweb. If $all is set, will return a list of all
web names under $web. The iterator returns web pathnames relative to $web.
The list of web names is sorted alphabetically by full path name e.g. - AWeb
- AWeb/SubWeb
- AWeb/XWeb
- BWeb
ObjectMethod remove( $cUID, $om, $attachment )
-
$cUIDwho is doing the removing -
$om- thing being removed (web or topic) -
$attachment- optional attachment being removed
ObjectMethod query($query, $inputTopicSet, $session, \%options) → $outputTopicSet
Search for data in the store (not web based). $query must
be a Foswiki::*::Node object.
my $query = $Foswiki::Plugins::SESSION->search->parseSearch($searchString, $options);
#where $options->{type} is the type specifier as per SEARCH
- $inputTopicSet is a reference to an iterator containing a list of topic in this web, if set to undef, the search/query algo will create a new iterator using eachTopic() and the topic and excludetopics options
ObjectMethod searchInWebMetaData($query, $web, $inputTopicSet, $session, \%options) → $outputTopicSet
Search for a meta-data expression in the content of a web. $query must be a Foswiki::Query object.
Returns an Foswiki::Search::InfoCache iterator
DEPRECATED: this is the old way to search, and should not be used in new code.
instead, use query() - using the topicSet iterator interface allows optimistations
ObjectMethod searchInWebContent($searchString, $web, \@topics, $session, \%options ) → \%map
Search for a string in the content of a web. The search must be over all
content and all formatted meta-data, though the latter search type is
deprecated (use queries instead).
-
$searchString- the search string, in egrep format if regex -
$web- The web to search in -
\@topics- reference to a list of topics to search -
$session- the session object that provides the context of this search. -
\%options- reference to an options hash
\%options hash may contain the following options: -
type- ifregexwill perform a egrep-syntax RE search (default '') -
casesensitive- false to ignore case (default true) -
files_without_match- true to return files only (default false) -
wordboundaries- true to limit the ends of the match to word boundaries
files_without_match is specified, it will
return on the first match in each topic (i.e. it will return only one
match per topic, and will not return matching lines).
DEPRECATED: this is the old way to search, and should not be used in new code.
instead, use query() - using the topicSet iterator interface allows optimistations
ObjectMethod getRevisionAtTime( $topicObject, $time ) → $rev
-
$topicObject- topic -
$time- time (in epoch secs) for the rev
ObjectMethod getLease( $topicObject ) → $lease
-
$topicObject- topic
user, taken and expires).
Leases are taken out when a topic is edited. Only one lease
can be active on a topic at a time. Leases are used to warn if
another user is already editing a topic.
ObjectMethod setLease( $topicObject, $length )
-
$topicObject- Foswiki::Meta topic object
getLease for more details about Leases.
ObjectMethod removeSpuriousLeases( $web )
Remove leases that are not related to a topic. These can get left behind in
some store implementations when a topic is created, but never saved.
History: r1 - 19 Apr 2011 - 03:38:03 - ProjectContributor