Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
FinishResult example
$this
->destination =
$destination
;
}
/** * @param int $offset * * @return FinishResult|ValidResult */
public
function
run
(
$offset
)
{
if
(
is_file
(
$this
->destination
)
&&
filesize
(
$this
->destination
)
> 0
)
{
return
new
FinishResult
(
$offset
,
$this
->version->size
)
;
}
$download
=
new
Download
(
)
;
$startTime
=
microtime
(
true
)
;
$download
->
setHaltCallback
(
function
D
)
use
(
$startTime
)
{
if
(
microtime
(
true
)
-
$startTime
> 10
)
{
return
true;
}
return
false;
}
)
;
if
(
time
(
)
-
$requestTime
>= 20
||
(
$position
+ 1
)
% 1000 === 0
)
{
$source
->
close
(
)
;
return
new
ValidResult
(
$position
+ 1,
$count
)
;
}
}
$source
->
close
(
)
;
unlink
(
$this
->source
)
;
return
new
FinishResult
(
$count
,
$count
)
;
}
}
// Issue rename to trash command
$remoteFs
->
delete
(
$targetFile
)
;
}
else
{
$remoteFs
->
rename
(
$targetFile
,
$backupFile
)
;
}
}
$remoteFs
->
rename
(
$sourceFile
,
$targetFile
)
;
}
}
return
new
FinishResult
(
$total
,
$total
)
;
}
}
$currentVersion
=
$this
->migrationManager->
getCurrentVersion
(
)
;
if
(
!
$totalCount
)
{
$totalCount
= \
count
(
$this
->migrationManager->
getMigrationsForVersion
(
$currentVersion
)
)
;
}
$migration
=
$this
->migrationManager->
getNextMigrationForVersion
(
$currentVersion
)
;
if
(
$migration
=== null
)
{
return
new
FinishResult
(
$offset
,
$totalCount
)
;
}
try
{
$this
->migrationManager->
apply
(
$migration
, AbstractMigration::MODUS_UPDATE
)
;
}
catch
(
Exception
$e
)
{
$reflection
=
new
ReflectionClass
(
\
get_class
(
$migration
)
)
;
$classFile
=
$reflection
->
getFileName
(
)
;
return
new
ErrorResult
(
$e
->
getMessage
(
)
,
$e
,
[
'deltaFile' =>
$classFile
,
'deltaVersion' =>
$migration
->
getVersion
(
)
,
try
{
$conn
->
exec
(
implode
(
";\n",
$sql
)
)
;
}
catch
(
PDOException
$e
)
{
return
new
ErrorResult
(
'second' .
$e
->
getMessage
(
)
,
$e
,
[
'query' =>
$sql
]
)
;
}
}
if
(
$dump
->
valid
(
)
)
{
return
new
ValidResult
(
$dump
->
key
(
)
,
$totalCount
)
;
}
return
new
FinishResult
(
$dump
->
key
(
)
,
$totalCount
)
;
}
}
$this
->request =
$request
;
$this
->response =
$response
;
$this
->container =
$container
;
$this
->resultMapper =
new
ResultMapper
(
)
;
}
public
function
importSnippets
(
)
{
$dump
=
$this
->container->
get
(
'dump'
)
;
if
(
!
$dump
)
{
$result
=
new
FinishResult
(
0, 0
)
;
$this
->
toJson
(
200,
$this
->resultMapper->
toExtJs
(
$result
)
)
;
return
;
}
$conn
=
$this
->container->
get
(
'db'
)
;
$snippetStep
=
new
SnippetStep
(
$conn
,
$dump
)
;
$offset
=
$this
->request->
get
(
'offset'
)
;
$result
=
$snippetStep
->
run
(
$offset
)
;