/**
  * 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);
     }
 }
Ejemplo n.º 2
0
 function insertRegularFile($object, $objectVersion, $objectLanguage, $objectAttribute, $filePath, &$result)
 {
     $result = array('errors' => array(), 'require_storage' => false);
     $attributeID = $objectAttribute->attribute('id');
     $media = eZMedia::fetch($attributeID, $objectVersion);
     if ($media === null) {
         $media = eZMedia::create($attributeID, $objectVersion);
     }
     $fileName = basename($filePath);
     $mimeData = eZMimeType::findByFileContents($filePath);
     $storageDir = eZSys::storageDirectory();
     list($group, $type) = explode('/', $mimeData['name']);
     $destination = $storageDir . '/original/' . $group;
     if (!file_exists($destination)) {
         if (!eZDir::mkdir($destination, false, true)) {
             return false;
         }
     }
     // create dest filename in the same manner as eZHTTPFile::store()
     // grab file's suffix
     $fileSuffix = eZFile::suffix($fileName);
     // prepend dot
     if ($fileSuffix) {
         $fileSuffix = '.' . $fileSuffix;
     }
     // grab filename without suffix
     $fileBaseName = basename($fileName, $fileSuffix);
     // create dest filename
     $destFileName = md5($fileBaseName . microtime() . mt_rand()) . $fileSuffix;
     $destination = $destination . '/' . $destFileName;
     copy($filePath, $destination);
     $fileHandler = eZClusterFileHandler::instance();
     $fileHandler->fileStore($destination, 'mediafile', true, $mimeData['name']);
     $classAttribute = $objectAttribute->contentClassAttribute();
     $player = $classAttribute->attribute("data_text1");
     $pluginPage = eZMediaType::pluginPage($player);
     $media->setAttribute("contentobject_attribute_id", $attributeID);
     $media->setAttribute("version", $objectVersion);
     $media->setAttribute("filename", $destFileName);
     $media->setAttribute("original_filename", $fileName);
     $media->setAttribute("mime_type", $mimeData['name']);
     // Setting width and height to zero means that the browser/player must find the size itself.
     // In the future we will probably analyze the media file and find this information
     $width = $height = 0;
     // Quality is not known, so we don't set any
     $quality = false;
     // Not sure what this is for, set to false
     $controls = false;
     // We want to show controllers by default
     $hasController = true;
     // Don't play automatically
     $isAutoplay = false;
     // Don't loop movie
     $isLoop = false;
     $media->setAttribute("width", $width);
     $media->setAttribute("height", $height);
     $media->setAttribute("quality", $quality);
     $media->setAttribute("controls", $controls);
     $media->setAttribute("pluginspage", $pluginPage);
     $media->setAttribute("is_autoplay", $isAutoplay);
     $media->setAttribute("has_controller", $hasController);
     $media->setAttribute("is_loop", $isLoop);
     $media->store();
     $objectAttribute->setContent($media);
     return true;
 }