kernel/classes/ezpackage.php
static function import( $archiveName, &$packageName, $dbAvailable = true, $repositoryID = false )
    {
        if ( is_dir( $archiveName ) )
        {
            eZDebug::writeError( "Importing from directory is not supported." );
            $retValue = false;
            return $retValue;
        }
        else
        {
            $tempDirPath = eZPackage::temporaryImportPath();
            // make a temporary directory to extract the package file to
            do
            {
                $archivePath = eZDir::path( array( $tempDirPath, mt_rand() ) );
            } while ( file_exists( $archivePath ) );

            eZDir::mkdir( $archivePath, false, true );

            $archiveOptions = new ezcArchiveOptions( array( 'readOnly' => true ) );

            // Fix for issue #15891: ezjscore - file names are cutted
            // Force the type of the archive as ezcArchive::TAR_GNU so that long file names are supported on Windows
            // The previous value for the second parameter was null which meant the type was guessed from the
            // archive, but on Windows it was detected as TAR_USTAR and this lead to filenames being limited
            // to 100 characters
            $archive = ezcArchive::open( "compress.zlib://$archiveName", ezcArchive::TAR_GNU, $archiveOptions );

            $fileList = array();
            $fileList[] = eZPackage::definitionFilename();

            // Search for the files we want to extract
            foreach( $archive as $entry )
            {
                if ( in_array( $entry->getPath(), $fileList ) )
                {
                    if ( !$archive->extractCurrent( $archivePath ) )
                    {
                        eZDebug::writeError( "Failed extracting package definition file from $archivePath" );
                        return false;
                    }
                }
            }

            $definitionFileName = eZDir::path( array( $archivePath, self::definitionFilename() ) );

            $package = eZPackage::fetchFromFile( $definitionFileName );

            eZPackage::removeFiles( $archivePath );

            if ( $package )
            {
                $packageName = $package->attribute( 'name' );

                if ( !self::isValidName( $packageName ) )
                {
                    return eZPackage::STATUS_INVALID_NAME;
                }

                if ( !$repositoryID )
                {
                    $repositoryID = $package->attribute( 'vendor-dir' );
                }

                $existingPackage = eZPackage::fetch( $packageName, false, false, $dbAvailable );
                if ( $existingPackage )
                {
                    return eZPackage::STATUS_ALREADY_EXISTS;
                }

                unset( $package );

                $fullRepositoryPath = eZPackage::repositoryPath() . '/' . $repositoryID;
                $packagePath = $fullRepositoryPath . '/' . $packageName;
                if ( !file_exists( $packagePath ) )
                {
                    eZDir::mkdir( $packagePath, false, true );
                }
                $archive->extract( $packagePath );

                $package = eZPackage::fetch( $packageName, $fullRepositoryPath, false, $dbAvailable );
                if ( !$package )
                {
                    eZDebug::writeError( "Failed loading imported package $packageName from $fullRepositoryPath" );
                }
            }
            else
            {
                eZDebug::writeError( "Failed loading temporary package $packageName" );
            }

            return $package;
        }
    }
static function import( $archiveName, &$packageName, $dbAvailable = true, $repositoryID = false )
    {
        if ( is_dir( $archiveName ) )
        {
            eZDebug::writeError( "Importing from directory is not supported." );
            $retValue = false;
            return $retValue;
        }
        else
        {
            $tempDirPath = eZPackage::temporaryImportPath();
            // make a temporary directory to extract the package file to
            do
            {
                $archivePath = eZDir::path( array( $tempDirPath, mt_rand() ) );
            } while ( file_exists( $archivePath ) );

            eZDir::mkdir( $archivePath, false, true );

            $archiveOptions = new ezcArchiveOptions( array( 'readOnly' => true ) );

            // Fix for issue #15891: ezjscore - file names are cutted
            // Force the type of the archive as ezcArchive::TAR_GNU so that long file names are supported on Windows
            // The previous value for the second parameter was null which meant the type was guessed from the
            // archive, but on Windows it was detected as TAR_USTAR and this lead to filenames being limited
            // to 100 characters
            $archive = ezcArchive::open( "compress.zlib://$archiveName", ezcArchive::TAR_GNU, $archiveOptions );

            $fileList = array();
            $fileList[] = eZPackage::definitionFilename();

            // Search for the files we want to extract
            foreach( $archive as $entry )
            {
                if ( in_array( $entry->getPath(), $fileList ) )
                {
                    if ( !$archive->extractCurrent( $archivePath ) )
                    {
                        eZDebug::writeError( "Failed extracting package definition file from $archivePath" );
                        return false;
                    }
                }
            }

            $definitionFileName = eZDir::path( array( $archivePath, self::definitionFilename() ) );

            $package = eZPackage::fetchFromFile( $definitionFileName );

            eZPackage::removeFiles( $archivePath );

            if ( $package )
            {
                $packageName = $package->attribute( 'name' );

                if ( !self::isValidName( $packageName ) )
                {
                    return eZPackage::STATUS_INVALID_NAME;
                }

                if ( !$repositoryID )
                {
                    $repositoryID = $package->attribute( 'vendor-dir' );
                }

                $existingPackage = eZPackage::fetch( $packageName, false, false, $dbAvailable );
                if ( $existingPackage )
                {
                    return eZPackage::STATUS_ALREADY_EXISTS;
                }

                unset( $package );

                $fullRepositoryPath = eZPackage::repositoryPath() . '/' . $repositoryID;
                $packagePath = $fullRepositoryPath . '/' . $packageName;
                if ( !file_exists( $packagePath ) )
                {
                    eZDir::mkdir( $packagePath, false, true );
                }
                $archive->extract( $packagePath );

                $package = eZPackage::fetch( $packageName, $fullRepositoryPath, false, $dbAvailable );
                if ( !$package )
                {
                    eZDebug::writeError( "Failed loading imported package $packageName from $fullRepositoryPath" );
                }
            }
            else
            {
                eZDebug::writeError( "Failed loading temporary package $packageName" );
            }

            return $package;
        }
    }
static function import ( $ archiveName , & $ packageName , $ dbAvailable = true , $ repositoryID = false ) { if ( is_dir ( $ archiveName ) ) { eZDebug :: writeError ( "Importing from directory is not supported." ) ; $ retValue = false ; return $ retValue ; } else { $ tempDirPath = eZPackage :: temporaryImportPath ( ) ; // make a temporary directory to extract the package file to do { $ archivePath = eZDir :: path ( array ( $ tempDirPath , mt_rand ( ) ) ) ; } while ( file_exists ( $ archivePath ) ) ; eZDir :: mkdir ( $ archivePath , false , true ) ; $ archiveOptions = new ezcArchiveOptions ( array ( 'readOnly' => true ) ) ; // Fix for issue #15891: ezjscore - file names are cutted // Force the type of the archive as ezcArchive::TAR_GNU so that long file names are supported on Windows // The previous value for the second parameter was null which meant the type was guessed from the // archive, but on Windows it was detected as TAR_USTAR and this lead to filenames being limited // to 100 characters $ archive = ezcArchive :: open ( "compress.zlib://$archiveName" , ezcArchive :: TAR_GNU , $ archiveOptions ) ; $ fileList = array ( ) ; $ fileList [ ] = eZPackage :: definitionFilename ( ) ; // Search for the files we want to extract foreach ( $ archive as $ entry ) { if ( in_array ( $ entry -> getPath ( ) , $ fileList ) ) { if ( ! $ archive -> extractCurrent ( $ archivePath ) ) { eZDebug :: writeError ( "Failed extracting package definition file from $archivePath" ) ; return false ; } } } $ definitionFileName = eZDir :: path ( array ( $ archivePath , self :: definitionFilename ( ) ) ) ; $ package = eZPackage :: fetchFromFile ( $ definitionFileName ) ; eZPackage :: removeFiles ( $ archivePath ) ; if ( $ package ) { $ packageName = $ package -> attribute ( 'name' ) ; if ( ! self :: isValidName ( $ packageName ) ) { return eZPackage :: STATUS_INVALID_NAME ; } if ( ! $ repositoryID ) { $ repositoryID = $ package -> attribute ( 'vendor-dir' ) ; } $ existingPackage = eZPackage :: fetch ( $ packageName , false , false , $ dbAvailable ) ; if ( $ existingPackage ) { return eZPackage :: STATUS_ALREADY_EXISTS ; } unset ( $ package ) ; $ fullRepositoryPath = eZPackage :: repositoryPath ( ) . '/' . $ repositoryID ; $ packagePath = $ fullRepositoryPath . '/' . $ packageName ; if ( ! file_exists ( $ packagePath ) ) { eZDir :: mkdir ( $ packagePath , false , true ) ; } $ archive -> extract ( $ packagePath ) ; $ package = eZPackage :: fetch ( $ packageName , $ fullRepositoryPath , false , $ dbAvailable ) ; if ( ! $ package ) { eZDebug :: writeError ( "Failed loading imported package $packageName from $fullRepositoryPath" ) ; } } else { eZDebug :: writeError ( "Failed loading temporary package $packageName" ) ; } return $ package ; } }
Imports a package from a gzip compressed tarball file

@param string $archiveName Path to the archive file
@param string $packageName Package name
@param bool $dbAvailable
@param bool $repositoryID

@return eZPackage The eZPackage object if successfull, or one of the
STATUS_* class constants if an error occurs
Imports a package from a gzip compressed tarball file