Skip to content

Commit

Permalink
Item14848: fix invalid use of store api
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Jul 26, 2019
1 parent f7a4c82 commit 3ab689b
Show file tree
Hide file tree
Showing 36 changed files with 1,448 additions and 748 deletions.
2 changes: 1 addition & 1 deletion bin/copy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env perl
# Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2011-2017 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2011-2019 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
40 changes: 31 additions & 9 deletions data/System/CopyContrib.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="BramVanOosterhout" comment="" date="1490961236" format="1.1" version="7"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1564156088" format="1.1" version="1"}%
---+!! %TOPIC%
%FORMFIELD{"Description"}%

Expand Down Expand Up @@ -53,16 +53,22 @@ a copy agent is created to perform the actual operation. The basic skeleton for
| =minor= | True if this change is not to be notified | =off= |
| =clear= | boolean flag; when enabled data on the destination will be _deleted_ first before copying the source data; (exception: text is always cleared before copying it over); when disabled data of source and destination will be merged | =off= |
| =redirectto= | topic or url where to redirect the browser after a successful copy operation | |
| =nohandlers= | boolean flag; when enabled plugin handlers will not be called, such as =beforeSaveHander= and =afterSaveHandler= | =off= |

---+++ Mode: =topic=

| *Name* | *Description* | *Default* |
| =source= | the source topic to be copied | =%<nop>BASEWEB%.%<nop>BASETOPIC%= |
| =destination= | the destination topic where to copy =source= to | =source= |
| =dstWeb= | the destination web where to copy =source= to | =%<nop>BASEWEB%= |
| =dstTopic=, =destination= | the destination topic where to copy =source= to | =source= |
| =includepart=, =includeparts= | a list of parts of a topic to be copied; known part-ids are =text=, =attachments=, =all=, =preferences=, =parent=, =form=, =fields=, or any other custom meta data alias such as =comment= from [[Foswiki:Extensions/MetaCommentPlugin][MetaCommentPlugin]] | =all= |
| =excludepart=, =excludeparts= | a list of parts to exclude from the copy process | |
| =include&lt;part-id>= | when meta data is named as is the case for =fields= you may specify a regular expression in =includefields= that all fields must match when copying formfields | |
| =exclude&lt;part-id>= | same as =include&lt;part-id>= but in reverse logic | |
| =fromrev= | specify the starting revision to be copied over; if left undefined, will only the top revision be copied | |
| =torev= | specify the last revision to be copied over | |
| =preservetopicinfo= | boolean flag; this will try to preserve the original date and authorship of the source; note that this may not always be possible when the top revision of the target is earlier than the revision(s) to be copied over; further note, that attachments of old revisions not present in the top revision cannot be recreated on the taregt topic as they are versioned independently | |
| =trashsource= | boolean flag; this will trash the source after successfully copying it to the target; note: when only parts of the topic have been copied will the rest of it get lost! | =off= |

---+++ Mode: =topics=

Expand Down Expand Up @@ -137,6 +143,20 @@ All parameters of the [[##Mode:_61topic_61][topic mode]] apply to each topic in
<label><input type="checkbox" name="dontlog" value="off">%MAKETEXT{"Don't log changes"}%</label> %BR%
<label><input type="checkbox" name="clear" value="on">%MAKETEXT{"Clear before copying"}%</label>
</div>
<div class="foswikiFormStep">
<h3>%MAKETEXT{"Advanced Options"}%:</h3>
<table class='foswikiLayoutTable'>
<tr>
<th>%MAKETEXT{"From Version"}%</th>
<td><input type="text" name="fromrev" class="foswikiInputField" value="%REVINFO{format="$rev" rev="%URLPARAM{"rev"}%"}%" size="3" /></td>
</tr>
<tr>
<th>%MAKETEXT{"To Version"}%</th>
<td><input type="text" name="torev" class="foswikiInputField" value="%REVINFO{format="$rev" rev="%URLPARAM{"rev"}%"}%" size="3" /></td>
</tr>
</table>
<label><input type="checkbox" name="preservetopicinfo" value="on" checked />%MAKETEXT{"Preserver author and revision information"}%</label>
</div>
<div class="foswikiFormStep">
%BUTTON{"%MAKETEXT{"Submit"}%" icon="tick" type="submit"}%%CLEAR%
</div>
Expand Down Expand Up @@ -179,22 +199,24 @@ All parameters of the [[##Mode:_61topic_61][topic mode]] apply to each topic in
---++ Change History

%TABLE{columnwidths="7em" tablewidth="100%"}%
| 26 Jul 2019: | fix use of store; create a new revision when copying attachments instead of erasing anything that existed before |
| 11 Jun 2019: | added =copy= perl api; added =nohandlers= option; fixed copying attachments |
| 21 Nov 2018: | added =trashsource= to topic agent; fixed memory leaks |
| 09 Feb 2018: | added feature to restore a subset of topic revisions |
| 30 Jun 2017: | added =application= mode (by Foswiki:Main/BramVanOosterhout) |
| 25 Sep 2015: | added support for unicode foswiki |
| 10 Jun 2014: | improved error handling; make messages translatable |
| 30 May 2014: | added forcenewrevision, minor and dontlog |
| 22 Oct 2013: | initial release |

<!--
-->

%META:FORM{name="PackageForm"}%
%META:FIELD{name="Author" title="Author" value="Michael Daum"}%
%META:FIELD{name="Copyright" title="Copyright" value="&copy; 2013-2017, Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Home" title="Home" value="https://foswiki.org/Extensions/CopyContrib"}%
%META:FIELD{name="License" title="License" value="[[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]]"}%
%META:FIELD{name="Version" title="Version" value="%25$VERSION%25"}%
%META:FIELD{name="Release" title="Release" value="%25$RELEASE%25"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/CopyContrib"}%
%META:FIELD{name="Copyright" title="Copyright" value="&copy; 2013-2019, Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="License" title="License" value="[[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]]"}%
%META:FIELD{name="Home" title="Home" value="https://foswiki.org/Extensions/CopyContrib"}%
%META:FIELD{name="Support" title="Support" value="https://foswiki.org/Support/CopyContrib"}%
%META:FIELD{name="Version" title="Version" value="%25$VERSION%25"}%
38 changes: 29 additions & 9 deletions lib/Foswiki/Contrib/CopyContrib.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2013-2017 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2013-2019 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -17,12 +17,13 @@ use strict;
use warnings;

use Foswiki::Func();
use Foswiki::Plugins();
use Error qw( :try );
use Encode();
use Foswiki::OopsException ();

our $VERSION = '3.00';
our $RELEASE = '30 Jun 2017';
our $VERSION = '4.00';
our $RELEASE = '26 Jul 2019';
our $SHORTDESCRIPTION = 'Copies webs, topics, attachments, or part of them';

our %agentImpls = (
Expand All @@ -45,6 +46,25 @@ sub registerAgent {
return $prevImpl;
}

###############################################################################
sub copy {
my $mode = shift;

my $impl = $agentImpls{$mode};
throw Error::Simple("Unknown copy mode '$mode'") unless defined $impl;

eval "require $impl";
throw Error::Simple($@) if $@;

my $session = $Foswik::Plugins::SESSION;
my $agent = $impl->new($session, @_);
my @result = $agent->copy();

$agent->finish();

return @result;
}

###############################################################################
sub copyCgi {
my $session = shift;
Expand All @@ -66,13 +86,15 @@ sub copyCgi {
my $mode = $request->param("mode");
throw Error::Simple("No copy mode") unless defined $mode;

my $agent = $agentImpls{$mode};
throw Error::Simple("Unknown copy mode '$mode'") unless defined $agent;
my $impl = $agentImpls{$mode};
throw Error::Simple("Unknown copy mode '$mode'") unless defined $impl;

eval "require $agent";
eval "require $impl";
throw Error::Simple($@) if $@;

@result = $agent->new($session)->parseRequestObject($request)->copy();
my $agent = $impl->new($session);
@result = $agent->parseRequestObject($request)->copy();
$agent->finish();

} catch Error::Simple with {
my $error = shift;
Expand Down Expand Up @@ -110,8 +132,6 @@ sub copyCgi {
my $target = $session->redirectto();

if ($target) {
$msg = Foswiki::Func::renderText($msg);
$target .= (($target =~ /\?/) ? '&':'?').'_copy_result='.urlEncode($msg);
$session->redirect($target);
} else {
my @params = ("Success");
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Contrib/CopyContrib/ApplicationAgent.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2013-2017 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2013-2019 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
13 changes: 12 additions & 1 deletion lib/Foswiki/Contrib/CopyContrib/CopyAgent.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2013-2017 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2013-2019 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -36,6 +36,14 @@ sub new {
return $this;
}

###############################################################################
# optional destructor
sub finish {
my $this = shift;

undef $this->{session};
}

###############################################################################
sub writeDebug {
my $this = shift;
Expand Down Expand Up @@ -63,6 +71,9 @@ sub parseRequestObject {
$this->{forceNewRevision} = Foswiki::Func::isTrue($request->param('forcenewrevision'), 0)
unless defined $this->{forceNewRevision};

$this->{noHandlers} = Foswiki::Func::isTrue($request->param('nohandlers'), 0)
unless defined $this->{nohandlers};

$this->{dontLog} = Foswiki::Func::isTrue($request->param('dontlog'), 0)
unless defined $this->{dontLog};

Expand Down
22 changes: 22 additions & 0 deletions lib/Foswiki/Contrib/CopyContrib/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ lib/Foswiki/Contrib/CopyContrib/TopicAgent.pm 0644
lib/Foswiki/Contrib/CopyContrib/TopicListAgent.pm 0644
lib/Foswiki/Contrib/CopyContrib/TopicStubAgent.pm 0644
lib/Foswiki/Contrib/CopyContrib/WebAgent.pm 0644
locale/CopyContrib/bg.po 0644
locale/CopyContrib/cs.po 0644
locale/CopyContrib/da.po 0644
locale/CopyContrib/de.po 0644
locale/CopyContrib/el.po 0644
locale/CopyContrib/es.po 0644
locale/CopyContrib/fi.po 0644
locale/CopyContrib/Foswiki.pot 0644
locale/CopyContrib/fr.po 0644
locale/CopyContrib/it.po 0644
locale/CopyContrib/ja.po 0644
locale/CopyContrib/ko.po 0644
locale/CopyContrib/nl.po 0644
locale/CopyContrib/no.po 0644
locale/CopyContrib/pl.po 0644
locale/CopyContrib/pt-br.po 0644
locale/CopyContrib/pt.po 0644
locale/CopyContrib/ru.po 0644
locale/CopyContrib/sv.po 0644
locale/CopyContrib/tlh.po 0644
locale/CopyContrib/tr.po 0644
locale/CopyContrib/uk.po 0644
locale/CopyContrib/zh-cn.po 0644
locale/CopyContrib/zh-tw.po 0644
templates/oopscopy.tmpl 0644
Loading

0 comments on commit 3ab689b

Please sign in to comment.