0

I am creating a filemanger that uses Google Docs for storage, but I am having difficulty working out how to restore a file that has been sent to the trash. I can send to trash by using this code:

$resourceId = "file:12345";
$link = "https://docs.google.com/feeds/default/private/full/";
$file = $docs->getDocumentListEntry($link.$resourceId);
$file->delete();

I can then view all trashed documents using:

$docs = new Zend_Gdata_Docs($client);
$docs->setMajorProtocolVersion(3);
$feed = $docs->getDocumentListFeed($link."-/trashed");

foreach($feed->entries as $entry) {
  ...
}

My question is how can I then restore one of these files back to location it was before it was deleted as you can in Google Docs proper?

amburnside
  • 1,943
  • 5
  • 24
  • 43
  • Ok, so worked out you need to edit the metadata to restore from the Trash. By editing the following: `` to: `` – amburnside Sep 30 '11 at 12:51

1 Answers1

0

Ok, so I worked out how to restore trashed files in my Google Docs App. Code is as follows:

$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($gUser, $gPass, $service);
$client->setHeaders('If-Match: *');
$gdocs = new Zend_GData_Docs($client);
$gdocs->setMajorProtocolVersion(3);

$slug = array('If-Match'=>'*'); 

$link = "https://docs.google.com/feeds/default/private/full/".$resourceId;
$entry = $gdocs->getDocumentListEntry($link);
$xml = $entry->getXML();
$feed = str_replace('label="trashed"', 'label=""',$xml);

$entryResult = $gdocs->updateEntry($feed, $entry->getEditLink()->href,null,$slug);

This will also work for unstarring a document and with other category elements. So for example:

Replace:

$feed = str_replace('label="trashed"', 'label=""',$xml);

With:

$feed = str_replace('label="starred"', 'label=""',$xml);
amburnside
  • 1,943
  • 5
  • 24
  • 43