delete and unpublish via web services

lauren.fraser's Avatar

lauren.fraser

23 Oct, 2015 10:09 PM

We have a couple of scripts that compare an xml file to an existing folder in Cascade and create, update or delete assets that don't match the xml file.

This has been working great, but I noticed recently, that the pages aren't unpublished.

We use this code to remove the "old" jobs:

// Remove old, unprocessed jobs.
foreach ($existingJobs as $number => $id) {
  if (!in_array($id, $processedJobs)) {
    $log[] = $service->delete(array(
      "authentication" => $auth,
      "identifier" => array(
        "type"=> "page",
        "id" => $id
      )
    ));
  }
}

Is there something I can add to this that will unpublish them from the server as well?
Thanks,
Lauren

  1. 1 Posted by Wing Ming Chan on 23 Oct, 2015 11:11 PM

    Wing Ming Chan's Avatar

    Hi Lauren,

    Assuming that you know how to publish an asset, you just need to set $publish_info->unpublish to true (when publishing, it is set to false).

    Wing

  2. 2 Posted by lauren.fraser on 27 Oct, 2015 10:47 PM

    lauren.fraser's Avatar

    Hi Wing,
    Thanks for the quick response. I don't know how to publish an asset. We've been using a scheduled Publish Set inside of Cascade to handle that.
    I did find the github page for delete and unpublish via web services (https://github.com/hannonhill/Cascade-Web-Services-Examples/blob/ma...)

    I tried my hand at pulling the pieces I thought I'd need from this into our script, but I just keep getting new errors.

    Any suggestions? I feel like I'm making this harder than it needs to be. I've attached our script (username and pw are incorrect on purpose).

  3. 3 Posted by Wing Ming Chan on 28 Oct, 2015 01:24 PM

    Wing Ming Chan's Avatar

    Hi Lauren,

    I assume that you understand what the github example does. To make it work, first you'll need a workflow definition like the following:

      <steps>
        <step type="system" identifier="initialize" label="Initialization" >
          <actions>
            <action identifier="publish" label="Publish" move="forward" >
              <trigger name="UnpublishAndDelete" />
            </action>
          </actions>
        </step>
        <step type="system" identifier="finished" label="Finished" />
      </steps>
    

    Second, you need to edit the page and tie it with the workflow. Once the page is edited, the workflow will kick in and unpublish/delete the page. Since I don't write code like most people do, I just need one statement to achieve this, using my own library:

    $cascade->getAsset( 
            a\Page::TYPE, 
            '31eaa9338b7f08560139425cc3ccec7d' )->
        edit( 
            null, 
            $cascade->getAsset( a\WorkflowDefinition::TYPE, 'e7a95d678b7f085600b2e0be901d57ae' ), 
            "Delete and Unpublish", 
            "Comment", 
            false );
    

    You may want to look at my Page class to figure out how to make your code work.

    Wing

  4. 4 Posted by lauren.fraser on 04 Nov, 2015 06:49 PM

    lauren.fraser's Avatar

    I do have the workflow created.

    So I'll need to use web services to edit the page and tie it with the workflow? So I would need to capture every page that is currently being deleted with the script now and edit them instead?

    I'm currently passing those pages to an array to delete them. I'm getting an error with my "new" code below related to the line with "Workflow Definition" in it.

    If I get that corrected am I on the right track?

    Current:

    foreach ($existingJobs as $number => $id) {
      if (!in_array($id, $processedJobs)) {
    $log[] = $service->delete(array( "authentication" => $auth, "identifier" => array( "type"=> "page", "id" => $id ) )); } }

    New:

    foreach ($existingJobs as $number => $id) {
      if (!in_array($id, $processedJobs)) {

    $log[] = $service-&gt;edit(
        null,
      $service-&gt;getAsset (a\Workflow Definition::TYPE, 'a43471bdac105ad0097919f6968cc046' ), 
       &quot;Delete and Unpublish&quot;, 
        &quot;Comment&quot;, 
        false );
        array(
      &quot;authentication&quot; =&gt; $auth,
      &quot;identifier&quot; =&gt; array(
        &quot;type&quot;=&gt; &quot;page&quot;,
        &quot;id&quot; =&gt; $id
      )
    ));
    
    
    
    
    } }
  5. 5 Posted by Wing Ming Chan on 04 Nov, 2015 08:27 PM

    Wing Ming Chan's Avatar

    Lauren,

    I can see that you are trying to use my code. But I want to find out if you know anything about my library. You can always mix my code with your code. But you need to set up your PHP environment to use my library first. Once you have it set up, I will help you with this piece of code.

    By the way, will you be interested in joining a 3-part webinar on Google Hangout about web services? Details can be found on Online Tutorials.

    Wing

  6. 6 Posted by lauren.fraser on 04 Nov, 2015 09:11 PM

    lauren.fraser's Avatar

    Wing,
    I wasn’t sure where to find your library. I looked on the link below and clicked around and found this:

    http://www.upstate.edu/cascade-admin/projects/web-services/oop/classes/index.php

    I’m a one-woman shop here, with other duties outside of Cascade. Our network admins are the only ones with access to our php install. What’s the best way for me to tell them how to set up our PHP environment with your library?

    I’m very interested in the Google hangout! Cascade helped us develop what we have so far. I’ve been able to limp along making modifications as needed – but I know we could be doing more (with me doing less) if we leveraged web services.

    Thanks!
    Lauren

  7. 7 Posted by Wing Ming Chan on 04 Nov, 2015 09:16 PM

    Wing Ming Chan's Avatar

    Yes, that's the page where you can download my library. Try to follow the steps on Basic Setup. If you can read a text block using the library, then you should be fine.

    Wing

  8. 8 Posted by Wing Ming Chan on 05 Nov, 2015 01:52 PM

    Wing Ming Chan's Avatar

    Just want to give you one more piece of information. In the worst scenario, you can still install a web server with PHP on your own computer. Then you can run web service scripts there without any need from other people. I wrote and tested much of the library code from home on my own PC.

    Wing

  9. 9 Posted by lauren.fraser on 05 Nov, 2015 03:15 PM

    lauren.fraser's Avatar

    Good thought. Our network admin looked at it briefly yesterday and was going to check on having to change some extensions when they update php each month.

    Thanks,
    Lauren

  10. Ryan Griffith closed this discussion on 19 Nov, 2015 03:50 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