Hello, I had a question about the feasibility or approach I should take to programatically build a list of pages in SilverStripe. The data for the pages lives in a separate JSON API and the fields are uniform and simple (e.g. title, description, etc). I need to run the import once a day. My first thought was to generate a CSV file from the API then use CsvBulkLoader
to create the pages. Is this a good approach to take? Are there approaches that would be simpler?
Depends on how familliar you are with REST (?) APIs vs CSV. For me, the CSV is an extra layer of complexity that isn't needed.
Off the top of my head:
$pages = $this->getPageDataFromAPI() // Returns a blob of JSON. Assumes an array of pages // Assumes API data looks something like this, or can be modified to look like this: [ { "Title": "Some title", "Description": "Some description" }, { "Title": "Some title 2", "Description": "Some description 2" } ] foreach ($pages as $page) { // TODO // Check wether the page has unpublished changes. If so, just use ->write() // Other implemenmtation specific stuff SiteTree::create($array)->publishRecursive(); }
Awesome thanks, I'm more comfortable with REST so that is very helpful. Thanks again!
Make your API call, iterate over the result, create new SiteTree
records based on what the API endpoint returns.
Hey, I’m looking at the new logout functionality with the interstitial logout form. Is there any way to set BackURL
for that form? We’re adding a get var to the logout link but that seems to be stripped before it even gets to Security#logout
so the value of the BackURL
form field always falls back to the referrer URL.
@robjingram I think you can set it as a session value too
Really? getBackURL
just checks GET and POST vars.
I’m currently overriding that method in a custom LogoutHandler
That’s currently working and since it is in a LogoutHandler
I assume it won’t leak into any other uses of getBackURL
.
Just noticed that the back URL is probably not being set because the URL we’re building is malformed. It has two ?
characters since the security ID is being added by SS too.
And when that URL is properly formed the interstitial logout form isn’t displayed.