Erzeuge die Vererbungen für alle Contenttypen beim Upgrade.
git-svn-id: https://svn.libreccm.org/ccm/trunk@714 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
b5bc15d2d1
commit
0f7948f18a
|
|
@ -98,10 +98,95 @@ public class CreateGenericContentTypes extends Program {
|
|||
|
||||
tc.commitTxn(); // save database additions for re-reading
|
||||
|
||||
tc.beginTxn();
|
||||
|
||||
ContentTypeCollection ctc = ContentType.getAllContentTypes();
|
||||
|
||||
s_log.debug("Starte content types update");
|
||||
|
||||
while (ctc.next()) {
|
||||
|
||||
ContentType ct = ctc.getContentType();
|
||||
|
||||
s_log.debug("Verarbeite " + ct.getClassName());
|
||||
|
||||
createPedigree(ct);
|
||||
|
||||
}
|
||||
tc.commitTxn();
|
||||
}
|
||||
}.run();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the pedigree for this content type
|
||||
* @param type The new content type
|
||||
*/
|
||||
private void createPedigree(ContentType type) {
|
||||
|
||||
// The parent content type
|
||||
ContentType parent = null;
|
||||
|
||||
// Get all content types
|
||||
ContentTypeCollection cts = ContentType.getAllContentTypes();
|
||||
|
||||
// This is a brute force method, but I can't come up with something
|
||||
// better atm without changing either all Loader or the xml-files.
|
||||
while (cts.next()) {
|
||||
ContentType ct = cts.getContentType();
|
||||
|
||||
try {
|
||||
Class.forName(type.getClassName()).asSubclass(Class.forName(ct.getClassName()));
|
||||
} catch (Exception ex) {
|
||||
// This cast is not valid so type is not a sublacss of ct
|
||||
continue;
|
||||
}
|
||||
|
||||
// Save the current ct as possible parent if we haven't found any parent yet
|
||||
// or if the current ancestor list is longer than that one from the possible
|
||||
// parent earlier found
|
||||
if (!type.getClassName().equals(ct.getClassName())
|
||||
&& (parent == null
|
||||
|| (parent.getAncestors() != null
|
||||
&& ct.getAncestors() != null
|
||||
&& parent.getAncestors().length() < ct.getAncestors().length()))) {
|
||||
parent = ct;
|
||||
}
|
||||
}
|
||||
|
||||
// If there is a valid parent content type create the pedigree
|
||||
if (parent != null && !parent.getClassName().equals(type.getClassName())) {
|
||||
if (parent.getAncestors() != null) {
|
||||
String parentAncestors = parent.getAncestors();
|
||||
|
||||
StringTokenizer strTok = new StringTokenizer(parentAncestors, "/");
|
||||
|
||||
// Add parent ancestors to this content types ancestor list
|
||||
// Also while we iterate through the list, we also need to add
|
||||
// this content type as descendant to all entries in the ancestor list
|
||||
while (strTok.hasMoreElements()) {
|
||||
BigDecimal ctID = new BigDecimal(strTok.nextToken());
|
||||
|
||||
// Get the current content type
|
||||
try {
|
||||
ContentType ct = new ContentType(ctID);
|
||||
ct.addDescendants(ctID);
|
||||
} catch (Exception ex) {
|
||||
// The db is broken. There is no content type for this ID
|
||||
}
|
||||
|
||||
// Add parent ancestor
|
||||
type.addAncestor(ctID);
|
||||
}
|
||||
}
|
||||
|
||||
// Add parent to ancestor list
|
||||
type.addAncestor(parent.getID());
|
||||
|
||||
// Add this to parent descendants
|
||||
parent.addDescendants(type.getID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue