PHP-SharePoint-Lists-API
PHP-SharePoint-Lists-API copied to clipboard
addDocument
Thanks for such a great API !
I am trying to update /SharePointAPI.php to allow me to use the Copy.asmx?WSDL for the CopyIntoItems feature. Extrapolation from the modifyList function is pretty straight forward ... until I think about the actual execution of the CAML.
I suspect I need a separate Copy.asmx?WSDL-based soapClient->UpdateListItems -- with UpdateListItems being replaced as well. Any guidance on how it should be changed to handle the Copy.asmx?WSDL, instead of the Lists.asmx?WSDL that modifyList uses?
I still have some other items to work through, but for now I am mostly interested in the "// Attempt to run operation" part -- that way I can troubleshoot the other stuff.
Here is what I have so far:
/**
* addDocument
* Perform an action on a sharePoint library to either add content to it.
* This method will call the SharePoint SOAP API with this data
* to apply the changes.
*
* @param $strSourceURL Externally where the file comes from ???
* @param $strDestinationURL Internally where to put the file, what should this look like ???
* @param $arrFields Associative Array with keys (DisplayName, InternalName, Id, Value)
* @param $b64Stream byte-64 encoding of the Source file's contents
* @return Array|Object
*/
public function addDocument ($strSourceURL, $strDestinationURL, array $arrFields, $b64Stream) {
// Wrap in CAML
$strType = 'File'; // see https://[domain].sharepoint.com/[[site]/[subsite]]/_vti_bin/Copy.asmx?WSDL for other Types
$CAML = '
<CopyIntoItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<SourceUrl>
' . $strSourceURL . '
</SourceUrl>
<DestinationUrls>
<string>
' . $strDestinationURL . '
</string>
</DestinationUrls>
<Fields>
<FieldInformation>
<Type>
' . $strType . '
</Type>
<DisplayName>
' . $arrFields['DisplayName'] . '
</DisplayName>
<InternalName>
' . $arrFields['InternalName'] . '
</InternalName>
<Id>
' . $arrFields['Id'] . '
</Id>
<Value>
' . $arrFields['Value'] . '
</Value>
</FieldInformation>
</Fields>
<Stream>
' . $b64Stream . '
</Stream>
</CopyIntoItems>';
$this->capturedCAML = $CAML;
$xmlvar = new \SoapVar($CAML, XSD_ANYXML);
$result = NULL;
// Attempt to run operation
try {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ vv what should that be ????
$result = $this->xmlHandler($this->soapClient->UpdateListItems($xmlvar)->UpdateListItemsResult->any);
} catch (\SoapFault $fault) {
$this->onError($fault);
}
// Return a XML as nice clean Array
return $result;
}
Hello,
Not really familiar with the copy stuff, but I think your right in that you'd need to set up a soapClient with the copy WSDL.
Assuming the auth would be the same as for the Lists stuff, you'd probably want to figure out a way to let users supply more than one WSDL's (maybe allowing the spWsdl to be defined as an associative array in addition to its base usage so you get pass in array('copy' => 'path, 'list'=>'path)
, then alter soap client setup ( https://github.com/thybag/PHP-SharePoint-Lists-API/blob/develop/src/Thybag/SharePointAPI.php#L174 ) to maybe register a few clients, listClient, copyClient etc & call the correct one for interacting with the different webservices.
In theory having a few clients sitting around shouldn't be an issue since they don't actually auth till they start interacting with the API's.
Granted, I've not looked in to or tested any of this so its pretty much random speculation at this point :p
Looking further it appears it appears most if not all of what I just wrote is totally wrong >.<
Seems a few people have independently managed to get this working:
@drjoju in https://github.com/thybag/PHP-SharePoint-Lists-API/pull/78 @alexdemers in https://github.com/alexdemers/PHP-SharePoint-Lists-API
Will have to have a proper read through the code :)
https://github.com/thybag/PHP-SharePoint-Lists-API/issues/63 also appears to be looking for the same thing.