Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getCacheRefreshed example
$directory
=
$this
->
createOutputDirectory
(
)
;
$fileName
=
$productFeed
->
getHash
(
)
. '_' .
$productFeed
->
getFileName
(
)
;
$filePath
=
$directory
.
$fileName
;
if
(
$productFeed
->
getInterval
(
)
=== -1 &&
file_exists
(
$filePath
)
)
{
readfile
(
$filePath
)
;
return
;
}
$diffInterval
=
time
(
)
;
if
(
$productFeed
->
getCacheRefreshed
(
)
)
{
$diffInterval
-=
$productFeed
->
getCacheRefreshed
(
)
->
getTimestamp
(
)
;
}
if
(
$diffInterval
>=
$productFeed
->
getInterval
(
)
|| !
file_exists
(
$filePath
)
)
{
$this
->
generateExport
(
$filePath
)
;
// update last refresh
$productFeed
->
setCacheRefreshed
(
'now'
)
;
$this
->
get
(
'models'
)
->
persist
(
$productFeed
)
;
$this
->
get
(
'models'
)
->
flush
(
$productFeed
)
;
}
$productFeedRepository
=
Shopware
(
)
->
Models
(
)
->
getRepository
(
ProductFeed::
class
)
;
$activeFeeds
=
$productFeedRepository
->
getActiveListQuery
(
)
->
getResult
(
)
;
foreach
(
$activeFeeds
as
$feedModel
)
{
$fileName
=
$feedModel
->
getHash
(
)
. '_' .
$feedModel
->
getFileName
(
)
;
$filePath
=
$cacheDir
.
$fileName
;
if
(
$feedModel
->
getInterval
(
)
=== 0
)
{
continue
;
}
elseif
(
$feedModel
->
getInterval
(
)
> 0
)
{
$diffInterval
=
time
(
)
;
if
(
$feedModel
->
getCacheRefreshed
(
)
)
{
$diffInterval
-=
$feedModel
->
getCacheRefreshed
(
)
->
getTimestamp
(
)
;
}
if
(
$diffInterval
<
$feedModel
->
getInterval
(
)
&&
file_exists
(
$filePath
)
)
{
continue
;
}
}
$export
->sFeedID =
$feedModel
->
getId
(
)
;
$export
->sHash =
$feedModel
->
getHash
(
)
;
$export
->
sInitSettings
(
)
;