Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
extractPluginZip example
public
function
uploadPlugin
(
UploadedFile
$file
, Context
$context
)
: void
{
/** @var string $tempFileName */
$tempFileName
=
tempnam
(
sys_get_temp_dir
(
)
,
$file
->
getClientOriginalName
(
)
)
;
$tempRealPath
=
realpath
(
$tempFileName
)
;
\
assert
(
\
is_string
(
$tempRealPath
)
)
;
$tempDirectory
= \
dirname
(
$tempRealPath
)
;
$tempFile
=
$file
->
move
(
$tempDirectory
,
$tempFileName
)
;
$type
=
$this
->
extractPluginZip
(
$tempFile
->
getPathname
(
)
)
;
if
(
$type
=== self::PLUGIN
)
{
$this
->pluginService->
refreshPlugins
(
$context
,
new
NullIO
(
)
)
;
}
}
public
function
downloadStorePlugin
(
PluginDownloadDataStruct
$location
, Context
$context
)
: void
{
/** @var string $tempFileName */
$tempFileName
=
tempnam
(
sys_get_temp_dir
(
)
, 'store-plugin'
)
;
$downloadsDir
=
$this
->container->
getParameter
(
'shopware.app.downloadsDir'
)
;
if
(
!\
is_string
(
$downloadsDir
)
)
{
throw
new
RuntimeException
(
'Parameter shopware.app.downloadsDir has to be a string'
)
;
}
$filePath
=
rtrim
(
$downloadsDir
, '/'
)
. DIRECTORY_SEPARATOR .
$metaStruct
->
getFileName
(
)
;
$service
=
Shopware
(
)
->
Container
(
)
->
get
(
'shopware_plugininstaller.plugin_download_service'
)
;
try
{
$service
->
extractPluginZip
(
$filePath
,
$metaStruct
->
getTechnicalName
(
)
)
;
$pluginManager
=
$this
->
get
(
InstallerService::
class
)
;
$pluginManager
->
refreshPluginList
(
)
;
}
catch
(
Exception
$e
)
{
$this
->
View
(
)
->
assign
(
[
'success' => false, 'message' =>
$e
->
getMessage
(
)
]
)
;
return
;
}
$this
->
View
(
)
->
assign
(
'success', true
)
;
}
$request
->
getTechnicalName
(
)
,
$request
->
getShopwareVersion
(
)
,
$request
->
getDomain
(
)
,
$request
->
getToken
(
)
)
;
$result
=
$this
->
getMetaInformation
(
$metaRequest
)
;
$response
=
$this
->httpClient->
get
(
$result
->
getUri
(
)
)
;
$file
=
$this
->
createDownloadZip
(
$response
->
getBody
(
)
)
;
$this
->
extractPluginZip
(
$file
,
$metaRequest
->
getTechnicalName
(
)
)
;
unlink
(
$file
)
;
return
true;
}
/** * @return string file path to the downloaded file */
private
function
createDownloadZip
(
string
$content
)
: string
{
$file
=
tempnam
(
sys_get_temp_dir
(
)
, 'plugin_'
)
. '.zip';
return
;
}
$tempFileName
=
tempnam
(
sys_get_temp_dir
(
)
,
$file
->
getClientOriginalName
(
)
)
;
$tempDirectory
= \
dirname
(
realpath
(
$tempFileName
)
)
;
try
{
$file
=
$file
->
move
(
$tempDirectory
,
$tempFileName
)
;
$pluginName
=
$information
[
'basename'
]
;
$pluginDownloadService
->
extractPluginZip
(
$file
->
getPathname
(
)
,
$pluginName
)
;
}
catch
(
Exception
$e
)
{
$this
->
View
(
)
->
assign
(
[
'success' => false,
'message' =>
$e
->
getMessage
(
)
,
]
)
;
return
;
}
finally
{
unlink
(
$file
->
getPathname
(
)
)
;
}
/** * {@inheritdoc} */
protected
function
execute
(
InputInterface
$input
, OutputInterface
$output
)
: int
{
$zipFile
=
$input
->
getArgument
(
'zip-file'
)
;
$io
=
new
ShopwareStyle
(
$input
,
$output
)
;
$io
->
title
(
'Shopware Plugin Zip Import'
)
;
try
{
$type
=
$this
->pluginManagementService->
extractPluginZip
(
$zipFile
,
(bool)
$input
->
getOption
(
'delete'
)
)
;
}
catch
(
NoPluginFoundInZipException
$e
)
{
$io
->
error
(
$e
->
getMessage
(
)
)
;
return
self::FAILURE;
}
if
(
$type
=== PluginManagementService::PLUGIN
)
{
$this
->cacheClearer->
clearContainerCache
(
)
;
}
$io
->
success
(
'Successfully import zip file ' .
basename
(
(string)
$zipFile
)
)
;
public
function
testUploadPlugin
(
)
: void
{
$pluginFile
=
$this
->
createUploadedFile
(
)
;
$this
->
getPluginManagementService
(
)
->
uploadPlugin
(
$pluginFile
, Context::
createDefaultContext
(
)
)
;
static
::
assertFileExists
(
self::PLUGIN_FASHION_THEME_PATH
)
;
static
::
assertFileExists
(
self::PLUGIN_FASHION_THEME_BASE_CLASS_PATH
)
;
}
public
function
testExtractPluginZip
(
)
: void
{
$this
->
getPluginManagementService
(
)
->
extractPluginZip
(
self::PLUGIN_ZIP_FIXTURE_PATH
)
;
$extractedPlugin
=
$this
->filesystem->
exists
(
self::PLUGIN_FASHION_THEME_PATH
)
;
$extractedPluginBaseClass
=
$this
->filesystem->
exists
(
self::PLUGIN_FASHION_THEME_BASE_CLASS_PATH
)
;
$pluginZipExists
=
$this
->filesystem->
exists
(
self::PLUGIN_ZIP_FIXTURE_PATH
)
;
static
::
assertTrue
(
$extractedPlugin
)
;
static
::
assertTrue
(
$extractedPluginBaseClass
)
;
static
::
assertFalse
(
$pluginZipExists
)
;
}
public
function
testExtractPluginZipWithoutDeletion
(
)
: void
{
$pluginManagementService
=
new
PluginManagementService
(
'',
$pluginZipDetector
,
$extractor
,
$pluginService
,
$this
->
createMock
(
Filesystem::
class
)
,
$cacheClearer
,
$client
)
;
$pluginManagementService
->
extractPluginZip
(
'/some/zip/file.zip',
)
;
}
public
function
testExtractPluginWithDetectedApp
(
)
: void
{
$client
=
$this
->
createClient
(
[
new
Response
(
)
]
)
;
$pluginService
=
$this
->
createMock
(
PluginService::
class
)
;
$pluginZipDetector
=
$this
->
createMock
(
PluginZipDetector::
class
)
;