Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
isFinished example
$progressBar
=
$io
->
createProgressBar
(
$total
)
;
$io
->
title
(
sprintf
(
'Starting import of size %d ',
$total
)
)
;
$records
= 0;
$progress
=
new
Progress
(
$log
->
getId
(
)
, Progress::STATE_PROGRESS, 0
)
;
do
{
$progress
=
$importExport
->
import
(
Context::
createDefaultContext
(
)
,
$progress
->
getOffset
(
)
)
;
$progressBar
->
setProgress
(
$progress
->
getOffset
(
)
)
;
$records
+=
$progress
->
getProcessedRecords
(
)
;
}
while
(
!
$progress
->
isFinished
(
)
)
;
$elapsed
=
time
(
)
-
$startTime
;
$io
->
newLine
(
2
)
;
if
(
$printErrors
)
{
$this
->
printErrors
(
$importExport
,
$log
,
$io
,
$doRollback
&&
$progress
->
getState
(
)
=== Progress::STATE_FAILED
)
;
}
$this
->
printResults
(
$log
,
$io
)
;
if
(
$dryRun
)
{
if
(
$logEntity
->
getActivity
(
)
=== ImportExportLogEntity::ACTIVITY_IMPORT
||
$logEntity
->
getActivity
(
)
=== ImportExportLogEntity::ACTIVITY_DRYRUN
)
{
$progress
=
$importExport
->
import
(
$context
,
$message
->
getOffset
(
)
)
;
}
elseif
(
$logEntity
->
getActivity
(
)
=== ImportExportLogEntity::ACTIVITY_EXPORT
)
{
$progress
=
$importExport
->
export
(
$context
,
new
Criteria
(
)
,
$message
->
getOffset
(
)
)
;
}
else
{
throw
new
ProcessingException
(
'Unknown activity'
)
;
}
if
(
!
$progress
->
isFinished
(
)
)
{
$nextMessage
=
new
ImportExportMessage
(
$context
,
$logEntity
->
getId
(
)
,
$logEntity
->
getActivity
(
)
,
$progress
->
getOffset
(
)
)
;
$this
->messageBus->
dispatch
(
$nextMessage
)
;
}
}
}
public
function
import
(
Context
$context
, int
$offset
= 0
)
: Progress
{
$progress
=
$this
->importExportService->
getProgress
(
$this
->logEntity->
getId
(
)
,
$offset
)
;
/** @var ImportExportFileEntity $file */
$file
=
$this
->logEntity->
getFile
(
)
;
$progress
->
setTotal
(
$file
->
getSize
(
)
)
;
if
(
$progress
->
isFinished
(
)
)
{
return
$progress
;
}
$processed
= 0;
$path
=
$file
->
getPath
(
)
;
$progress
->
setTotal
(
$this
->filesystem->
fileSize
(
$path
)
)
;
$invalidRecordsProgress
= null;
$failedRecords
=
[
]
;
$mockRepository
,
$pipeFactory
->
create
(
$logEntity
)
,
$readerFactory
->
create
(
$logEntity
)
,
$writerFactory
->
create
(
$logEntity
)
,
$this
->
getContainer
(
)
->
get
(
FileService::
class
)
,
5,
5
)
;
do
{
$progress
=
$importExport
->
import
(
$context
,
$progress
->
getOffset
(
)
)
;
}
while
(
!
$progress
->
isFinished
(
)
)
;
static
::
assertSame
(
Progress::STATE_SUCCEEDED,
$progress
->
getState
(
)
, 'Import with MockRepository failed. Maybe check for mock errors.'
)
;
return
$mockRepository
;
}
protected
function
createProduct
(
?string
$productId
= null
)
: string
{
$productId
??= Uuid::
randomHex
(
)
;
$data
=
[
public
function
testImportExport
(
)
: void
{
/** @var FilesystemOperator $filesystem */
$filesystem
=
$this
->
getContainer
(
)
->
get
(
'shopware.filesystem.private'
)
;
$productId
= Uuid::
randomHex
(
)
;
$this
->
getTestProduct
(
$productId
)
;
$criteria
=
new
Criteria
(
[
$productId
]
)
;
$progress
=
$this
->
export
(
Context::
createDefaultContext
(
)
, ProductDefinition::ENTITY_NAME,
$criteria
)
;
static
::
assertTrue
(
$progress
->
isFinished
(
)
)
;
static
::
assertImportExportSucceeded
(
$progress
,
$this
->
getInvalidLogContent
(
$progress
->
getInvalidRecordsLogId
(
)
)
)
;
$progress
=
$this
->
export
(
Context::
createDefaultContext
(
)
, ProductDefinition::ENTITY_NAME,
$criteria
)
;
/** @var EntityRepository $fileRepository */
$fileRepository
=
$this
->
getContainer
(
)
->
get
(
'import_export_file.repository'
)
;
/** @var ImportExportFileEntity|null $file */
$file
=
$fileRepository
->
search
(
new
Criteria
(
array_filter
(
[
$this
->
getLogEntity
(
$progress
->
getLogId
(
)
)
->
getFileId
(
)
]
)
)
, Context::
createDefaultContext
(
)
)
->
first
(
)
;
static
::
assertNotNull
(
$file
)
;
$importExportFileEntity
=
$this
->
getLogEntity
(
$progress
->
getLogId
(
)
)
->
getFile
(
)
;