// Get arguments. $exampleName = array_shift($argv); $baseUrl = array_shift($argv); $username = array_shift($argv); $password = array_shift($argv); $spaceId = array_shift($argv); $contentId = array_shift($argv); // Try a connection. $dcc = new DuraCloudConnection($baseUrl, $username, $password); $ds = new DuraStore($dcc); // Create a content file. $fp = tmpfile(); fwrite($fp, TEST_CONTENT_STRING); // Create content. $descriptor = new DuraCloudContentDescriptor(array('custommetadataname' => 'CustomMetadataValue')); $content = new DuraCloudFileContent($descriptor); $content->setResource($fp); unset($fp); // Store content. $location = $ds->storeContent($spaceId, $contentId, $content); if (!$location) { die("Could not create content!\n"); } // Clean up unset($content, $descriptor); // Check its metadata. $descriptor = $ds->getContentMetadata($spaceId, $contentId); if ($descriptor) { $metadata = $descriptor->getMetadata(); } else { $metadata = null;
/** * Store an issue in DuraCloud. * @param $journal Journal * @param $issue Issue * @return string location iff success; false otherwise */ function exportIssue(&$journal, &$issue) { // Export the native XML to a file. $nativeImportExportPlugin =& $this->getNativeImportExportPlugin(); $filename = tempnam('duracloud', 'dcissue'); $nativeImportExportPlugin->exportIssue($journal, $issue, $filename); // Store the file in DuraCloud. $dcc = $this->getDuraCloudConnection(); $ds = new DuraStore($dcc); $descriptor = new DuraCloudContentDescriptor(array('creator' => $this->getName(), 'identification' => $issue->getIssueIdentification(), 'date_published' => $issue->getDatePublished(), 'num_articles' => $issue->getNumArticles())); $content = new DuraCloudFileContent($descriptor); $fp = fopen($filename, 'r'); $content->setResource($fp); $location = $ds->storeContent($this->getDuraCloudSpace(), 'issue-' . $issue->getId(), $content); // Clean up temporary file unlink($filename); return $location; }
/** * Get content. * @param $spaceId string * @param $contentId string * @param $storeId int optional ID of store * @return object DuraCloudContent */ function &getContent($spaceId, $contentId, $storeId = DURACLOUD_DEFAULT_STORE) { // Prepare descriptor and content $descriptor = new DuraCloudContentDescriptor(); $content = new DuraCloudFileContent($descriptor); $fp = tmpfile(); $content->setResource($fp); $dcc =& $this->getConnection(); $params = array(); if ($storeId !== DURACLOUD_DEFAULT_STORE) { $params['storeId'] = $storeId; } if (!$dcc->getFile($this->getPrefix() . urlencode($spaceId) . '/' . urlencode($contentId), $fp, $params)) { $returner = false; // Return by ref kludge return $returner; } $headers = $dcc->getHeaders(); if (isset($headers['Content-Type'])) { $descriptor->setContentType($headers['Content-Type']); } if (isset($headers['Content-MD5'])) { $descriptor->setMD5($headers['Content-MD5']); } // Parse the result headers to return as metadata $descriptor->setMetadata($this->_filterMetadata($headers)); return $content; }