Ejemplo n.º 1
0
 /**
  * Process the changes and build the output
  * 
  * @return void
  * @access public
  * @since 10/25/07
  */
 public function buildContent()
 {
     try {
         ob_start();
         $fileAsset = $this->getFileAsset();
         $fileAssetId = $fileAsset->getId();
         $contentAsset = $this->getContentAsset();
         $repository = $fileAsset->getRepository();
         $repository->deleteAsset($fileAsset->getId());
         // Log the success or failure
         if (Services::serviceRunning("Logging")) {
             $loggingManager = Services::getService("Logging");
             $log = $loggingManager->getLogForWriting("Segue");
             $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified.");
             $priorityType = new Type("logging", "edu.middlebury", "Event_Notice", "Normal events.");
             $message = "File deleted with id '" . $fileAssetId->getIdString() . "'.";
             $item = new AgentNodeEntryItem("Media Library", $message);
             $item->addNodeId($fileAssetId);
             $item->addNodeId($contentAsset->getId());
             $idManager = Services::getService("Id");
             $director = AssetSiteDirector::forAsset($contentAsset);
             $site = $director->getRootSiteComponent($contentAsset->getId()->getIdString());
             $item->addNodeId($idManager->getId($site->getId()));
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         $error = ob_get_clean();
         if ($error) {
             $this->error($error);
         }
     } catch (Exception $e) {
         $this->error($e->getMessage());
     }
     $this->start();
     print $this->getQuota();
     // No content.
     $this->end();
 }
Ejemplo n.º 2
0
 /**
  * Create a new file asset
  * 
  * @return object Asset
  * @access public
  * @since 1/26/07
  */
 function createFileAsset()
 {
     $contentAsset = $this->getContentAsset();
     $asset = MediaAsset::createForContentAsset($contentAsset);
     if (!($displayName = RequestContext::value('displayName'))) {
         $displayName = $_FILES['media_file']['name'];
     }
     if (!($description = RequestContext::value('description'))) {
         $description = '';
     }
     // Check the quota
     $slot = $this->getSlot();
     if ($this->getQuotaUsed() + $_FILES['media_file']['size'] > $slot->getMediaQuota()->value()) {
         throw new Exception("Cannot add File, {$displayName}, quota of " . $slot->getMediaQuota()->asString() . " exceeded.");
     }
     // Create the asset
     $asset->updateDisplayName($displayName);
     $asset->updateDescription($description);
     try {
         $this->addFileRecord($asset);
     } catch (Exception $e) {
         HarmoniErrorHandler::logException($e, 'Segue');
         $this->nonFatalError($e->getMessage(), get_class($e));
     }
     try {
         $this->addDublinCoreRecord($asset);
     } catch (Exception $e) {
         HarmoniErrorHandler::logException($e, 'Segue');
         $this->nonFatalError($e->getMessage(), get_class($e));
     }
     // Log the success or failure
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Segue");
         $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified.");
         $priorityType = new Type("logging", "edu.middlebury", "Event_Notice", "Normal events.");
         $item = new AgentNodeEntryItem("Media Library", "File uploaded with id '" . $asset->getId()->getIdString() . "' and filename '" . $_FILES['media_file']['name'] . "'");
         $item->addNodeId($asset->getId());
         $item->addNodeId($contentAsset->getId());
         $idManager = Services::getService("Id");
         $director = AssetSiteDirector::forAsset($contentAsset);
         $site = $director->getRootSiteComponent($contentAsset->getId()->getIdString());
         $item->addNodeId($idManager->getId($site->getId()));
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     return $asset;
 }
Ejemplo n.º 3
0
 /**
  * Process the changes and build the output
  * 
  * @return void
  * @access public
  * @since 1/26/07
  */
 public function buildContent()
 {
     try {
         ob_start();
         $idManager = Services::getService("Id");
         $fileAsset = $this->getFileAsset();
         // Update the files
         $oldFilename = null;
         $newFilename = null;
         foreach (array_keys($_FILES) as $fieldName) {
             if (preg_match('/^file___(.+)$/', $fieldName, $matches)) {
                 $fileRecord = $fileAsset->getRecord($idManager->getId($matches[1]));
                 $filenameParts = $fileRecord->getPartsByPartStructure($idManager->getId("FILE_NAME"));
                 $oldFilename = $filenameParts->next()->getValue();
                 $newFilename = $_FILES[$fieldName]['name'];
                 $this->updateFileRecord($fileAsset, $fileRecord, $fieldName);
             } else {
                 if ($fieldName == 'media_file') {
                     $oldFilename = null;
                     $newFilename = $_FILES[$fieldName]['name'];
                     $this->addFileRecord($fileAsset);
                 }
             }
         }
         // Update the displayname
         //
         // If the displayname in the form is the old filename, update it to the
         // new filename
         if (RequestContext::value('displayName') && RequestContext::value('displayName') == $oldFilename && $newFilename) {
             $fileAsset->updateDisplayName($newFilename);
         } else {
             if (RequestContext::value('displayName') && RequestContext::value('displayName') != $fileAsset->getDisplayName()) {
                 $fileAsset->updateDisplayName(HtmlString::getSafeHtml(RequestContext::value('displayName')));
             }
         }
         // Update the description if needed.
         if (!RequestContext::value('description')) {
             $fileAsset->updateDescription('');
         } else {
             if (RequestContext::value('description') != $fileAsset->getDescription()) {
                 $fileAsset->updateDescription(HtmlString::getSafeHtml(RequestContext::value('description')));
             }
         }
         // Update the other metadata.
         $dublinCoreRecords = $fileAsset->getRecordsByRecordStructure($idManager->getId('dc'));
         if ($dublinCoreRecords->hasNext()) {
             $this->updateDublinCoreRecord($fileAsset, $dublinCoreRecords->next());
         } else {
             $this->addDublinCoreRecord($fileAsset);
         }
         // Log the success or failure
         if (Services::serviceRunning("Logging")) {
             $loggingManager = Services::getService("Logging");
             $log = $loggingManager->getLogForWriting("Segue");
             $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified.");
             $priorityType = new Type("logging", "edu.middlebury", "Event_Notice", "Normal events.");
             $message = "File updated with id '" . $fileAsset->getId()->getIdString() . "'";
             if (isset($newFilename)) {
                 $message .= " and new filename '" . $newFilename . "'";
             }
             $item = new AgentNodeEntryItem("Media Library", $message);
             $item->addNodeId($fileAsset->getId());
             $item->addNodeId($this->getContentAsset()->getId());
             $contentAsset = $this->getContentAsset();
             $idManager = Services::getService("Id");
             $director = AssetSiteDirector::forAsset($contentAsset);
             $site = $director->getRootSiteComponent($contentAsset->getId()->getIdString());
             $item->addNodeId($idManager->getId($site->getId()));
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         // 		printpre($_FILES);
         if ($error = ob_get_clean()) {
             $this->error($error);
         }
         $this->start();
         // 		print "\n<![CDATA[";
         // 		print_r($_REQUEST);
         // 		print_r($_FILES);
         // 		print "\n]]>";
         print $this->getAssetXml($fileAsset);
         print $this->getQuota();
         $this->end();
     } catch (Exception $e) {
         $this->error($e->getMessage(), get_class($e));
     }
 }
Ejemplo n.º 4
0
 /**
  * Log an event
  * 
  * @param string $message
  * @param array $commentNodes An array of effected comment node Ids.
  * @return void
  * @access public
  * @since 11/9/07
  */
 public static function logMessage($message, $contentAsset, array $commentNodes)
 {
     $logName = 'Segue';
     $type = 'Event_Notice';
     $category = 'Comments';
     $loggingManager = Services::getService("Logging");
     $log = $loggingManager->getLogForWriting($logName);
     $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified.");
     $priorityType = new Type("logging", "edu.middlebury", $type, "Events involving critical system errors.");
     $item = new AgentNodeEntryItem($category, $message);
     // Add the comment Ids
     foreach ($commentNodes as $nodeId) {
         $item->addNodeId($nodeId);
     }
     // Add the content asset
     $item->addNodeId($contentAsset->getId());
     // Add the site as a whole
     $idManager = Services::getService("Id");
     $director = AssetSiteDirector::forAsset($contentAsset);
     $site = $director->getRootSiteComponent($contentAsset->getId()->getIdString());
     $item->addNodeId($idManager->getId($site->getId()));
     $log->appendLogWithTypes($item, $formatType, $priorityType);
 }