Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a script to translate existing imported confluence data into th…
…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
Showing
6 changed files
with
123 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} --------------------- | ||
<> | ||
""" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |