Skip to content

Commit

Permalink
Added a script to translate existing imported confluence data into th…
Browse files Browse the repository at this point in the history
…e new plugin model. Modified the views a bit to account.

Also added migration for model change to comment.

git-svn-id: https://svn.codehaus.org/grails/trunk@8470 1cfb16fd-6d17-0410-8ff1-b7e8e1e2867d
  • Loading branch information
rhyolight committed Feb 9, 2009
1 parent 630430d commit c8eab40
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 43 deletions.
4 changes: 4 additions & 0 deletions README.txt
Expand Up @@ -40,6 +40,10 @@ Once this is done CTRL-C or quit the application and import the data from Conflu

grails import-confluence-xml ./data/confluence/entities.xml

If you want to translate the Plugin Wiki pages into the new Plugin model, run this script

grails translate-content-to-plugins

With this done you can now run-app

grails run-app
Expand Down
14 changes: 10 additions & 4 deletions grails-app/domain/org/grails/comment/Comment.groovy
@@ -1,16 +1,22 @@
package org.grails.comment

import org.grails.content.Content
import org.grails.auth.User

class Comment {
String poster
User user
String body
String email
Content parent

static constraints = {
poster(blank:false)
email(email:true, nullable:true)
body(blank:false)
}

String toString() {
"""+--- COMMENT: ---------------------
$body
+--- ${user.login} ---------------------
<>
"""
}
}
14 changes: 11 additions & 3 deletions grails-app/domain/org/grails/plugin/Plugin.groovy
Expand Up @@ -13,8 +13,8 @@ class Plugin extends WikiPage {
String author
String authorEmail
String screenshots
String grailsVersion // version it was developed against
Boolean official // specifies SpringSource support
String grailsVersion // version it was developed against
Boolean official = false // specifies SpringSource support
Number avgRating

static hasMany = [tags:Tag, ratings:Rating]
Expand All @@ -29,7 +29,7 @@ class Plugin extends WikiPage {
screenshots(nullable: true)
author(nullable: true)
authorEmail(email:true, blank:false)
grailsVersion(nullable:false, blank:false, maxLength:16)
grailsVersion(nullable:true, blank:false, maxLength:16)
}

Version createVersion() {
Expand All @@ -53,4 +53,12 @@ class Plugin extends WikiPage {
this.@description = desc
this.body = desc
}

String toString() {
"""$title
-------------------------
$description
-------------------------
AUTHOR: $author ($authorEmail)"""
}
}
14 changes: 14 additions & 0 deletions grails-app/migrations/r2.6/2009-02-09.xml
Expand Up @@ -13,4 +13,18 @@
</addColumn>
</changeSet>

<!--
Adding removing poster/email strings in place of a reference to the User domain
-->
<changeSet author="rhyolight" id="2009-02-09:2">
<dropColumn tableName="comment" columnName="poster"/>
<dropColumn tableName="comment" columnName="email"/>
<addColumn tableName="comment">
<column name="user_id" type="BIGINT(20)"/>
</addColumn>
<addForeignKeyConstraint constraintName="fk_comment_user"
baseTableName="comment" baseColumnNames="user_id"
referencedTableName="user" referencedColumnNames="id"
/>
</changeSet>
</databaseChangeLog>
41 changes: 5 additions & 36 deletions grails-app/views/plugin/listPlugins.gsp
Expand Up @@ -13,42 +13,11 @@
<g:if test="${flash.message}">
<div class="message">${flash.message}</div>
</g:if>
<div class="list">
<table>
<thead>
<tr>
<g:sortableColumn property="id" title="Id"/>
<g:sortableColumn property="title" title="Title"/>
<g:sortableColumn property="body" title="Body"/>
<g:sortableColumn property="description" title="Description"/>
<g:sortableColumn property="installation" title="Installation"/>
<g:sortableColumn property="faq" title="Faq"/>
</tr>
</thead>
<tbody>
<g:each in="${plugins}" status="i" var="plugin">
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">

<td><g:link action="show" id="${plugin.id}">${fieldValue(bean: plugin, field: 'id')}</g:link></td>

<td>${fieldValue(bean: plugin, field: 'title')}</td>

<td>${fieldValue(bean: plugin, field: 'body')}</td>

<td>${fieldValue(bean: plugin, field: 'description')}</td>

<td>${fieldValue(bean: plugin, field: 'installation')}</td>

<td>${fieldValue(bean: plugin, field: 'faq')}</td>

</tr>
</g:each>
</tbody>
</table>
</div>
<div class="paginateButtons">
<g:paginate total="${totalPlugins}"/>
</div>
<ul>
<g:each var="plugin" in="${plugins}">
<li><g:link action="show" id="${plugin.id}">${plugin.title}</g:link></li>
</g:each>
</ul>
</div>
</body>
</html>
79 changes: 79 additions & 0 deletions scripts/TransferContentToPlugins.groovy
@@ -0,0 +1,79 @@
import org.springframework.orm.hibernate3.SessionHolder
import org.springframework.orm.hibernate3.SessionFactoryUtils
import org.springframework.transaction.support.TransactionSynchronizationManager

grailsHome = Ant.project.properties."environment.GRAILS_HOME"

includeTargets << new File("${grailsHome}/scripts/Bootstrap.groovy")

target('default': "Translates all Context objects that represent Plugins into Plugin objects") {
packageApp()
classLoader = new URLClassLoader([classesDir.toURL()] as URL[], rootLoader)
Thread.currentThread().setContextClassLoader(classLoader)
loadApp()
configureApp()

sessionFactory = grailsApp.mainContext.getBean("sessionFactory")
session = SessionFactoryUtils.getSession(sessionFactory, true)
TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session))

translateContextToPlugin()
}

target(translateContextToPlugin: "The implementation task") {

def wikiClass = grailsApp.getDomainClass("org.grails.wiki.WikiPage").clazz

def id = wikiClass.executeQuery("select max(w.id) from WikiPage w where w.title = 'Plugins'")[0]

def pluginList = wikiClass.get(id)

matcher = pluginList.body =~ /\* \[([^\[\]]*)\]/ // matches "* [Plugin name]"

println "Found ${matcher.size()} plugins within wiki pages... processing..."
matcher.each {match ->
def title = match[1].split(/\|/)[0]
def pluginContent = wikiClass.findByTitle(title)

if (!pluginContent) {
def url = match[1].split(/\|/)[1]
pluginContent = wikiClass.findByTitle(url)
}

if (!pluginContent) {
println "X: ${title} has no docs on grails.org, see: ${match[1].split(/\|/)[1]}"

} else {
contentToPlugin pluginContent
}
}
}

private contentToPlugin(c) {
println "--> Translating $c.title to plugin..."
def p = grailsApp.getDomainClass("org.grails.plugin.Plugin").clazz.newInstance()
def authors = c.versions*.author
def author = (authors as Set).inject(null) {mostEdited, it ->
if (!mostEdited) return it
if (mostEdited < authors.count(it)) return it
mostEdited
}

p.title = c.title
p.description = c.body
p.author = author.login
p.authorEmail = author.email

if (!p.validate()) {
p.errors.allErrors.each { println it }
}
assert p.save()

def comment = grailsApp.getDomainClass("org.grails.comment.Comment").clazz.newInstance()
comment.user = grailsApp.getDomainClass("org.grails.auth.User").clazz.findByLogin('admin')
comment.body = "This Plugin page was automatically generated. To see the old Wiki version, go to [${p.title}]. This will only be available for a limited time in order for plugin authors to make adjustments during this transition."
comment.parent = p
assert comment.save()
p.comments = [comment]
assert p.save()
}

0 comments on commit c8eab40

Please sign in to comment.