Skip to content

Commit

Permalink
Item13068: store migration: tools/bulk_copy.pl script to support clea…
Browse files Browse the repository at this point in the history
…n migration of data from one Foswiki install to another. Various fixes to borked RCS code found along the way. Added the capability to call store actions while suppressing plugin handlers. Removed never-populated CREATEINFO meta - think this was something Sven never finished
  • Loading branch information
Comment committed Nov 29, 2014
1 parent 444ea50 commit 0203b40
Show file tree
Hide file tree
Showing 7 changed files with 629 additions and 31 deletions.
10 changes: 3 additions & 7 deletions PlainFileStoreContrib/lib/Foswiki/Store/PlainFile.pm
Expand Up @@ -447,10 +447,9 @@ sub saveTopic {

# Fix TOPICINFO
my $ti = $meta->get('TOPICINFO');
$ti->{version} = $rn;
$ti->{date} = $options->{forcedate} || time;
$ti->{author} = $cUID;
$ti->{encoding} = $Foswiki::cfg{Site}{CharSet};
$ti->{version} = $rn;
$ti->{date} = $options->{forcedate} || time;
$ti->{author} = $cUID;

# Create new latest
my $latest = _latestFile($meta);
Expand Down Expand Up @@ -483,9 +482,6 @@ sub saveTopic {
newmeta => $meta
);

# Remove encoding information
delete $ti->{encoding};

return $rn;
}

Expand Down
1 change: 1 addition & 0 deletions RCSStoreContrib/lib/Foswiki/Store/VC/RcsLiteHandler.pm
Expand Up @@ -703,6 +703,7 @@ sub getRevision {
my ( $this, $version ) = @_;

return $this->SUPER::getRevision($version) unless $version;
return $this->SUPER::getRevision($version) unless $this->noCheckinPending();

$this->_ensureRead( $version, 0 );

Expand Down
7 changes: 6 additions & 1 deletion RCSStoreContrib/lib/Foswiki/Store/VC/RcsWrapHandler.pm
Expand Up @@ -245,7 +245,12 @@ sub _deleteRevision {
sub getRevision {
my ( $this, $version ) = @_;

unless ( $version && $this->revisionHistoryExists() ) {
# If there is no revision history, or if $version is not given,
# or there is a checkin pending, then consult the .txt
if ( !$this->revisionHistoryExists()
|| !$version
|| !$this->noCheckinPending() )
{

# Get the latest rev from the cache
return ( $this->SUPER::getRevision($version) );
Expand Down
3 changes: 2 additions & 1 deletion RCSStoreContrib/lib/Foswiki/Store/VC/Store.pm
Expand Up @@ -427,7 +427,8 @@ sub saveAttachment {
my $verb = ( $topicObject->hasAttachment($name) ) ? 'update' : 'insert';
my $comment = $options->{comment} || '';

$handler->addRevisionFromStream( $stream, $comment, $cUID );
$handler->addRevisionFromStream( $stream, $comment, $cUID,
$options->{forcedate} );

my $rev = $handler->getLatestRevisionID();
$this->recordChange(
Expand Down
40 changes: 23 additions & 17 deletions core/lib/Foswiki/Meta.pm
Expand Up @@ -157,19 +157,11 @@ our %VALIDATE = (
TOPICINFO => {
allow => [
qw( author version date format reprev
rev comment encoding )
rev comment )
],
_default => 1,
alias => 'info',
},
CREATEINFO => {
allow => [
qw( author version date format reprev
rev comment encoding )
],
_default => 1,
alias => 'createinfo',
},
TOPICMOVED => {
require => [qw( from to by date )],
_default => 1,
Expand Down Expand Up @@ -1911,7 +1903,7 @@ sub save {

# Semantics inherited from Cairo. See
# Foswiki:Codev.BugBeforeSaveHandlerBroken
if ( $plugins->haveHandlerFor('beforeSaveHandler') ) {
if ( !$opts{nohandlers} && $plugins->haveHandlerFor('beforeSaveHandler') ) {

# Break up the tom and write the meta into the topic text.
# Nasty compatibility requirement as some old plugins may hack the
Expand Down Expand Up @@ -1963,7 +1955,10 @@ sub save {

# Semantics inherited from TWiki. See
# TWiki:Codev.BugBeforeSaveHandlerBroken
if ( !defined $signal && $plugins->haveHandlerFor('afterSaveHandler') ) {
if ( !$opts{nohandlers}
&& !defined $signal
&& $plugins->haveHandlerFor('afterSaveHandler') )
{
my $text = Foswiki::Serialise::serialise( $this, 'Embedded' );
delete $this->{_preferences}; # Make sure handler has changed prefs
my $error = $signal ? $signal->{-text} : undef;
Expand Down Expand Up @@ -2007,6 +2002,7 @@ Save the current topic to a store location. Only works on topics.
* =savecmd= - Save command (core use only)
* =forcedate= - force the revision date to be this (core only)
* =author= - cUID of author of change (core only - default current user)
* =nohandlers= - *do not* call plugins handlers
Note that the %options are passed on verbatim from Foswiki::Func::saveTopic,
so an extension author can in fact use all these options. However those
Expand Down Expand Up @@ -2717,6 +2713,7 @@ sub getAttachmentRevisionInfo {
This may result in incorrect meta-data stored in the topic, so must
be used with care. Only has a meaning if the store implementation
stores meta-data in topics.
* =nohandlers= - *do not* call plugin handlers
Saves a new revision of the attachment, invoking plugin handlers as
appropriate. This method automatically updates the loaded rev of $this
Expand Down Expand Up @@ -2758,11 +2755,13 @@ sub attach {
name => $opts{name},
attachment => $opts{name},
stream => $opts{stream},
user => $this->{_session}->{user}, # cUID
user => $opts{author} || $this->{_session}->{user}, # cUID
comment => defined $opts{comment} ? $opts{comment} : '',
};

if ( $plugins->haveHandlerFor('beforeAttachmentSaveHandler') ) {
if ( !$opts{nohandlers}
&& $plugins->haveHandlerFor('beforeAttachmentSaveHandler') )
{

# *Deprecated* handler.

Expand Down Expand Up @@ -2810,7 +2809,9 @@ sub attach {
$attrs->{tmpFilename} = $fh->filename();
}

if ( $plugins->haveHandlerFor('beforeAttachmentSaveHandler') ) {
if ( !$opts{nohandlers}
&& $plugins->haveHandlerFor('beforeAttachmentSaveHandler') )
{
$plugins->dispatch( 'beforeAttachmentSaveHandler', $attrs,
$this->{_topic}, $this->{_web} );
}
Expand All @@ -2824,7 +2825,9 @@ sub attach {
delete $attrs->{tmpFilename};
}

if ( $plugins->haveHandlerFor('beforeUploadHandler') ) {
if ( !$opts{nohandlers}
&& $plugins->haveHandlerFor('beforeUploadHandler') )
{

# Check the stream is seekable
ASSERT(
Expand Down Expand Up @@ -2859,7 +2862,9 @@ sub attach {
$attrs->{size} = $opts{filesize} if ( defined( $opts{filesize} ) );
$attrs->{date} = defined $opts{filedate} ? $opts{filedate} : time();

if ( $plugins->haveHandlerFor('afterAttachmentSaveHandler') ) {
if ( !$opts{nohandlers}
&& $plugins->haveHandlerFor('afterAttachmentSaveHandler') )
{

# *Deprecated* handler
$plugins->dispatch( 'afterAttachmentSaveHandler', $attrs,
Expand Down Expand Up @@ -2901,7 +2906,8 @@ sub attach {
}
);

if ( $plugins->haveHandlerFor('afterUploadHandler') ) {
if ( !$opts{nohandlers} && $plugins->haveHandlerFor('afterUploadHandler') )
{
$plugins->dispatch( 'afterUploadHandler', $attrs, $this );
}
}
Expand Down
5 changes: 0 additions & 5 deletions core/lib/Foswiki/Store/Interfaces/QueryAlgorithm.pm
Expand Up @@ -291,11 +291,6 @@ sub getField {
# Ensure the revision info is populated from the store
$data->getRevisionInfo();
}
if ( $field eq 'CREATEINFO' ) {

# Ensure the revision info is populated from the store
return $this->getRev1Info($data);
}

if ( $Foswiki::Query::Node::isArrayType{$field} ) {

Expand Down

0 comments on commit 0203b40

Please sign in to comment.