The following code is a re-creation of Hannon Hill’s “Web Services PHP Sample Project” using Zend SOAP Client. I re-created this project as a learning exercise for a project I am working on for my employer. Although most of the code is similar, it is not a cut-and-paste or the original project.
Note lines 39 and 40. I had to unset these lest I receive an error when sending an edit request to an asset. I’m not sure why this is the case. Clarification is welcome.
It appears it is no longer necessary to unset the elements specified on lines 39 and 40 in the latest version of Cascade (6.8.3 as of this update).
<?php
/* A re-creation of Hannon Hill's Web Services PHP Sample Project
* using Zend SOAP Client.
*
* Author: Mark Zolton (mark@zolton.org)
* Website: http://www.zolton.org
*
* Original Project:
* https://github.com/hannonhill/Webservices-PHP-Sample-Project
*
* Zend SOAP Client:
* http://framework.zend.com/manual/en/zend.soap.client.html
*/
require_once 'web_services_util.php';
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Soap_Client');
Zend_Loader::loadClass('Zend_Debug');
$url = 'http://localhost:8080/ws/services/AssetOperationService?wsdl';
$auth = array('username' => 'admin', 'password' => 'admin');
$id = array('type' => 'page', 'id' => '8e8535540a63e2190189a406c0805cdb');
$client = new Zend_Soap_Client($url, array('compression' => SOAP_COMPRESSION_ACCEPT));
$params = array('authentication' => $auth, 'identifier' => $id);
$reply = $client->read($params);
if($reply->readReturn->success == true)
{
$page = (array) $reply->readReturn->asset->page;
Zend_Debug::dump($page);
Zend_Debug::dump($page['metadata']->title);
$page['metadata']->title = date('l dS \of F Y h:i:s A');
unset($page['entityType']);
unset($page['pageConfigurations']);
$params = array('authentication' => $auth, 'asset' => array('page' => $page));
try
{
$reply = $client->edit($params);
}
catch(Exception $e)
{
echo 'Exception: ' . $e->getMessage();
}
$result = $client->getLastResponse();
if(!isSuccess($result))
{
echo 'Error occured: ' . extractMessage($result);
}
else
{
Zend_Debug::dump($page['metadata']->title);
echo 'Asset updated successfully.';
}
}
else
{
echo 'A problem occured.';
}
?>
I have to give credit to my colleague for working with me on this exercise. I would state his name, but I’m not in the habit of mixing my personal site with my job.
You may also be interested in the article Creating Folder and Page Assets Using Web Services for Cascade and Zend SOAP Client.