public function createMediaInstance($fileSource, $classUri, $language, $label = null, $mimeType = null, $userId = null)
    {
        $clazz = $this->getClass($classUri);

        //create media instance
        if (is_null($label)) {
            $label = $fileSource instanceof File ? $fileSource->getBasename() : basename($fileSource);
        }
        $md5 = $fileSource instanceof File ? md5($fileSource->read()) : md5_file($fileSource);

        $link = $this->getFileManager()->storeFile($fileSource, $label);

        if ($link !== false) {
            if (is_null($mimeType)) {
                $mimeType = $fileSource instanceof File ? $fileSource->getMimeType() : \tao_helpers_File::getMimeType($fileSource);
            }
            $instance = $clazz->createInstanceWithProperties(array(
                OntologyRdfs::RDFS_LABEL => $label,
                self::PROPERTY_LINK => $link,
                self::PROPERTY_LANGUAGE => $language,
                self::PROPERTY_MD5 => $md5,
                self::PROPERTY_MIME_TYPE => $mimeType,
                self::PROPERTY_ALT_TEXT => $label
            ));

            if ($this->getServiceLocator()->get(common_ext_ExtensionsManager::SERVICE_ID)->isEnabled('taoRevision')) {
                \common_Logger::i('Auto generating initial revision');
                $this->getServiceLocator()->get(Repository::SERVICE_ID)->commit($instance->getUri(), __('Initial import'), null, $userId);
            }
            return $instance->getUri();
        }
        return false;
    }
public function createMediaInstance($fileSource, $classUri, $language, $label = null, $mimeType = null, $userId = null)
    {
        $clazz = $this->getClass($classUri);

        //create media instance
        if (is_null($label)) {
            $label = $fileSource instanceof File ? $fileSource->getBasename() : basename($fileSource);
        }
        $md5 = $fileSource instanceof File ? md5($fileSource->read()) : md5_file($fileSource);

        $link = $this->getFileManager()->storeFile($fileSource, $label);

        if ($link !== false) {
            if (is_null($mimeType)) {
                $mimeType = $fileSource instanceof File ? $fileSource->getMimeType() : \tao_helpers_File::getMimeType($fileSource);
            }
            $instance = $clazz->createInstanceWithProperties(array(
                OntologyRdfs::RDFS_LABEL => $label,
                self::PROPERTY_LINK => $link,
                self::PROPERTY_LANGUAGE => $language,
                self::PROPERTY_MD5 => $md5,
                self::PROPERTY_MIME_TYPE => $mimeType,
                self::PROPERTY_ALT_TEXT => $label
            ));

            if ($this->getServiceLocator()->get(common_ext_ExtensionsManager::SERVICE_ID)->isEnabled('taoRevision')) {
                \common_Logger::i('Auto generating initial revision');
                $this->getServiceLocator()->get(Repository::SERVICE_ID)->commit($instance->getUri(), __('Initial import'), null, $userId);
            }
            return $instance->getUri();
        }
        return false;
    }
public function createMediaInstance ( $ fileSource , $ classUri , $ language , $ label = null , $ mimeType = null , $ userId = null ) { $ clazz = $ this -> getClass ( $ classUri ) ; //create media instance if ( is_null ( $ label ) ) { $ label = $ fileSource instanceof File ? $ fileSource -> getBasename ( ) : basename ( $ fileSource ) ; } $ md5 = $ fileSource instanceof File ? md5 ( $ fileSource -> read ( ) ) : md5_file ( $ fileSource ) ; $ link = $ this -> getFileManager ( ) -> storeFile ( $ fileSource , $ label ) ; if ( $ link !== false ) { if ( is_null ( $ mimeType ) ) { $ mimeType = $ fileSource instanceof File ? $ fileSource -> getMimeType ( ) : \ tao_helpers_File :: getMimeType ( $ fileSource ) ; } $ instance = $ clazz -> createInstanceWithProperties ( array ( OntologyRdfs :: RDFS_LABEL => $ label , self :: PROPERTY_LINK => $ link , self :: PROPERTY_LANGUAGE => $ language , self :: PROPERTY_MD5 => $ md5 , self :: PROPERTY_MIME_TYPE => $ mimeType , self :: PROPERTY_ALT_TEXT => $ label ) ) ; if ( $ this -> getServiceLocator ( ) -> get ( common_ext_ExtensionsManager :: SERVICE_ID ) -> isEnabled ( 'taoRevision' ) ) { \ common_Logger :: i ( 'Auto generating initial revision' ) ; $ this -> getServiceLocator ( ) -> get ( Repository :: SERVICE_ID ) -> commit ( $ instance -> getUri ( ) , __ ( 'Initial import' ) , null , $ userId ) ; } return $ instance -> getUri ( ) ; } return false ; }
Create a media instance from a file, and define its class and language

@param string|File $fileSource path to the file to create instance from
@param string $classUri parent to add the instance to
@param string $language language of the content
@param string $label label of the instance
@param string $mimeType mimeType of the file
@param string|null $userId owner of the resource
@return string | bool $instanceUri or false on error
Create a media instance from a file and define its class and language