Updating Pages to New Data Definition

Ken Dickinson's Avatar

Ken Dickinson

26 Feb, 2013 10:25 PM

We have just changed the DD for one set of pages. We need to set some default values in a couple of fields for all of the updated pages. I'd like to do this through the API (eventually as a batch operation - right now, I'm just trying to do it to a single page for testing purposes). So, when I do a read operation through the API, the field I want to updated doesn't exist. I need to create new arrays within the structured data (and, actually, remove one old one) but this is a fairly complex data definition with some nested data. In PHP, I can easily read the data through a construct like this:

$data = $reply->readReturn->asset->page; $value = $data->structuredData->structuredDataNodes->structuredDataNode[3]->structuredDataNodes->structuredDataNode[0]->identifier

And I can set a value using a similar construct with no problem:

$data->structuredData->structuredDataNodes->structuredDataNode[3]->structuredDataNodes->structuredDataNode[0]->structuredDataNodes->structuredDataNode[0]->blockPath = "path to index"

Then I just poke the whole thing back into the structured data using an edit command.

But, because of persistence, there are structured data nodes that don't exist. So, I need to create the entire structured data set as an array (which works fine). The problem occurs with inserting that new array element into the PHP structure for the structured data. array_splice doesn't think my base array ($data) is an array. PHP thinks it's an object and it should cast it to an array but won't.

Now all of this would be a lot easier if I could do one of the following...

a) just do some kind of batch update that would update the actual data structure of all of the pages to match the data definition (then I could just set the values using the api)

-- or --

2) Just use raw XML.

Option 2 seems like the better option in many ways (who doesn't love manipulating strings, eh?) but my PHP skills are a bit rusty and my PHP SOAP skills are virtually non-existent (we're a dotnet shop).

Suggestions?

  1. 1 Posted by Ryan Griffith on 28 Feb, 2013 07:03 PM

    Ryan Griffith's Avatar

    Hi Ken,

    The problem occurs with inserting that new array element into the PHP structure for the structured data. array_splice doesn't think my base array ($data) is an array. PHP thinks it's an object and it should cast it to an array but won't.

    Without looking at the code, it sounds as though you are trying to mimic the original structured of the structuredData. As long as the identifiers and groupings match your Data Definition the order shouldn't matter, so you should be able to just append your new field onto the end.

    Note: you may want to also check to see if the node exists as well. If a Page was updating through the Cascade Interface, it may be present. If not, you would add the new node.

    Also, you mentioned removing an old field. This field won't be rendered anywhere in the UI, so you shouldn't have to worry about removing it.

    Please let me know if you have any questions.

    Thanks

  2. 2 Posted by Ken Dickinson on 06 Mar, 2013 04:24 PM

    Ken Dickinson's Avatar

    Since I could just append to the end of the array, I didn't have to use array_splice to insert the new elements any longer. Now, though, I'm still getting a related error. The top error is "Undefined property: stdClass". When I did a print_r of the readReturn, it indicated that it was an object, not an array. PHP soapclient is supposed to automatically cast an object to an array on a send but it doesn't seem to be doing that. This was similar to the error I was initially getting when attempting to use array_splice on the readReturn - PHP was telling me it was an object instead of an array and couldn't, therefore, perform an array_splice so I think there is something about the readReturn that it doesn't like. For what it's worth, this is a pretty deep data definition so readReturn is pretty complex. I'm trying now to use nusoap which will let me operate on strings rather than arrays and objects. Although that's not what is in the HH github examples, it seems like it might be a better approach overall. I'll report back when I know something more.

  3. 3 Posted by Ryan Griffith on 06 Mar, 2013 06:51 PM

    Ryan Griffith's Avatar

    Thank you for the follow up, Ken. When you have a moment, can you attach your PHP script at the point of your last post? Perhaps I may be able to help look over it with you.

    Thanks!

  4. 4 Posted by Ken Dickinson on 08 Mar, 2013 08:33 PM

    Ken Dickinson's Avatar

    I've attached the PHP file with the last error (from the above message).

    I've also started playing around with using nusoap to send a raw xml soap message to the server. This would work rather well in a sense because I don't have to deal with the array structure. I can just use XSL transformation in PHP to make the changes needed and feed the asset back to the Cascade API. I've been playing around with using Oxygen's WSDL Soap Analzyer to try out some raw xml but I'm getting some different errors there.

    Basically, from what I've seen, I should be able to get the page structure using a read operation, make edits to the XML, then send back the asset portion of the readReturn with the changes - but Cascade gives me an "invalid content" error when sending back the raw xml. I've also attached a sample of the raw xml I've been working with and the fault message returned. I've tried massaging the raw edit message in several ways (such as removing items that may be unnecessary) but each time, I just get another error. (Note: so far, all if this is in Oxygen - once I get it to work in Oxygen it should work in nusoap PHP).

  5. 5 Posted by Ryan Griffith on 11 Mar, 2013 12:02 PM

    Ryan Griffith's Avatar

    Hi Ken,

    I am not too familiar with passing in the raw XML, but based on the error message try removing the empty <as:asset> elements from your XML and see if that has any affect on the operation.

    In the meantime, I'll take a look at your script as well as ask the developers if they have any additional information regarding using raw XML with Web Services.

    Please let me know if you have any questions.

    Thanks

  6. 6 Posted by Ryan Griffith on 11 Mar, 2013 12:07 PM

    Ryan Griffith's Avatar

    Hi Ken,

    When you have a moment, can you also attach the Data Definition for Pages being updated with the script you provided? I would like to see if I can do some local testing as well.

    Thanks!

  7. 7 Posted by Ken Dickinson on 11 Mar, 2013 09:42 PM

    Ken Dickinson's Avatar

    Removing as:asset made no difference. I also tried removing all assets with xsl:nil='true' - did not fix. I've attached the data definition.

  8. 8 Posted by Ken Dickinson on 12 Mar, 2013 08:56 PM

    Ken Dickinson's Avatar

    So I tried using Oxygen with a simpler page. I've attached the SOAP readResponse and the SOAP edit message I sent for this page. By using a simpler page I was able to use quite a bit of trial and error with Oxygen before I finally had a successful edit. Note that, on the SOAP message, there are several empty nodes (the Cascade API wouldn't accept xsi:nil='true' for most nodes but insisted on it for one). The nodes that are in the message were required by the API and no others were accepted. As importantly they had to be ordered exactly as in the SOAP edit message. The SOAP call when through and returned success but viewing the page in Cascade now results in an error: "Content is not allowed in Prolog" (I can still edit the page).

  9. 9 Posted by Ryan Griffith on 13 Mar, 2013 06:33 PM

    Ryan Griffith's Avatar

    Hi Ken,

    I was about to do some testing locally and wanted to get a better feel for the logic in the sample code you provided above. When you have a moment, can you explain a bit more what field(s) you are looking to add default values to?

    Thanks!

  10. 10 Posted by Ken Dickinson on 13 Mar, 2013 06:45 PM

    Ken Dickinson's Avatar

    After looking back at that DD, I realized I uploaded the wrong one. I've attached the correct one. I'm attempting to add nodes the nodes for /system-data-structure/group[identifier='requirements']/group[identifier='dom-all'] and /system-data-structure/group[identifier='requirements']/group[identifier='int'] with default values for block[identifier='default'] (in each of them).

  11. 11 Posted by Ryan Griffith on 13 Mar, 2013 07:02 PM

    Ryan Griffith's Avatar

    Thank you for the additional information Ken. Let me work with this a bit and see if I can help come up with something.

    Please let me know if you have any questions.

    Thanks

  12. 12 Posted by Ryan Griffith on 13 Mar, 2013 09:34 PM

    Ryan Griffith's Avatar

    Hi Ken,

    After some local testing, let's give the attached script a try.

    Basically it loops through the top level groups searching for dom-all or int , then looks for the default field for each to see if they have been set. If the field has not been set, it sets them to the corresponding default Block ID (set at the top of the script).

    To apply this to multiple pages, you would surround this code with either a loop over a Folder's children using a read() operation on the parent Folder or the subscribers of the Content Type using listSubscribers() (if you are running Cascade 7.2)

    Please let me know if you have any questions.

    Thanks

  13. 13 Posted by Ryan Griffith on 19 Mar, 2013 12:50 PM

    Ryan Griffith's Avatar

    Hi Ken,

    Just wanted to follow up to see if you had a chance to view my recent comment.

    Please let us know if you have any questions.

    Thanks.

  14. 14 Posted by Ken Dickinson on 19 Mar, 2013 02:00 PM

    Ken Dickinson's Avatar

    Hi, Ryan.

    Yes, I have had a chance to look at that code and I'm working with it now. Your code really gave me an opportunity to wrap my head around how PHP talks to the Cascade API. I should have this solution working by the end of this week and I will post the final solution when done.

    Thank you for your help.

  15. 15 Posted by Ryan Griffith on 19 Mar, 2013 06:23 PM

    Ryan Griffith's Avatar

    Thank you for the follow up, Ken. I am glad to hear the sample code was helpful.

    I'm going to go ahead and close this discussion for now, but please feel free to comment or reply to re-open if you would like to post your solution or if you have any additional questions.

    Thanks

  16. Ryan Griffith closed this discussion on 19 Mar, 2013 06:23 PM.

  17. Ken Dickinson re-opened this discussion on 20 Mar, 2013 04:47 PM

  18. 16 Posted by Ken Dickinson on 20 Mar, 2013 04:47 PM

    Ken Dickinson's Avatar

    There was a slight difference in what your code did and what I needed it to do - mostly caused by communications, I'm sure. The structure is really quite deep. I've attached the final version (tested and works nicely).

    It was a great exercise and helped me to really wrap my head around the structures created by a data definition and how PHP soapclient deals with them. I have confidence now that I can do pretty much anything I want with the API.

    Thank you again for your help.

    Ken Dickinson
    Web Manager
    Information Technology – Application Solutions
    Phone: 903-468-3247
    Email: [email blocked]

  19. 17 Posted by Ryan Griffith on 20 Mar, 2013 07:37 PM

    Ryan Griffith's Avatar

    Thank you for following up and providing your working code, Ken. I am glad to hear you were able to get things working and feel more comfortable with Web Services.

    Have a great day!

  20. Ryan Griffith closed this discussion on 20 Mar, 2013 07:37 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac