protected function storeFiles()
    {
        $items = $this->package->getStorageServices();
        $stored = false;

        foreach ($items as $service => $resources) {
            if (is_string($resources)) {
                $resources = explode(',', $resources);
            }

            try {
                /** @type FileServiceInterface $storage */
                $storage = ServiceManager::getService($service);
                foreach ($resources as $resource) {
                    try {
                        // checkServicePermission throws exception below if action not allowed for the user.
                        Session::checkServicePermission(
                            Verbs::POST, $service, trim($resource, '/'),
                            Session::getRequestor()
                        );

                        $resourcePath = $service . '/' . ltrim($resource, '/');
                        $file = $this->package->getFileFromZip($resourcePath);
                        if (!empty($file)) {
                            $storage->moveFile(ltrim($resource, '/'), $file, true);
                        } else {
                            $resourcePath = $service . '/' . trim($resource, '/') . '/' . md5($resource) . '.zip';
                            $zip = $this->package->getZipFromZip($resourcePath);
                            if (!empty($zip)) {
                                $storage->extractZipFile(
                                    rtrim($resource, '/') . '/',
                                    $zip,
                                    false,
                                    rtrim($resource, '/') . '/'
                                );
                            }
                        }
                        $stored = true;
                    } catch (\Exception $e) {
                        // Not throwing exceptions here. File storage process is not
                        // transactional. There is no way to rollback if exception
                        // is thrown in the middle of import process. Instead, log
                        // the error and finish the process.
                        $logLevel = 'warning';
                        if ($e->getCode() === HttpStatusCodes::HTTP_FORBIDDEN) {
                            $logLevel = 'error';
                        }
                        $this->log(
                            $logLevel,
                            'Skipping storage resource ' . $service . '/' . $resource . '. ' . $e->getMessage()
                        );
                    }
                }
            } catch (\Exception $e) {
                $this->log('error', 'Failed to store files for service ' . $service . '. ' . $e->getMessage());
            }
        }

        return $stored;
    }
protected function storeFiles()
    {
        $items = $this->package->getStorageServices();
        $stored = false;

        foreach ($items as $service => $resources) {
            if (is_string($resources)) {
                $resources = explode(',', $resources);
            }

            try {
                /** @type FileServiceInterface $storage */
                $storage = ServiceManager::getService($service);
                foreach ($resources as $resource) {
                    try {
                        // checkServicePermission throws exception below if action not allowed for the user.
                        Session::checkServicePermission(
                            Verbs::POST, $service, trim($resource, '/'),
                            Session::getRequestor()
                        );

                        $resourcePath = $service . '/' . ltrim($resource, '/');
                        $file = $this->package->getFileFromZip($resourcePath);
                        if (!empty($file)) {
                            $storage->moveFile(ltrim($resource, '/'), $file, true);
                        } else {
                            $resourcePath = $service . '/' . trim($resource, '/') . '/' . md5($resource) . '.zip';
                            $zip = $this->package->getZipFromZip($resourcePath);
                            if (!empty($zip)) {
                                $storage->extractZipFile(
                                    rtrim($resource, '/') . '/',
                                    $zip,
                                    false,
                                    rtrim($resource, '/') . '/'
                                );
                            }
                        }
                        $stored = true;
                    } catch (\Exception $e) {
                        // Not throwing exceptions here. File storage process is not
                        // transactional. There is no way to rollback if exception
                        // is thrown in the middle of import process. Instead, log
                        // the error and finish the process.
                        $logLevel = 'warning';
                        if ($e->getCode() === HttpStatusCodes::HTTP_FORBIDDEN) {
                            $logLevel = 'error';
                        }
                        $this->log(
                            $logLevel,
                            'Skipping storage resource ' . $service . '/' . $resource . '. ' . $e->getMessage()
                        );
                    }
                }
            } catch (\Exception $e) {
                $this->log('error', 'Failed to store files for service ' . $service . '. ' . $e->getMessage());
            }
        }

        return $stored;
    }
protected function storeFiles ( ) { $ items = $ this -> package -> getStorageServices ( ) ; $ stored = false ; foreach ( $ items as $ service => $ resources ) { if ( is_string ( $ resources ) ) { $ resources = explode ( ',' , $ resources ) ; } try { /** @type FileServiceInterface $storage */ $ storage = ServiceManager :: getService ( $ service ) ; foreach ( $ resources as $ resource ) { try { // checkServicePermission throws exception below if action not allowed for the user. Session :: checkServicePermission ( Verbs :: POST , $ service , trim ( $ resource , '/' ) , Session :: getRequestor ( ) ) ; $ resourcePath = $ service . '/' . ltrim ( $ resource , '/' ) ; $ file = $ this -> package -> getFileFromZip ( $ resourcePath ) ; if ( ! empty ( $ file ) ) { $ storage -> moveFile ( ltrim ( $ resource , '/' ) , $ file , true ) ; } else { $ resourcePath = $ service . '/' . trim ( $ resource , '/' ) . '/' . md5 ( $ resource ) . '.zip' ; $ zip = $ this -> package -> getZipFromZip ( $ resourcePath ) ; if ( ! empty ( $ zip ) ) { $ storage -> extractZipFile ( rtrim ( $ resource , '/' ) . '/' , $ zip , false , rtrim ( $ resource , '/' ) . '/' ) ; } } $ stored = true ; } catch ( \ Exception $ e ) { // Not throwing exceptions here. File storage process is not // transactional. There is no way to rollback if exception // is thrown in the middle of import process. Instead, log // the error and finish the process. $ logLevel = 'warning' ; if ( $ e -> getCode ( ) === HttpStatusCodes :: HTTP_FORBIDDEN ) { $ logLevel = 'error' ; } $ this -> log ( $ logLevel , 'Skipping storage resource ' . $ service . '/' . $ resource . '. ' . $ e -> getMessage ( ) ) ; } } } catch ( \ Exception $ e ) { $ this -> log ( 'error' , 'Failed to store files for service ' . $ service . '. ' . $ e -> getMessage ( ) ) ; } } return $ stored ; }
Imports app files or other storage files from package.
Imports app files or other storage files from package .