tkuehl
I'm new here

Script to iterate over sitestore

Jump to solution

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

1 Solution

Accepted Solutions
gockel
Crownpeak employee

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() + ")");
                }
            }
        }
    }
}

View solution in original post

3 Replies
gockel
Crownpeak employee

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

0 Kudos
gockel
Crownpeak employee

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.