/** * Delete a Part and all its Parts. * * @param object Id $partId * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT}, {@link * org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID} * * @access public */ function deletePart(Id $partId) { $string = $partId->getIdString(); if (preg_match("/(.*)-(FILE_SIZE|FILE_NAME|FILE_DATA|MIME_TYPE|THUMBNAIL_DATA|THUMBNAIL_MIME_TYPE)/", $string, $r)) { $recordId = $r[1]; $field = $r[2]; if ($this->_isLastPart($field)) { $dbHandler = Services::getService("DatabaseManager"); // Delete the data $file = $this->_parts['FILE_DATA']->_getFilePath(); if (!unlink($file)) { throwError(new Error(RepositoryException::OPERATION_FAILED() . ": '{$file}' could not be deleted.", "FileSystemFileRecord", true)); } // Delete the thumbnail $query = new DeleteQuery(); $query->setTable("dr_thumbnail"); $query->setWhere("fk_file = '" . $this->_id->getIdString() . "'"); $dbHandler->query($query, $this->_configuration->getProperty("database_index")); // Delete the data row in case we were switching from another type // that used it. $query = new DeleteQuery(); $query->setTable("dr_file_data"); $query->setWhere("fk_file = '" . $this->_id->getIdString() . "'"); $dbHandler->query($query, $this->_configuration->getProperty("database_index")); // delete the file row. $query = new DeleteQuery(); $query->setTable("dr_file"); $query->setWhere("id = '" . $this->_id->getIdString() . "'"); $dbHandler->query($query, $this->_configuration->getProperty("database_index")); } else { if ($field != "FILE_SIZE") { $this->_parts[$field]->updateValue("NULL"); } } } else { throwError(new Error(RepositoryException::UNKNOWN_ID() . ": {$string}", "FileSystemFileRecord", true)); } }
/** * Update the value for this Part. * * @param object mixed $value (original type: java.io.Serializable) * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT} * * @access public */ function updateValue($value) { $file = $this->_getFilePath(); if (!($handle = fopen($file, 'w'))) { throwError(new Error(RepositoryException::OPERATION_FAILED() . ": '{$file}' could not be opened for writing.", "FileSystemFileDataPart", true)); } if (fwrite($handle, $value) === FALSE) { fclose($handle); throwError(new Error(RepositoryException::OPERATION_FAILED() . ": '{$file}' could not be written to.", "FileSystemFileDataPart", true)); } fclose($handle); // Check to see if the size is in the database $dbHandler = Services::getService("DatabaseManager"); $query = new SelectQuery(); $query->addTable("dr_file"); $query->addColumn("COUNT(*) as count"); $query->addWhere("id = '" . $this->_recordId->getIdString() . "'"); $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index")); // If it already exists, use an update query. if ($result->field("count") > 0) { $query = new UpdateQuery(); $query->setTable("dr_file"); $query->setColumns(array("size")); $query->setValues(array("'" . strlen($value) . "'")); $query->addWhere("id = '" . $this->_recordId->getIdString() . "'"); } else { $query = new InsertQuery(); $query->setTable("dr_file"); $query->setColumns(array("id", "size")); $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . strlen($value) . "'")); } $result->free(); // run the query $dbHandler->query($query, $this->_configuration->getProperty("database_index")); $this->_asset->updateModificationDate(); }
/** * Get the RecordStructure associated with this Asset's content. * * @return object RecordStructure * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED} * * @access public */ function getContentRecordStructure() { $idManager = Services::getService("Id"); $schemaMgr = Services::getService("SchemaManager"); $recordStructures = $this->_repository->getRecordStructures(); // Get the id of the Content DataSetTypeDef $contentType = "edu.middlebury.harmoni.repository.asset_content"; $contentTypeId = $idManager->getId($contentType); while ($recordStructures->hasNext()) { $structure = $recordStructures->next(); if ($contentTypeId->isEqual($structure->getId())) { return $structure; } } throwError(new Error(RepositoryException::OPERATION_FAILED(), "Repository :: Asset", TRUE)); }
/** * Delete a RecordStructure all Records in the repository that use it. * * WARNING: NOT IN OSID * * @param object Id $recordStructureId * @return void * @access public * @since 6/6/06 */ function deleteRecordStructure(Id $recordStructureId, $statusStars = null) { // Delete the Records that use this RecordStructure $assets = $this->getAssets(); if (!is_null($statusStars)) { $statusStars->initializeStatistics($assets->count()); } while ($assets->hasNext()) { $asset = $assets->next(); $records = $asset->getRecordsByRecordStructure($recordStructureId); while ($records->hasNext()) { $record = $records->next(); $asset->deleteRecord($record->getId()); } if (!is_null($statusStars)) { $statusStars->updateStatistics(); } } // Delete the Structure $schemaMgr = Services::getService("SchemaManager"); $recordMgr = Services::getService("RecordManager"); $recordIdsForSchema = $recordMgr->getRecordIDsByType($recordStructureId->getIdString()); if (count($recordIdsForSchema)) { throwError(new Error(RepositoryException::OPERATION_FAILED() . " when deleting RecordStructure: '" . $recordStructureId->getIdString() . "', Records exist for this RecordStructure.", "Repository", 1)); } $schema = $schemaMgr->deleteSchema($recordStructureId->getIdString()); }
/** * Delete a PartStucture * * @param object Id $partStructureId * @return void * @access public * @since 6/8/06 */ function deletePartStructure(Id $partStructureId) { // Delete the Structure $schemaMgr = Services::getService("SchemaManager"); $recordMgr = Services::getService("RecordManager"); $partStructure = $this->getPartStructure($partStructureId); $dummyValues = array(String::withValue('4000-02-05')); $recordIdsWithValues = $recordMgr->getRecordSetIDsBySearch(new FieldValueSearch($this->_schema->getID(), $this->_schema->getFieldLabelFromID($partStructureId->getIdString()), new HarmoniIterator($dummyValues), SEARCH_TYPE_NOT_IN_LIST)); if (count($recordIdsWithValues)) { throwError(new Error(RepositoryException::OPERATION_FAILED() . " when deleting RecordStructure: '" . $recordStructureId->getIdString() . "', Records exist for this RecordStructure.", "Repository", 1)); } $sm = Services::getService("SchemaManager"); $this->_schema->deleteField($partStructureId->getIdString()); $sm->synchronize($this->_schema); $partStructure = null; }