| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.web; |
| 21 |
|
|
| 22 |
|
import org.apache.commons.lang3.StringUtils; |
| 23 |
|
import org.suigeneris.jrcs.rcs.Version; |
| 24 |
|
|
| 25 |
|
import com.xpn.xwiki.XWikiContext; |
| 26 |
|
import com.xpn.xwiki.XWikiException; |
| 27 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 28 |
|
import com.xpn.xwiki.doc.XWikiDocumentArchive; |
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
@version |
| 34 |
|
|
| |
|
| 66.2% |
Uncovered Elements: 24 (71) |
Complexity: 17 |
Complexity Density: 0.35 |
|
| 35 |
|
public class DeleteVersionsAction extends XWikiAction |
| 36 |
|
{ |
| |
|
| 74.4% |
Uncovered Elements: 10 (39) |
Complexity: 9 |
Complexity Density: 0.31 |
|
| 37 |
2 |
@Override... |
| 38 |
|
public boolean action(XWikiContext context) throws XWikiException |
| 39 |
|
{ |
| 40 |
2 |
DeleteVersionsForm form = (DeleteVersionsForm) context.getForm(); |
| 41 |
2 |
if (!form.isConfirmed() || !csrfTokenCheck(context)) { |
| 42 |
0 |
return true; |
| 43 |
|
} |
| 44 |
|
|
| 45 |
2 |
XWikiDocument doc = context.getDoc(); |
| 46 |
2 |
String language = form.getLanguage(); |
| 47 |
2 |
XWikiDocument tdoc = doc.getTranslatedDocument(language, context); |
| 48 |
2 |
XWikiDocumentArchive archive = tdoc.getDocumentArchive(context); |
| 49 |
|
|
| 50 |
|
|
| 51 |
2 |
Version[] versions = getVersionsFromForm(form, archive); |
| 52 |
2 |
Version v1 = versions[0]; |
| 53 |
2 |
Version v2 = versions[1]; |
| 54 |
|
|
| 55 |
2 |
if (v1 != null && v2 != null) { |
| 56 |
|
|
| 57 |
2 |
archive.removeVersions(v1, v2, context); |
| 58 |
2 |
context.getWiki().getVersioningStore().saveXWikiDocArchive(archive, true, context); |
| 59 |
2 |
tdoc.setDocumentArchive(archive); |
| 60 |
|
|
| 61 |
|
|
| 62 |
2 |
if (archive.getLatestVersion() == null) { |
| 63 |
0 |
if (StringUtils.isEmpty(language) || language.equals(doc.getDefaultLanguage())) { |
| 64 |
0 |
context.getWiki().deleteAllDocuments(doc, context); |
| 65 |
|
} else { |
| 66 |
|
|
| 67 |
0 |
context.getWiki().deleteDocument(tdoc, context); |
| 68 |
|
} |
| 69 |
|
} else { |
| 70 |
|
|
| 71 |
|
|
| 72 |
2 |
if (!tdoc.getRCSVersion().equals(archive.getLatestVersion())) { |
| 73 |
2 |
XWikiDocument newdoc = archive.loadDocument(archive.getLatestVersion(), context); |
| 74 |
|
|
| 75 |
|
|
| 76 |
2 |
newdoc.setDocumentReference(tdoc.getDocumentReference()); |
| 77 |
|
|
| 78 |
|
|
| 79 |
2 |
newdoc.addXObjectsToRemoveFromVersion(tdoc); |
| 80 |
|
|
| 81 |
|
|
| 82 |
2 |
newdoc.setMetaDataDirty(false); |
| 83 |
2 |
newdoc.setContentDirty(false); |
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
2 |
newdoc.setOriginalDocument(tdoc.getOriginalDocument()); |
| 88 |
|
|
| 89 |
|
|
| 90 |
2 |
context.getWiki().saveDocument(newdoc, newdoc.getComment(), context); |
| 91 |
2 |
context.setDoc(newdoc); |
| 92 |
|
} |
| 93 |
|
} |
| 94 |
|
} |
| 95 |
2 |
sendRedirect(context); |
| 96 |
2 |
return false; |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
|
| 100 |
|
@param@link |
| 101 |
|
@param |
| 102 |
|
@return |
| 103 |
|
|
| 104 |
|
|
| |
|
| 52% |
Uncovered Elements: 12 (25) |
Complexity: 6 |
Complexity Density: 0.35 |
|
| 105 |
2 |
private Version[] getVersionsFromForm(DeleteVersionsForm form, XWikiDocumentArchive archive)... |
| 106 |
|
{ |
| 107 |
|
|
| 108 |
2 |
String[] versions = new String[2]; |
| 109 |
2 |
if (form.getRev() == null) { |
| 110 |
2 |
versions[0] = form.getRev1(); |
| 111 |
2 |
versions[1] = form.getRev2(); |
| 112 |
|
} else { |
| 113 |
0 |
versions[0] = form.getRev(); |
| 114 |
0 |
versions[1] = form.getRev(); |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
|
| 118 |
2 |
Version[] result = new Version[2]; |
| 119 |
6 |
for (int i = 0; i < versions.length; i++) { |
| 120 |
|
|
| 121 |
4 |
if ("latest".equals(versions[i])) { |
| 122 |
4 |
result[i] = archive.getLatestVersion(); |
| 123 |
0 |
} else if ("previous".equals(versions[i])) { |
| 124 |
0 |
Version currentVersion = archive.getLatestVersion(); |
| 125 |
0 |
result[i] = archive.getPrevVersion(currentVersion); |
| 126 |
|
} else { |
| 127 |
|
|
| 128 |
0 |
try { |
| 129 |
0 |
result[i] = new Version(versions[i]); |
| 130 |
|
} catch (Exception e) { |
| 131 |
|
|
| 132 |
0 |
result[i] = null; |
| 133 |
|
} |
| 134 |
|
} |
| 135 |
|
} |
| 136 |
|
|
| 137 |
2 |
return result; |
| 138 |
|
} |
| 139 |
|
|
| 140 |
|
|
| 141 |
|
|
| 142 |
|
|
| 143 |
|
@param |
| 144 |
|
@throws |
| 145 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 146 |
2 |
private void sendRedirect(XWikiContext context) throws XWikiException... |
| 147 |
|
{ |
| 148 |
|
|
| 149 |
2 |
String redirect = Utils.getRedirect("view", "viewer=history", context); |
| 150 |
2 |
sendRedirect(context.getResponse(), redirect); |
| 151 |
|
} |
| 152 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 153 |
0 |
@Override... |
| 154 |
|
public String render(XWikiContext context) throws XWikiException |
| 155 |
|
{ |
| 156 |
0 |
return "deleteversionsconfirm"; |
| 157 |
|
} |
| 158 |
|
} |