/** * Regression test for issue 16400 * @link http://issues.ez.no/16400 * @return unknown_type */ public function testIssue16400() { $className = 'Media test class'; $classIdentifier = 'media_test_class'; $filePath = 'tests/tests/kernel/datatypes/ezmedia/ezmediatype_regression_issue16400.flv'; eZFile::create( $filePath ); $attributeName = 'Media'; $attributeIdentifier = 'media'; $attributeType = 'ezmedia'; //1. test method fetchByContentObjectID $class = new ezpClass( $className, $classIdentifier, $className ); $class->add( $attributeName, $attributeIdentifier, $attributeType ); $attribute = $class->class->fetchAttributeByIdentifier( $attributeIdentifier ); $attribute->setAttribute( 'can_translate', 0 ); $class->store(); $object = new ezpObject( $classIdentifier, 2 ); $dataMap = $object->object->dataMap(); $fileAttribute = $dataMap[$attributeIdentifier]; $dataType = new eZMediaType(); $dataType->fromString( $fileAttribute, $filePath ); $fileAttribute->store(); $object->publish(); $object->refresh(); //verify fetchByContentObjectID $mediaObject = eZMedia::fetch( $fileAttribute->attribute( 'id' ), 1 ); $medias = eZMedia::fetchByContentObjectID( $object->object->attribute( 'id' ) ); $this->assertEquals( $mediaObject->attribute( 'filename' ), $medias[0]->attribute( 'filename' ) ); $medias = eZMedia::fetchByContentObjectID( $object->object->attribute( 'id' ), $fileAttribute->attribute( 'language_code' ) ); $this->assertEquals( $mediaObject->attribute( 'filename' ), $medias[0]->attribute( 'filename' ) ); //2. test issue // create translation $contentObject = $object->object; $storedFileName = $mediaObject->attribute( 'filename' ); $version = $contentObject->createNewVersionIn( 'nor-NO', $fileAttribute->attribute( 'language_code' ) ); $version->setAttribute( 'status', eZContentObjectVersion::STATUS_INTERNAL_DRAFT ); $version->store(); $version->removeThis(); $sys = eZSys::instance(); $dir = $sys->storageDirectory(); //verify the file is deleted $storedFilePath = $dir . '/original/video/' . $storedFileName; $file = eZClusterFileHandler::instance( $storedFilePath ); $this->assertTrue( $file->exists( $storedFilePath ) ); if ( $file->exists( $storedFilePath ) ) unlink( $storedFilePath ); }
function deleteStoredObjectAttribute($contentObjectAttribute, $version = null) { $contentObjectAttributeID = $contentObjectAttribute->attribute("id"); $sys = eZSys::instance(); $storage_dir = $sys->storageDirectory(); if ($version == null) { $mediaFiles = eZMedia::fetch($contentObjectAttributeID, null); foreach ($mediaFiles as $mediaFile) { $mimeType = $mediaFile->attribute("mime_type"); list($prefix, $suffix) = explode('/', $mimeType); // $orig_dir = "var/storage/original/" . $prefix; $orig_dir = $storage_dir . '/original/' . $prefix; $fileName = $mediaFile->attribute("filename"); if ($fileName == '') { continue; } $file = eZClusterFileHandler::instance($orig_dir . "/" . $fileName); if ($file->exists()) { $file->delete(); } } } else { $mediaFiles = eZMedia::fetchByContentObjectID($contentObjectAttribute->attribute('contentobject_id')); $count = 0; $currentBinaryFile = eZMedia::fetch($contentObjectAttributeID, $version); if ($currentBinaryFile != null) { $mimeType = $currentBinaryFile->attribute("mime_type"); $currentFileName = $currentBinaryFile->attribute("filename"); list($prefix, $suffix) = is_string($mimeType) && $mimeType ? explode('/', $mimeType) : array(null, null); // $orig_dir = "var/storage/original/" . $prefix; $orig_dir = $storage_dir . '/original/' . $prefix; foreach ($mediaFiles as $mediaFile) { $fileName = $mediaFile->attribute("filename"); if ($currentFileName == $fileName) { $count += 1; } } if ($count == 1 && $currentFileName != '') { $file = eZClusterFileHandler::instance($orig_dir . "/" . $currentFileName); if ($file->exists()) { $file->delete(); } } } } eZMedia::removeByID($contentObjectAttributeID, $version); }