General Actions:
Log-in
Register
Wiki:
games
▼
:
Document Index
»
Space:
Admin
▼
:
Document Index
»
Page:
CheckIndexes
Search
en
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
WebHome
»
XWiki and MySQL Configuration Check
»
XWiki Database Indexes Check
Wiki source code of
XWiki Database Indexes Check
Last modified by
Administrator
on 2010/09/22 19:13
Content
·
Comments
(0)
·
Annotations
(0)
·
Attachments
(0)
·
History
·
Information
Hide line numbers
1: {{groovy}} 2: def context2 = context.getContext(); 3: def store = xwiki.getXWiki().getStore().getStore(); 4: def wikilist = xwiki.isVirtual() ? xwiki.wikimanager.getAllWikis() : [ "xwiki" ]; 5: def indexes = xwiki.getDocument("Admin.CheckIndexesSQL").getContent().split("n") 6: 7: if (!wikilist.contains("xwiki")) 8: wikilist.add(0, "xwiki") 9: def creationNeeded = false; 10: for(wiki in wikilist) { 11: creationNeededForThisWiki = false; 12: try { 13: store.beginTransaction(context2); 14: def session = store.getSession(context2); 15: def connection = session.connection(); 16: def stmt = connection.createStatement(); 17: stmt.execute("show indexes from {{velocity filter="none"}} 18: ${wiki}.xwikiattrecyclebin where column_name='xda_deleter'"); 19: def rset = stmt.getResultSet(); 20: def result = null; 21: try { 22: rset.first(); 23: result = rset.getObject(1); 24: } catch (Exception e2) {} 25: if (result!=null && result.equals("xwikiattrecyclebin")) { 26: println "* Indexes created for wiki ${wiki}" 27: } else { 28: println "* <font color='red'>Indexes not created for wiki ${wiki}</font>" 29: creationNeeded = true; 30: creationNeededForThisWiki = true; 31: } 32: stmt.close(); 33: } catch (Exception e) { 34: println "* <font color='red'>Failed to check indexes for wiki ${wiki}</font>: " + e.getMessage() 35: } finally { 36: store.endTransaction(context2, false); 37: } 38: if (creationNeededForThisWiki && request.confirm=="1") { 39: try { 40: println "* Indexes will be created for wiki ${wiki}" 41: store.beginTransaction(context2); 42: def session = store.getSession(context2); 43: def connection = session.connection(); 44: connection.setCatalog(wiki.toString()); 45: for (sql in indexes) { 46: println "* Running sql: ${sql}"; 47: def stmt = connection.createStatement(); 48: try { 49: stmt.execute(sql.replaceAll(";", "")); 50: stmt.close(); 51: } catch (Exception e2) { 52: println "* Error running sql: ${sql} " + e2.getMessage(); 53: } finally { 54: stmt.close(); 55: } 56: } 57: } catch (Exception e) { 58: println "* <font color='red'>Error creating indexes for wiki ${wiki}: </font>" + e.getMessage(); 59: } finally { 60: store.endTransaction(context2, false); 61: } 62: } 63: 64: } 65: 66: if (creationNeeded && request.confirm!="1") { 67: println "[Confirm creation of indexes>$doc.fullName 68: {{/velocity}}?confirm=1]" 69: } 70: {{/groovy}}