From df0e09286bf4c08b41f99cad9c87f865a622fadb Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Thu, 14 Aug 2008 14:54:25 +0000 Subject: [PATCH] Change to the way we apply 'versionable' aspect by default to uploaded documents. Aspect is still applied but "autoversion" and "create initial version" features are off by default. First version is instead explicitly created during checkout process. Fix to apply 'versionable' aspect to documents that are being updated via the Share client but were initially uploaded via another route i.e. FTP or JSF Client. Minor fix to doclist json to handle documents that have 'versionable' aspect applied but do not have any version history. Code cleanup to ML document details. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10370 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/repository/upload/upload.post.js | 43 +++++++++++++++---- .../documentlibrary/action/checkout.post.js | 16 +++++++ .../documentlibrary/doclist.get.json.ftl | 2 +- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js b/config/alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js index c616f98050..b4177cfe65 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js @@ -117,33 +117,52 @@ function main() if (updateNodeRef !== null && uploadDirectory === null) { - // Update mode, since updateNodeRef was used + // Update existing file mode var workingCopy = search.findNode(updateNodeRef); if (workingCopy.isLocked) { - // It's not a working copy, should have been the working copy, throw error + // We cannot update a locked document status.code = 404; - status.message = "Cannot upload document since updateNodeRef '" + updateNodeRef + "' points to a locked document, supply a nodeRef to its working copy instead."; + status.message = "Cannot update locked document '" + updateNodeRef + "', supply a reference to its working copy instead."; status.redirect = true; return; } if (!workingCopy.hasAspect("cm:workingcopy")) { - // It's not a working copy, do a check out to get the working copy + // Ensure the original file is versionable - may have been uploaded via different route + if (!workingCopy.hasAspect("cm:versionable")) + { + // Ensure the file is versionable - but do not autoversion or create initial version yet + var props = new Array(2); + props["cm:autoVersion"] = false; + props["cm:initialVersion"] = false; + workingCopy.addAspect("cm:versionable", props); + } + + if (workingCopy.versionHistory == null) + { + // Create the first version manually so we have 1.0 before checkout + workingCopy.createVersion("", true); + } + + // It's not a working copy, do a check out to get the actual working copy workingCopy = workingCopy.checkout(); } - // Update the working copy + + // Update the working copy content workingCopy.properties.content.write(content); // Reset working copy mimetype and encoding workingCopy.properties.content.guessMimetype(filename); workingCopy.properties.content.encoding = "UTF-8"; - // check it in again, but with a version history note and as minor or major version increment + // check it in again, with supplied version history note workingCopy = workingCopy.checkin(description, majorVersion); + model.document = workingCopy; } else if (uploadDirectory !== null && updateNodeRef === null) { + // Upload file mode var destNode = container; if (uploadDirectory != "") { @@ -173,7 +192,7 @@ function main() // Upload component was configured to find a new unique name for clashing filenames var suffix = 1; var tmpFilename; - while(existingFile !== null) + while (existingFile !== null) { tmpFilename = filename.substring(0, filename.lastIndexOf(".")) + "-" + suffix + filename.substring(filename.lastIndexOf(".")); existingFile = container.childByNamePath(uploadDirectory + tmpFilename); @@ -187,15 +206,20 @@ function main() var newFile = destNode.createFile(filename); newFile.properties.contentType = contentType; newFile.properties.content.write(content); + // Reapply mimetype as upload may have been via Flash - which always sends binary mimetype newFile.properties.content.guessMimetype(filename); newFile.properties.content.encoding = "UTF-8"; newFile.properties.title = title; newFile.properties.description = description; - // Make file versionable (todo: check that this is ok depending on version store development) - newFile.addAspect("cm:versionable"); newFile.save(); + // Ensure the file is versionable - but do not autoversion or create initial version + var props = new Array(2); + props["cm:autoVersion"] = false; + props["cm:initialVersion"] = false; + newFile.addAspect("cm:versionable", props); + // Create thumbnail? if (thumbnailNames != null) { @@ -209,6 +233,7 @@ function main() } } } + model.document = newFile; } else diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action/checkout.post.js b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action/checkout.post.js index df89bc2d1d..2475c4ce12 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action/checkout.post.js +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action/checkout.post.js @@ -29,6 +29,22 @@ function runAction(p_params) return; } + // Ensure the file is versionable - but do not autoversion or create initial version + if (!assetNode.hasAspect("cm:versionable")) + { + // Do not autoversion (we perform explicit checkout) + var props = new Array(2); + props["cm:autoVersion"] = false; + props["cm:initialVersion"] = false; + assetNode.addAspect("cm:versionable", props); + } + + if (assetNode.versionHistory == null) + { + // Create the first version manually so we have 1.0 before checkout + assetNode.createVersion("", true); + } + // Checkout the asset var workingCopy = assetNode.checkout(); if (workingCopy === null) diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.json.ftl index 1f15b63e95..ceef5298fd 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.json.ftl @@ -8,7 +8,7 @@ <#list doclist.items as item> <#assign d = item.asset> <#assign version = "1.0"> - <#if d.hasAspect("cm:versionable")><#assign version = d.versionHistory?sort_by("versionLabel")?reverse[0].versionLabel> + <#if d.hasAspect("cm:versionable") && d.versionHistory?size != 0><#assign version = d.versionHistory?sort_by("versionLabel")?reverse[0].versionLabel> <#if item.owner?exists> <#assign lockedBy = (item.owner.properties.firstName + " " + item.owner.properties.lastName)?trim> <#assign lockedByUser = item.owner.properties.userName>