Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
unlock example
public
function
testReadsAnEmptyArrayWithReadWhenNothingCachedAtKey
(
)
{
$this
->
assertEmpty
(
$this
->
getStoreMetadata
(
'/nothing'
)
)
;
}
public
function
testUnlockFileThatDoesExist
(
)
{
$this
->
storeSimpleEntry
(
)
;
$this
->store->
lock
(
$this
->request
)
;
$this
->
assertTrue
(
$this
->store->
unlock
(
$this
->request
)
)
;
}
public
function
testUnlockFileThatDoesNotExist
(
)
{
$this
->
assertFalse
(
$this
->store->
unlock
(
$this
->request
)
)
;
}
public
function
testRemovesEntriesForKeyWithPurge
(
)
{
$request
= Request::
create
(
'/foo'
)
;
$this
->store->
write
(
$request
,
new
Response
(
'foo'
)
)
;
$http
=
preg_replace
(
'#^https:#', 'http:',
$url
)
;
if
(
$http
=== null
)
{
return
false;
}
$https
=
preg_replace
(
'#^http:#', 'https:',
$url
)
;
if
(
$https
=== null
)
{
return
false;
}
$httpPurged
=
$this
->
unlock
(
Request::
create
(
$http
)
)
;
$httpsPurged
=
$this
->
unlock
(
Request::
create
(
$https
)
)
;
return
$httpPurged
||
$httpsPurged
;
}
private
function
getLockKey
(
Request
$request
)
: string
{
return
'http_lock_' .
$this
->cacheKeyGenerator->
generate
(
$request
)
;
}
}
$result
=
$urlProvider
->
getUrls
(
$context
,
$this
->batchSize,
$offset
)
;
$this
->
processSiteMapHandles
(
$result
)
;
$needRun
=
$result
->
getNextOffset
(
)
!== null;
$offset
=
$result
->
getNextOffset
(
)
;
}
while
(
$needRun
)
;
}
$this
->
finishSitemapHandles
(
)
;
}
finally
{
$this
->
unlock
(
$context
)
;
}
$this
->dispatcher->
dispatch
(
new
SitemapGeneratedEvent
(
$context
)
)
;
return
new
SitemapGenerationResult
(
true,
$lastProvider
,
null,
$context
->
getSalesChannel
(
)
->
getId
(
)
,
$context
->
getLanguageId
(
)
)
;
}
if
(
$this
->options
[
'debug'
]
)
{
throw
$e
;
}
}
finally
{
foreach
(
$restoreHeaders
as
$header
=>
$values
)
{
$response
->headers->
set
(
$header
,
$values
)
;
}
}
// now that the response is cached, release the lock
$this
->store->
unlock
(
$request
)
;
}
/** * Restores the Response body. */
private
function
restoreResponseBody
(
Request
$request
, Response
$response
)
: void
{
if
(
$response
->headers->
has
(
'X-Body-Eval'
)
)
{
\
assert
(
self::BODY_EVAL_BOUNDARY_LENGTH === 24
)
;
ob_start
(
)
;
class
ReverseProxyCacheTest
extends
TestCase
{
/** * The store is only used to track the cache tags and not to cache actual */
public
function
testLookup
(
)
: void
{
$store
=
new
ReverseProxyCache
(
$this
->
createMock
(
AbstractReverseProxyGateway::
class
)
,
$this
->
createMock
(
CacheTracer::
class
)
,
[
]
)
;
static
::
assertNull
(
$store
->
lookup
(
new
Request
(
)
)
)
;
static
::
assertFalse
(
$store
->
isLocked
(
new
Request
(
)
)
)
;
static
::
assertTrue
(
$store
->
lock
(
new
Request
(
)
)
)
;
static
::
assertTrue
(
$store
->
unlock
(
new
Request
(
)
)
)
;
$store
->
cleanup
(
)
;
}
public
function
testWriteAddsGlobalStates
(
)
: void
{
$store
=
new
ReverseProxyCache
(
$this
->
createMock
(
AbstractReverseProxyGateway::
class
)
,
$this
->
createMock
(
CacheTracer::
class
)
,
[
CacheResponseSubscriber::STATE_LOGGED_IN
]
)
;
$request
=
new
Request
(
)
;
$request
->attributes->
set
(
RequestTransformer::ORIGINAL_REQUEST_URI, '/foo'
)
;
$response
=
new
Response
(
)
;
$store
->
write
(
$request
,
$response
)
;
try
{
$sql
= 'SELECT pg_try_advisory_lock_shared(:key)';
$stmt
=
$this
->
getConnection
(
)
->
prepare
(
$sql
)
;
$stmt
->
bindValue
(
':key',
$this
->
getHashedKey
(
$key
)
)
;
$result
=
$stmt
->
execute
(
)
;
// Check if lock is acquired
if
(
true ===
$stmt
->
fetchColumn
(
)
)
{
$key
->
markUnserializable
(
)
;
// release lock in case of demotion
$this
->
unlock
(
$key
)
;
$lockAcquired
= true;
return
;
}
}
finally
{
if
(
!
$lockAcquired
)
{
$this
->
getInternalStore
(
)
->
delete
(
$key
)
;
}
}
$this
->
redirect
(
$shop
->
getBaseUrl
(
)
)
;
}
public
function
unlockCustomerAction
(
)
{
$customerId
=
(int)
$this
->
Request
(
)
->
getParam
(
'customerId'
)
;
try
{
/** @var CustomerUnlockServiceInterface $unlockService */
$unlockService
=
$this
->
get
(
'shopware_account.customer_unlock_service'
)
;
$unlockService
->
unlock
(
$customerId
)
;
}
catch
(
Exception
$e
)
{
$this
->
View
(
)
->
assign
(
'success', false
)
;
return
;
}
$this
->
View
(
)
->
assign
(
'success', true
)
;
}
/** * Returns the shopware model manager * * @return ModelManager */
if
(
$this
->options
[
'debug'
]
)
{
throw
$e
;
}
}
finally
{
foreach
(
$restoreHeaders
as
$header
=>
$values
)
{
$response
->headers->
set
(
$header
,
$values
)
;
}
}
// now that the response is cached, release the lock
$this
->store->
unlock
(
$request
)
;
}
/** * Restores the Response body. */
private
function
restoreResponseBody
(
Request
$request
, Response
$response
)
: void
{
if
(
$response
->headers->
has
(
'X-Body-Eval'
)
)
{
\
assert
(
self::BODY_EVAL_BOUNDARY_LENGTH === 24
)
;
ob_start
(
)
;
try
{
$sql
= 'SELECT pg_try_advisory_lock_shared(:key)';
$result
=
$this
->conn->
executeQuery
(
$sql
,
[
'key' =>
$this
->
getHashedKey
(
$key
)
,
]
)
;
// Check if lock is acquired
if
(
true ===
$result
->
fetchOne
(
)
)
{
$key
->
markUnserializable
(
)
;
// release lock in case of demotion
$this
->
unlock
(
$key
)
;
$lockAcquired
= true;
return
;
}
}
finally
{
if
(
!
$lockAcquired
)
{
$this
->
getInternalStore
(
)
->
delete
(
$key
)
;
}
}