Aller au contenu principal

Edit content page with API

Commentaires

17 commentaires

  • Zendesk API User
    Author: Peter_Jodeleit - 11/16/2023 16:15

    The page element is from the release store, which is read-only. Only elements from the current store can be edited.

    0
  • Zendesk API User
    Author: dakaspbe - 11/17/2023 11:46

    Hi,

    thanks for the quick answer. How can I select the element of the correct current store?

    Currently my workflow is as follows:

    1. First find a specific template:

    StoreElementAgent sea = context.requireSpecialist(StoreElementAgent.TYPE);
    template = sea.loadStoreElement(TEMPLATE_UID, SectionTemplate.UID_TYPE, false);

    2. Find all usages of this template:

    template.getIncomingReferences()

    3. select the parent-page for each reference

    section = ref.getReferencedElement();
    page = section.getParent().getParent();

     

    Unfortunately these pages are always in the release store (page.isInReleaseStore() returns true).

    How can I edit the pages? What am I doing wrong?

    Kind regards

    Bernadette

    0
  • Zendesk API User
    Author: mbergmann - 11/17/2023 15:15

    Hi,

    the „isInReleaseStore()“ does not tell if the element is FROM the release store but (just) if that node (also) exists there. AFAIR It will only return false for never released elements.

    It should help to check the ReferenceEntry itself whether it points to an element from the releaseStore and ignore those:

    ref.getRelease()

    Michael

    0
  • Zendesk API User
    Author: dakaspbe - 12/13/2023 6:35

    Hi Michael,

    thanks for the hint. Unfortunately the error just changed.

    Now I see the following Exception in the fs-server.log:

    ERROR 13.12.2023 07:13:52.501 {uID=0,g-node=2412686,seID=2417967,pID=2312121,g-sec=2412681} (de.espirit.firstspirit.generate.SiteProduction): could not change page due to java.lang.SecurityException: read only store
    inside of: Template 'Produkt Seite' (id=2312649)
    inside of: $CMS_TRIM(level:2)$ - at 3, 1
    inside of: $CMS_IF( #global.page.body("content").childCount > 0 )$ - at 22, 3
    inside of: $CMS_FOR( for_section, #global.page.body("content").children )$ - at 23, 4
    inside of: $CMS_VALUE(for_section)$ - at 28, 6
    inside of: Template 'Grid Container' (id=2312652)
    inside of: $CMS_VALUE(st_elements)$ - at 3, 3
    inside of: Template 'Column' (id=2312653)
    inside of: $CMS_VALUE(st_cards)$ - at 15, 2
    inside of: Template 'Card' (id=2312654)
    inside of: $CMS_TRIM(level:3)$ - at 32, 1
    inside of: $CMS_VALUE(st_content)$ - at 60, 31
    inside of: Template 'Accordion' (id=2312660)
    inside of: $CMS_VALUE(st_content)$ - at 22, 3
    inside of: Template 'Card Text' (id=2312655)
    inside of: $CMS_VALUE(st_content)$ - at 1, 1
    inside of: Format Template 'unformatted_text' (id=2412496)
    inside of: $CMS_VALUE(#content)$ - at 1, 41
    inside of: Link Template 'bnp_default_link' (id=2412511)
    inside of: $CMS_TRIM(level:2)$ - at 1, 1
    inside of: $CMS_IF( ("internal".equals(lt_type.value) && ! lt_ref.isEmpty) || ("external".equals(lt_type.value) && ! lt_url.isEmpty) || ("mail".equals(lt_type.value) && ! lt_mail.isEmpty) )$ - at 9, 2
    inside of: $CMS_SWITCH( lt_type.value )$ - at 15, 3
    inside of: $CMS_IF( if(isSet(lt_use_disclaimer), lt_use_disclaimer, false) )$ - at 29, 6
    inside of: $CMS_RENDER(script:"add_host_to_whitelist", extUrl:lt_url)$ - at 30, 7
    inside of: Script 'add_host_to_whitelist' (id=2430683) - at 0, 0

     

    Here's the used code:

    StoreElementAgent sea = context.requireSpecialist(StoreElementAgent.TYPE);
     
    template = sea.loadStoreElement(TEMPLATE_UID, SectionTemplate.UID_TYPE, false);
      if (null != template) {
      references = template.getIncomingReferences();
        for (ref : references) {
              if(!ref.getRelease()) {
          section = ref.getReferencedElement();
            if (section instanceof Section) {
              page = section.getParent().getParent();
     
              if (page.isLockSupported()) {
              try {
    if (!page.isLocked()) {
              context.logInfo("setLocked =" + page.getReleaseStatus()); // the releaseStatus = 0 (RELEASED)
              page.setLock(true,true);
          }
    } catch(e) {
    context.logError("could not change page due to " + e);
    }
     
    It's the same exception for elements from release store. 
    How do I get the element writeable?
     
    Kind regards
    Bernadette
    0
  • Zendesk API User
    Author: Peter_Jodeleit - 12/13/2023 8:47

    This is a different error

    Inside a generation task you are in a read only environment, so it's intentional that you cannot alter data.

    Could you describe your use case? There may be an alternative solution available.

     

    0
  • Zendesk API User
    Author: dakaspbe - 12/13/2023 9:15

    Hi Peter,

    thanks for the answer.

    We want to create a list (whitelist) with all used external links within our website.

    I thought that I just can add a new domain to the whitelist when I generate the corresponding link within the page. 

     

    some years ago we had a script which created the whitelist by using FindExternalHosts.find().

    As this object doesn't exisits anymore I thought it is a good idea to just add new hosts everytime we create an external link. In this case I can easily pass the current link to the script.

    Kind regards

    Bernadette

    0
  • Zendesk API User
    Author: dakaspbe - 12/13/2023 9:56

    Hi, 

    is it possible to get all references/usages of a linkTemplate referenced by referencename?

    I mean something similar to 

    context.requireSpecialist(StoreElementAgent.TYPE).loadStoreElement(TEMPLATE_UID, SectionTemplate.UID_TYPE, false);

     

    In this case I can create the whitelist independent from the generation process by concating all used Urls.

    Kind regards

    Bernadette

    0
  • Zendesk API User
    Author: Peter_Jodeleit - 12/13/2023 11:07

    Yes, you can use the getIncomingReferences() method of the LinkTemplate. Each incoming reference is a usage. It sounds like you are interested in usages from the PageStore...

    0
  • Zendesk API User
    Author: mbergmann - 12/13/2023 11:23

    Not sure if that fits your use case but have you seen ProjectReferencesAgent.getExternalReferences(…)?

    Just a hint - might be useful depending on your case.

    0
  • Zendesk API User
    Author: dakaspbe - 12/27/2023 14:36

    Hi Michael,

    i'm not shure whether this fits for my needs. As discribed I need to find all external links in my project to create a whitelist with all referenced domains.

    in our old script we just simply used 

    de.espirit.firstspirit.ps.findexternalhosts.FindExternalHosts.find()

    My first approach was to collect the url during the generation but this is not possible. Thus I have to reimplement the FindExternalHosts somehow.

    As I'm a totally newbie it's very hard to understand your comments or the API documentations.

    Kind regards 

    Bernadette

    0
  • Zendesk API User
    Author: dakaspbe - 12/27/2023 14:52

    Hi Peter,

    I tried this appoach. It seams that the incomingReferences are the section within the linktemplate is used. How do I get the used links within a section? 

    Kind regards

    Bernadette

    0
  • Zendesk API User
    Author: Peter_Jodeleit - 1/4/2024 9:32

    I'll try to find someone in the company who knows something about the internals of the class de.espirit.firstspirit.ps.findexternalhosts.FindExternalHosts 
    Due to the holiday season this may take a while. Judging from the class name this was a project or customer specific implementation from our Professional Services team. Do you have more insights about this? Maybe the name of the module that provided this functionality and in which context this has been built? And why this is no longer available in your environment.

    0
  • Zendesk API User
    Author: mbergmann - 1/9/2024 12:56

    Hi Bernadette,

    in general, collecting the external links during generation is a valid approach. Especially as the "real" output is decided during generation and other mechanisms that only rely on FormData might - depending on your templates - gather too many entries (in case those are not rendered) or also miss others (if there are "other mechanisms" than just form entries that create external links).

    The problem here is in my opinion that you try to save it into a page.

    An option would be to "remember" those links in the schedule context in a variable (e.g. a map).

    You can use #global.scheduleContext here which will give a ScheduleContext object. On that, you can use set/getProperty to store a List or Map of URLs / domains. Of course you'd rather "bundle" that mechanism in a rendertemplate or script that is just called and also "extracts" the domain from the complete URL etc). The schedule context properties remain valid during the current execution of the whole schedule and thus allow "information transfer" from one schedule task to another.

    Hint: Mind the difference between get/setPropertyand  get/setVariable as the latter has a more "permanent" character and is (invisibly) stored "in the schedule" after a schedules's execution and could be accessed during later executions of the same schedule. That MIGHT (at least partially) be intended if you use mechanisms like partial or delta generation - depending on the concrete logic / code that fills the list.

    After the generation of the "normal" content, you could then (for example) generate a "technical page" that accesses that variable and renders the whitelist. That should be a separate partial generation task in the schedule to make sure it is executed after the generation of the content.

    Michael

     

    0
  • Zendesk API User
    Author: dakaspbe - 1/10/2024 6:36

    Hi Peter,

    thanks for this remark. I wasn't aware that this is a customer specific implementation. Your hint lead me to old source code. The module was not working since our last first spirit update.

    I had a look into the code. The functionality is like this:

    iterate through all references of the linktemplates and search in the formdata for the url-field. 

    But it's not working anylonger due to some errors. 

    As we have redesigned the setup of our pages I think this approach will be very difficult. The text with the links can be in different form-fields within multiple FS_CATALOG-entries.

    Kind regards

    Bernadette

    0
  • Zendesk API User
    Author: dakaspbe - 1/10/2024 14:48

    Hi Michael,

    this was a very good idea. It works. I can store the external host during the generation of the links and retrieve the stored entries to create the whitelist in a separate generation call.

    Last point is how to trigger the generation of the whitelist-page during the generate_partly-schedule.

    I tried to add a generate-action in the task administration. But unfortunately the task breaks with errors although I see no errors in the log.

    Is it possible to trigger the generation with a context script?

     

    Kind regards

    Bernadette

    0
  • Zendesk API User
    Author: mbergmann - 1/10/2024 15:41

    Hi Bernadette,

    hmm, usually that should work. Sounds strange especially that there is no error in the log... Do you have more details?

    Using a context script would not help in this case as the information "lives" only in the schedule context and is not accessible from "outside". So the "whitelist generation" has to be in the same schedule - at least when following that approach (which usually works well in similar situations).

    Kind regards

    Michael

    0
  • Zendesk API User
    Author: dakaspbe - 1/11/2024 11:13

    Hi Michael,

    this is very strange. Today everything works fine. The new additional generation of the whitelist works now without errors. The only difference to yesterday is that I closed the server manager before starting the generation.

    Right now I'm doing some tests but the first impression is very good. The pages and the whitelist with all used external domains are generated correctly.

     

    Thank you very much for all your help,

    Bernadette

    0

Vous devez vous connecter pour laisser un commentaire.