Skip to content

Commit

Permalink
Ability to enter cost as a string xwikisas#6
Browse files Browse the repository at this point in the history
* create migration files MigrationMacros with the link to 1.14
* file 1.14 retrieves idea's object with old property _nbestimate_, converts into string and saves as new property _cost_
* update Translations due to new prefixes for the migration process
  • Loading branch information
Nikita Petrenko committed Oct 21, 2022
1 parent a7ac048 commit cf4a4bf
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,18 @@ rendering.macro.ideasrecent.parameter.limit.description=Number of maximum entrie

# Template Provider
templateProvider.idea.name=Idea
templateProvider.idea.description=Share an idea</content>
templateProvider.idea.description=Share an idea

# Migrations
ideas.home.migrations=Some properties have been changed since your last upgrade. Please follow the next link/s to complete the migration:
ideas.migrations.programming=You need programming rights for executing the migration. More informations [[here&gt;&gt;{0}]]:
ideas.migrations.wiki=Wiki:
ideas.migrations.number=Number of documents to be modified:
ideas.migrations.document=Document
ideas.migrations.status=Status
ideas.migrations.properties=Properties to be updated after executing
ideas.migrations.deprecatedProps=No deprecated properties
ideas.migrations.button=Execute the modification</content>
<object>
<name>Ideas.IdeasTranslations</name>
<number>0</number>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?xml version="1.1" encoding="UTF-8"?>

<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<xwikidoc version="1.3" reference="Ideas.Migrations.1\.14.WebHome" locale="">
<web>Ideas.Migrations.1\.14</web>
<name>WebHome</name>
<language/>
<defaultLanguage/>
<translation>0</translation>
<creator>xwiki:XWiki.Admin</creator>
<parent>Ideas.Migrations.WebHome</parent>
<author>xwiki:XWiki.Admin</author>
<contentAuthor>xwiki:XWiki.Admin</contentAuthor>
<version>1.1</version>
<title>1.14</title>
<comment/>
<minorEdit>false</minorEdit>
<syntaxId>xwiki/2.1</syntaxId>
<hidden>false</hidden>
<content>{{velocity}}
{{info}}This migrator moves the number value from the **nbestimate** property of Ideas class, converts into string value, and stores into **cost** property.{{/info}}

#macro (handleWiki $w)
#set ($ideasClass = 'Ideas.IdeasClass')
#set ($ideasClassDoc = $xwiki.getDocument("${w}:$ideasClass"))
#set ($wikiPrettyName = $services.wiki.getById($w).prettyName)
#if ("$!wikiPrettyName.trim()" == '')
#set ($wikiPrettyName = $w)
#end
#if ($ideasClassDoc)
#set ($ideas = $services.query.xwql("from doc.object($ideasClass) as ideas order by doc.fullName asc").setWiki($w).addFilter('unique').execute())
$services.localization.render('ideas.migrations.wiki') $wikiPrettyName
$services.localization.render('ideas.migrations.number') $ideas.size()

## Table header
|=$services.localization.render('ideas.migrations.document')##
|=$services.localization.render('ideas.migrations.status')##
|=$services.localization.render('ideas.migrations.properties')
#foreach ($md in $ideas)
#set ($mDocRef = $services.model.resolveDocument($md, $services.model.createWikiReference($w)))
#set ($mDoc = $xwiki.getDocument($mDocRef))
#set ($ideasObj = $mDoc.getObject($ideasClass))
#set ($nbestimate = $ideasObj.getProperty('nbestimate').value)
#set ($saved = $NULL)
#if($nbestimate)
#set($stringCost = "$nbestimate")
## Save the idea's cost value after converting to the string.
#set ($saved = 'Would be saved on actual run')
#if ("$!request.confirm" == 'true')
#set($discard = $ideasObj.set('cost', $stringCost))
#set ($discard = $mDoc.save('Move the idea''s estimatecost converted value to the cost'))
#set ($saved = 'Saved')
#end
#end
## Clean the deprecated properties, if there are any
#set ($documentToClean = $xwiki.xWiki.getDocument($mDocRef, $xcontext.context))
#set ($deprecatedBaseObject = $documentToClean.getObject($ideasClass))
#set ($needsSave = false)
#foreach ($baseProp in $deprecatedBaseObject.getXClass($xcontext.context).getDeprecatedObjectProperties($deprecatedBaseObject))
#if ($baseProp.name == 'nbestimate')
#set ($cleanedProps = $baseProp.name)
#if ("$!request.confirm" == 'true')
#set ($discard = $deprecatedBaseObject.removeField($baseProp.name))
#set ($needsSave = true)
#end
#end
#end
#if ("$!request.confirm" == 'true' &amp;&amp; $needsSave)
## Set the new author
#set ($discard = $documentToClean.setAuthorReference($xcontext.context.userReference))
#set ($discard = $xwiki.xWiki.saveDocument($documentToClean,
$services.localization.render('core.model.xobject.synchronizeObjects.versionSummary'), true, $xcontext.context))
#end
|[[$mDoc.prefixedFullName]]|$!saved|$cleanedProps
#end

#end
#end

#if ("$!request.confirm" != 'true')
{{html}}
&lt;a href="$doc.getURL('view', 'confirm=true')" class='button'&gt;
$services.localization.render('ideas.migrations.button')
&lt;/a&gt;
{{/html}}
#end

#set ($wiki = "$!request.wiki")
#if ($wiki != '')
#handleWiki($wiki)
#else
#foreach ($wiki in $services.wiki.getAllIds())
#handleWiki($wiki)
#end
#end
{{/velocity}}</content>
</xwikidoc>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.1" encoding="UTF-8"?>

<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<xwikidoc version="1.3" reference="Ideas.Migrations.MigrationMacros.WebHome" locale="">
<web>Ideas.Migrations.MigrationMacros</web>
<name>WebHome</name>
<language/>
<defaultLanguage/>
<translation>0</translation>
<creator>xwiki:XWiki.Admin</creator>
<parent>Ideas.Migrations.WebHome</parent>
<author>xwiki:XWiki.Admin</author>
<contentAuthor>xwiki:XWiki.Admin</contentAuthor>
<version>1.1</version>
<title>MigrationMacros</title>
<comment/>
<minorEdit>false</minorEdit>
<syntaxId>xwiki/2.1</syntaxId>
<hidden>false</hidden>
<content>{{velocity}}
#macro (testMigrationNeeded)
#set($query = "from doc.object(Ideas.IdeasClass) as idea")
#set($ideas = $services.query.xwql($query).execute())
#set($migrationNeeded = false)
#foreach($idea in $ideas)
#set($ideaDoc = $xwiki.getDocument($idea))
#set($ideaObj = $ideaDoc.getObject('Ideas.IdeasClass'))
#set($nbestimate = $ideaObj.getValue('nbestimate'))
## Check which migration should be executed.
#if ("$!nbestimate" != '')
#set($migrationNeeded = true)
#set($migrationFileAccess = true)
#end
#end
#if($migrationNeeded)
{{error}}
$services.localization.render('ideas.home.migrations')
#if(!$hasProgramming)
$services.localization.render('ideas.migrations.programming',
'https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Access%20Rights/Permission%20types/#HProgrammingRight')
#else
#if($migrationFileAccess)
[[Ideas.Migrations.1\.14]]
#end
#end
{{/error}}
#end
#end
#if($hasAdmin)
#testMigrationNeeded()
#end
{{/velocity}}</content>
</xwikidoc>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.1" encoding="UTF-8"?>

<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<xwikidoc version="1.3" reference="Ideas.Migrations.WebHome" locale="">
<web>Ideas.Migrations</web>
<name>WebHome</name>
<language/>
<defaultLanguage/>
<translation>0</translation>
<creator>xwiki:XWiki.Admin</creator>
<parent>Ideas.WebHome</parent>
<author>xwiki:XWiki.Admin</author>
<contentAuthor>xwiki:XWiki.Admin</contentAuthor>
<version>1.1</version>
<title>Migrations</title>
<comment/>
<minorEdit>false</minorEdit>
<syntaxId>xwiki/2.1</syntaxId>
<hidden>false</hidden>
<content/>
</xwikidoc>

0 comments on commit cf4a4bf

Please sign in to comment.