示例#1
0
 static function removeByID($id, $version)
 {
     if ($version == null) {
         eZPersistentObject::removeObject(eZMedia::definition(), array("contentobject_attribute_id" => $id));
     } else {
         eZPersistentObject::removeObject(eZMedia::definition(), array("contentobject_attribute_id" => $id, "version" => $version));
     }
 }
 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;
 }
    /**
     * 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 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;
 }
示例#5
0
 function unserializeContentObjectAttribute($package, $objectAttribute, $attributeNode)
 {
     $mediaNode = $attributeNode->getElementsByTagName('media-file')->item(0);
     if (!$mediaNode) {
         // No media type data found.
         return;
     }
     $mediaFile = eZMedia::create($objectAttribute->attribute('id'), $objectAttribute->attribute('version'));
     $sourcePath = $package->simpleFilePath($mediaNode->getAttribute('filekey'));
     $ini = eZINI::instance();
     $mimeType = $mediaNode->getAttribute('mime-type');
     list($mimeTypeCategory, $mimeTypeName) = explode('/', $mimeType);
     $destinationPath = eZSys::storageDirectory() . '/original/' . $mimeTypeCategory . '/';
     if (!file_exists($destinationPath)) {
         if (!eZDir::mkdir($destinationPath, false, true)) {
             return false;
         }
     }
     $basename = basename($mediaNode->getAttribute('filename'));
     while (file_exists($destinationPath . $basename)) {
         $basename = substr(md5(mt_rand()), 0, 8) . '.' . eZFile::suffix($mediaNode->getAttribute('filename'));
     }
     eZFileHandler::copy($sourcePath, $destinationPath . $basename);
     eZDebug::writeNotice('Copied: ' . $sourcePath . ' to: ' . $destinationPath . $basename, __METHOD__);
     $mediaFile->setAttribute('contentobject_attribute_id', $objectAttribute->attribute('id'));
     $mediaFile->setAttribute('filename', $basename);
     $mediaFile->setAttribute('original_filename', $mediaNode->getAttribute('original-filename'));
     $mediaFile->setAttribute('mime_type', $mediaNode->getAttribute('mime-type'));
     $mediaFile->setAttribute('width', $mediaNode->getAttribute('width'));
     $mediaFile->setAttribute('height', $mediaNode->getAttribute('height'));
     $mediaFile->setAttribute('has_controller', $mediaNode->getAttribute('has-controller'));
     $mediaFile->setAttribute('controls', $mediaNode->getAttribute('controls'));
     $mediaFile->setAttribute('is_autoplay', $mediaNode->getAttribute('is-autoplay'));
     $mediaFile->setAttribute('pluginspage', $mediaNode->getAttribute('plugins-page'));
     $mediaFile->setAttribute('quality', $mediaNode->getAttribute('quality'));
     $mediaFile->setAttribute('is_loop', $mediaNode->getAttribute('is-loop'));
     $fileHandler = eZClusterFileHandler::instance();
     $fileHandler->fileStore($destinationPath . $basename, 'mediafile', true);
     $mediaFile->store();
 }