/** * Regression test for issue #14983 * * @link http://issues.ez.no/14983 */ public function testIssue14983() { $className = 'eZBinaryFileType test class'; $classIdentifier = 'ezbinaryfiletype_test_class'; $attributeName = 'File'; $attributeIdentifier = 'file'; $attributeType = 'ezbinaryfile'; $filePath = 'tests/tests/kernel/datatypes/ezbinaryfile/ezbinaryfiletype_regression_issue14983.txt'; $class = new ezpClass( $className, $classIdentifier, $className ); $classAttribute = $class->add( $attributeName, $attributeIdentifier, $attributeType ); $class->store(); $object = new ezpObject( $classIdentifier, 2 ); $object->name = __FUNCTION__; { $dataMap = $object->object->dataMap(); $fileAttribute = $dataMap[$attributeIdentifier]; { $dataType = new eZBinaryFileType(); $dataType->fromString( $fileAttribute, $filePath ); } $fileAttribute->store(); } $object->publish(); $object->refresh(); $contentObjectAttributeID = $fileAttribute->attribute( "id" ); $files = eZBinaryFile::fetch( $contentObjectAttributeID ); foreach ( $files as $file ) { // Read stored path, move to trash, and read stored path again $this->assertNotEquals( $file, null ); $storedFileInfo = $file->storedFileInfo(); $storedFilePath = $storedFileInfo['filepath']; $version = $file->attribute( 'version' ); $object->object->removeThis(); $object->refresh(); $file = eZBinaryFile::fetch( $contentObjectAttributeID, $version ); $storedFileInfo = $file->storedFileInfo(); $storedFilePathAfterTrash = $storedFileInfo['filepath']; $this->assertNotEquals( $storedFilePath, $storedFilePathAfterTrash, 'The stored file should be renamed when trashed' ); } }
/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return json encoded string for further processing * required first level elements 'method', 'version_format', 'data_type_identifier', 'content' * optional first level element is 'rendered' which should store (template) rendered xhtml snippets */ public static function getAttributeContent(eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute) { $dataTypeIdentifier = $contentObjectAttribute->attribute('data_type_string'); $attributeID = $contentObjectAttribute->attribute("id"); $version = $contentObjectAttribute->attribute("version"); if (!$contentObjectAttribute->hasContent()) { $content = null; } else { $binaryFile = eZBinaryFile::fetch($attributeID, $version); $content = $binaryFile->storedFileInfo(); } // This is not really the place, but for now initiate the safeguarding of the file itself here $archiveFileHandler = ezpFileArchiveFactory::getFileArchiveHandler('filesystem'); // todo: insert check if handler is really returned and of the right class before calling the archive action // maybe use the attribute id as prefix as well, may be useful for bookkeeping/recovery and potentially easier restore as well $archiveResult = $archiveFileHandler->archiveFile($content['filepath'], array($content['filepath']), $attributeID, 'ezbinaryfile'); $target = array('content' => $content, 'has_rendered_content' => false, 'rendered' => null, 'archived' => true, 'archive' => $archiveResult); return $target; }
function downloadFileObject($contentObject, $contentObjectAttribute) { $contentObjectAttributeID = $contentObjectAttribute->attribute('id'); $version = $contentObject->attribute('current_version'); $fileObject = eZBinaryFile::fetch($contentObjectAttributeID, $version); if ($fileObject) { return $fileObject; } $fileObject = eZMedia::fetch($contentObjectAttributeID, $version); return $fileObject; }
function downloadType($contentObject, $contentObjectAttribute) { $contentObjectAttributeID = $contentObjectAttribute->attribute('id'); $version = $contentObject->attribute('current_version'); $fileObject = eZBinaryFile::fetch($contentObjectAttributeID, $version); if ($fileObject) { return self::TYPE_FILE; } $fileObject = eZMedia::fetch($contentObjectAttributeID, $version); if ($fileObject) { return self::TYPE_MEDIA; } return false; }
function objectAttributeContent( $contentObjectAttribute ) { $binaryFile = eZBinaryFile::fetch( $contentObjectAttribute->attribute( "id" ), $contentObjectAttribute->attribute( "version" ) ); if ( !$binaryFile ) { $attrValue = false; return $attrValue; } return $binaryFile; }