Search the FirstSpirit Knowledge Base
Hi!
Is there any script or part of scripts that let me iterate over the sitestore to find an known attribute?
I would like to search for parameters used in a database query. As a result I need a list of all pages that use this parameter.
Best regards,
Torsten Kühl
Hi,
i would prefer to use the reference graph information to avoid iteration over the sitestore.
import de.espirit.firstspirit.access.store.Store;
import de.espirit.firstspirit.access.store.sitestore.PageRef;
import de.espirit.firstspirit.access.store.templatestore.Query;
import de.espirit.firstspirit.access.ReferenceEntry;
// UID of the query
QUERY_UID = "Products.products_1";
templateStore = context.getUserService().getStore(Store.Type.TEMPLATESTORE, false);
query = templateStore.getStoreElement(QUERY_UID, Query.UID_TYPE);
if (query == null) {
context.logError("query not found");
return;
}
// find all objects using the query
incomingRefs = query.getIncomingReferences();
for (ref : incomingRefs) {
// is it a sitestore reference
if (ref.isType(ReferenceEntry.SITE_STORE_REFERENCE)) {
element = ref.getReferencedElement();
if (element != null && element instanceof PageRef) {
cParams = element.getContent2Params();
if (cParams != null) {
catParam = cParams.getFilterParams().get("category");
if (catParam != null && catParam.equals(1088)) {
context.logInfo("pageref found - " + element.getUid() + "(ID=" + element.getId() + ")");
}
}
}
}
}
Hi,
i would prefer to use the reference graph information to avoid iteration over the sitestore.
import de.espirit.firstspirit.access.store.Store;
import de.espirit.firstspirit.access.store.sitestore.PageRef;
import de.espirit.firstspirit.access.store.templatestore.Query;
import de.espirit.firstspirit.access.ReferenceEntry;
// UID of the query
QUERY_UID = "Products.products_1";
templateStore = context.getUserService().getStore(Store.Type.TEMPLATESTORE, false);
query = templateStore.getStoreElement(QUERY_UID, Query.UID_TYPE);
if (query == null) {
context.logError("query not found");
return;
}
// find all objects using the query
incomingRefs = query.getIncomingReferences();
for (ref : incomingRefs) {
// is it a sitestore reference
if (ref.isType(ReferenceEntry.SITE_STORE_REFERENCE)) {
element = ref.getReferencedElement();
if (element != null && element instanceof PageRef) {
cParams = element.getContent2Params();
if (cParams != null) {
catParam = cParams.getFilterParams().get("category");
if (catParam != null && catParam.equals(1088)) {
context.logInfo("pageref found - " + element.getUid() + "(ID=" + element.getId() + ")");
}
}
}
}
}
Hi!
Can you explain, why you filter for some catParam that equals 1088? Or is it just an example?
Torsten
Hi,
this is just a simple example for the following specification of your first posting
I would like to search for parameters used in a database query.