本文整理汇总了PHP中Drupal\Core\Lock\LockBackendInterface类的典型用法代码示例。如果您正苦于以下问题:PHP LockBackendInterface类的具体用法?PHP LockBackendInterface怎么用?PHP LockBackendInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LockBackendInterface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->storage = $this->getMock('Drupal\\locale\\StringStorageInterface');
$this->cache = $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
$this->lock = $this->getMock('Drupal\\Core\\Lock\\LockBackendInterface');
$this->lock->expects($this->never())->method($this->anything());
$this->user = $this->getMock('Drupal\\Core\\Session\\AccountInterface');
$this->user->expects($this->any())->method('getRoles')->will($this->returnValue(array('anonymous')));
$this->configFactory = $this->getConfigFactoryStub(array('locale.settings' => array('cache_strings' => FALSE)));
$this->languageManager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface');
$container = new ContainerBuilder();
$container->set('current_user', $this->user);
\Drupal::setContainer($container);
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:17,代码来源:LocaleLookupTest.php
示例2: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$modules = $input->getArgument('module');
if (!$this->lock->acquire('cron', 900.0)) {
$io->warning($this->trans('commands.cron.execute.messages.lock'));
return 1;
}
if (in_array('all', $modules)) {
$modules = $this->moduleHandler->getImplementations('cron');
}
foreach ($modules as $module) {
if (!$this->moduleHandler->implementsHook($module, 'cron')) {
$io->warning(sprintf($this->trans('commands.cron.execute.messages.module-invalid'), $module));
continue;
}
try {
$io->info(sprintf($this->trans('commands.cron.execute.messages.executing-cron'), $module));
$this->moduleHandler->invoke($module, 'cron');
} catch (\Exception $e) {
watchdog_exception('cron', $e);
$io->error($e->getMessage());
}
}
$this->state->set('system.cron_last', REQUEST_TIME);
$this->lock->release('cron');
$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
$io->success($this->trans('commands.cron.execute.messages.success'));
return 0;
}
开发者ID:ddrozdik,项目名称:DrupalConsole,代码行数:33,代码来源:ExecuteCommand.php
示例3: testDestruct
/**
* Tests the destruct method.
*
* @covers ::destruct
*/
public function testDestruct()
{
$this->libraryDiscoveryParser->expects($this->once())->method('buildByExtension')->with('test')->will($this->returnValue($this->libraryData));
$lock_key = 'library_info:Drupal\\Core\\Cache\\CacheCollector';
$this->lock->expects($this->once())->method('acquire')->with($lock_key)->will($this->returnValue(TRUE));
$this->cache->expects($this->exactly(2))->method('get')->with('library_info')->will($this->returnValue(FALSE));
$this->cache->expects($this->once())->method('set')->with('library_info', array('test' => $this->libraryData), Cache::PERMANENT, array('library_info'));
$this->lock->expects($this->once())->method('release')->with($lock_key);
// This should get data and persist the key.
$this->libraryDiscoveryCollector->get('test');
$this->libraryDiscoveryCollector->destruct();
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:17,代码来源:LibraryDiscoveryCollectorTest.php
示例4: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
try {
$this->lock->release('cron');
$io->info($this->trans('commands.cron.release.messages.released'));
} catch (Exception $e) {
$io->error($e->getMessage());
return 1;
}
$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
return 0;
}
开发者ID:ibonelli,项目名称:DrupalConsole,代码行数:16,代码来源:ReleaseCommand.php
示例5: run
/**
* {@inheritdoc}
*/
public function run()
{
// Allow execution to continue even if the request gets cancelled.
@ignore_user_abort(TRUE);
// Prevent session information from being saved while cron is running.
$original_session_saving = $this->sessionManager->isEnabled();
$this->sessionManager->disable();
// Force the current user to anonymous to ensure consistent permissions on
// cron runs.
$original_user = $this->currentUser->getAccount();
$this->currentUser->setAccount(new AnonymousUserSession());
// Try to allocate enough time to run all the hook_cron implementations.
drupal_set_time_limit(240);
$return = FALSE;
// Try to acquire cron lock.
if (!$this->lock->acquire('cron', 240.0)) {
// Cron is still running normally.
watchdog('cron', 'Attempting to re-run cron while it is already running.', array(), WATCHDOG_WARNING);
} else {
$this->invokeCronHandlers();
$this->setCronLastTime();
// Release cron lock.
$this->lock->release('cron');
// Return TRUE so other functions can check if it did run successfully
$return = TRUE;
}
// Process cron queues.
$this->processQueues();
// Restore the user.
$this->currentUser->setAccount($original_user);
if ($original_session_saving) {
$this->sessionManager->enable();
}
return $return;
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:38,代码来源:Cron.php
示例6: rebuild
/**
* {@inheritdoc}
*/
public function rebuild()
{
if ($this->building) {
throw new \RuntimeException('Recursive router rebuild detected.');
}
if (!$this->lock->acquire('router_rebuild')) {
// Wait for another request that is already doing this work.
// We choose to block here since otherwise the routes might not be
// available, resulting in a 404.
$this->lock->wait('router_rebuild');
return FALSE;
}
$this->building = TRUE;
$collection = new RouteCollection();
foreach ($this->getRouteDefinitions() as $routes) {
// The top-level 'routes_callback' is a list of methods in controller
// syntax, see \Drupal\Core\Controller\ControllerResolver. These methods
// should return a set of \Symfony\Component\Routing\Route objects, either
// in an associative array keyed by the route name, which will be iterated
// over and added to the collection for this provider, or as a new
// \Symfony\Component\Routing\RouteCollection object, which will be added
// to the collection.
if (isset($routes['route_callbacks'])) {
foreach ($routes['route_callbacks'] as $route_callback) {
$callback = $this->controllerResolver->getControllerFromDefinition($route_callback);
if ($callback_routes = call_user_func($callback)) {
// If a RouteCollection is returned, add the whole collection.
if ($callback_routes instanceof RouteCollection) {
$collection->addCollection($callback_routes);
} else {
foreach ($callback_routes as $name => $callback_route) {
$collection->add($name, $callback_route);
}
}
}
}
unset($routes['route_callbacks']);
}
foreach ($routes as $name => $route_info) {
$route_info += array('defaults' => array(), 'requirements' => array(), 'options' => array());
$route = new Route($route_info['path'], $route_info['defaults'], $route_info['requirements'], $route_info['options']);
$collection->add($name, $route);
}
}
// DYNAMIC is supposed to be used to add new routes based upon all the
// static defined ones.
$this->dispatcher->dispatch(RoutingEvents::DYNAMIC, new RouteBuildEvent($collection));
// ALTER is the final step to alter all the existing routes. We cannot stop
// people from adding new routes here, but we define two separate steps to
// make it clear.
$this->dispatcher->dispatch(RoutingEvents::ALTER, new RouteBuildEvent($collection));
$this->checkProvider->setChecks($collection);
$this->dumper->addRoutes($collection);
$this->dumper->dump();
$this->lock->release('router_rebuild');
$this->dispatcher->dispatch(RoutingEvents::FINISHED, new Event());
$this->building = FALSE;
$this->rebuildNeeded = FALSE;
return TRUE;
}
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:63,代码来源:RouteBuilder.php
示例7: run
/**
* {@inheritdoc}
*/
public function run()
{
// Allow execution to continue even if the request gets cancelled.
@ignore_user_abort(TRUE);
// Force the current user to anonymous to ensure consistent permissions on
// cron runs.
$this->accountSwitcher->switchTo(new AnonymousUserSession());
// Try to allocate enough time to run all the hook_cron implementations.
drupal_set_time_limit(240);
$return = FALSE;
// Try to acquire cron lock.
if (!$this->lock->acquire('cron', 900.0)) {
// Cron is still running normally.
$this->logger->warning('Attempting to re-run cron while it is already running.');
} else {
$this->invokeCronHandlers();
$this->setCronLastTime();
// Release cron lock.
$this->lock->release('cron');
// Return TRUE so other functions can check if it did run successfully
$return = TRUE;
}
// Process cron queues.
$this->processQueues();
// Restore the user.
$this->accountSwitcher->switchBack();
return $return;
}
开发者ID:eigentor,项目名称:tommiblog,代码行数:31,代码来源:Cron.php
示例8: lockPersist
/**
* Creates a lock that will persist across requests.
*
* @param string $lock_name
* The name of the persistent lock to acquire.
*
* @return string
* The text to display.
*/
public function lockPersist($lock_name)
{
if ($this->persistentLock->acquire($lock_name)) {
return ['#markup' => 'TRUE: Lock successfully acquired in SystemTestController::lockPersist()'];
} else {
return ['#markup' => 'FALSE: Lock not acquired in SystemTestController::lockPersist()'];
}
}
开发者ID:HakS,项目名称:drupal8_training,代码行数:17,代码来源:SystemTestController.php
示例9: execute
/**
* Executes a callback.
*
* @param \Drupal\feeds\FeedInterface $feeds_feed
* The Feed we are executing a job for.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object to grab POST params from.
*
* @todo Configure a time limit.
* @todo Really awesome error handling.
*/
public function execute(FeedInterface $feeds_feed, Request $request)
{
$cid = 'feeds_feed:' . $feeds_feed->id();
if ($token = $request->request->get('token') && ($job = $this->state->get($cid))) {
if ($job['token'] == $token && ($lock = $this->lockBackend->acquire($cid))) {
$method = $job['method'];
$this->state->delete($cid);
ignore_user_abort(TRUE);
set_time_limit(0);
while ($feeds_feed->{$method}() != StateInterface::BATCH_COMPLETE) {
// Reset static caches in between runs to avoid memory leaks.
drupal_reset_static();
}
$this->lockBackend->release($cid);
}
}
}
开发者ID:alnutile,项目名称:drunatra,代码行数:28,代码来源:JobController.php
示例10: getMails
/**
* {@inheritdoc}
*/
public function getMails($limit = self::UNLIMITED, $conditions = array())
{
$messages = array();
// Continue to support 'nid' as a condition.
if (!empty($conditions['nid'])) {
$conditions['entity_type'] = 'node';
$conditions['entity_id'] = $conditions['nid'];
unset($conditions['nid']);
}
// Add default status condition if not set.
if (!isset($conditions['status'])) {
$conditions['status'] = array(SpoolStorageInterface::STATUS_PENDING, SpoolStorageInterface::STATUS_IN_PROGRESS);
}
// Special case for the status condition, the in progress actually only
// includes spool items whose locking time has expired. So this need to build
// an OR condition for them.
$status_or = new Condition('OR');
$statuses = is_array($conditions['status']) ? $conditions['status'] : array($conditions['status']);
foreach ($statuses as $status) {
if ($status == SpoolStorageInterface::STATUS_IN_PROGRESS) {
$status_or->condition((new Condition('AND'))->condition('status', $status)->condition('s.timestamp', $this->getExpirationTime(), '<'));
} else {
$status_or->condition('status', $status);
}
}
unset($conditions['status']);
$query = $this->connection->select('simplenews_mail_spool', 's')->fields('s')->condition($status_or)->orderBy('s.timestamp', 'ASC');
// Add conditions.
foreach ($conditions as $field => $value) {
$query->condition($field, $value);
}
/* BEGIN CRITICAL SECTION */
// The semaphore ensures that multiple processes get different message ID's,
// so that duplicate messages are not sent.
if ($this->lock->acquire('simplenews_acquire_mail')) {
// Get message id's
// Allocate messages
if ($limit > 0) {
$query->range(0, $limit);
}
foreach ($query->execute() as $message) {
if (Unicode::strlen($message->data)) {
$message->data = unserialize($message->data);
} else {
$message->data = simplenews_subscriber_load_by_mail($message->mail);
}
$messages[$message->msid] = $message;
}
if (count($messages) > 0) {
// Set the state and the timestamp of the messages
$this->updateMails(array_keys($messages), array('status' => SpoolStorageInterface::STATUS_IN_PROGRESS));
}
$this->lock->release('simplenews_acquire_mail');
}
/* END CRITICAL SECTION */
return new SpoolList($messages);
}
开发者ID:aritnath1990,项目名称:simplenewslatest,代码行数:60,代码来源:SpoolStorage.php
示例11: delete
/**
* Deletes data from the store for a given key and releases the lock on it.
*
* @param string $key
* The key of the data to delete.
*/
public function delete($key)
{
if (!$this->lockBackend->acquire($key)) {
$this->lockBackend->wait($key);
if (!$this->lockBackend->acquire($key)) {
throw new TempStoreException(String::format("Couldn't acquire lock to delete item %key from %collection temporary storage.", array('%key' => $key, '%collection' => $this->storage->getCollectionName())));
}
}
$this->storage->delete($key);
$this->lockBackend->release($key);
}
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:17,代码来源:SharedTempStore.php
示例12: testDeleteIfOwner
/**
* Tests the deleteIfOwner() method.
*
* @covers ::deleteIfOwner()
*/
public function testDeleteIfOwner()
{
$this->lock->expects($this->once())->method('acquire')->with('test_2')->will($this->returnValue(TRUE));
$this->keyValue->expects($this->at(0))->method('get')->with('test_1')->will($this->returnValue(FALSE));
$this->keyValue->expects($this->at(1))->method('get')->with('test_2')->will($this->returnValue($this->ownObject));
$this->keyValue->expects($this->at(2))->method('delete')->with('test_2');
$this->keyValue->expects($this->at(3))->method('get')->with('test_3')->will($this->returnValue($this->otherObject));
$this->assertTrue($this->tempStore->deleteIfOwner('test_1'));
$this->assertTrue($this->tempStore->deleteIfOwner('test_2'));
$this->assertFalse($this->tempStore->deleteIfOwner('test_3'));
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:16,代码来源:TempStoreTest.php
示例13: testRebuildIfNeeded
/**
* Tests \Drupal\Core\Routing\RouteBuilder::rebuildIfNeeded() method.
*/
public function testRebuildIfNeeded()
{
$this->lock->expects($this->once())->method('acquire')->with('router_rebuild')->will($this->returnValue(TRUE));
$this->lock->expects($this->once())->method('release')->with('router_rebuild');
$this->yamlDiscovery->expects($this->any())->method('findAll')->will($this->returnValue(array()));
$this->routeBuilder->setRebuildNeeded();
// This will trigger a successful rebuild.
$this->assertTrue($this->routeBuilder->rebuildIfNeeded());
// This will not trigger a rebuild.
$this->assertFalse($this->routeBuilder->rebuildIfNeeded());
}
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:14,代码来源:RouteBuilderTest.php
示例14: delete
/**
* Deletes data from the store for a given key and releases the lock on it.
*
* @param string $key
* The key of the data to delete.
*/
public function delete($key)
{
if (!$this->lockBackend->acquire($key)) {
$this->lockBackend->wait($key);
if (!$this->lockBackend->acquire($key)) {
throw new TempStoreException("Couldn't acquire lock to delete item '{$key}' from {$this->storage->getCollectionName()} temporary storage.");
}
}
$this->storage->delete($key);
$this->lockBackend->release($key);
}
开发者ID:318io,项目名称:318-io,代码行数:17,代码来源:SharedTempStore.php
示例15: menuLinksRebuild
/**
* Perform menu-specific rebuilding.
*/
protected function menuLinksRebuild()
{
if ($this->lock->acquire(__FUNCTION__)) {
$transaction = db_transaction();
try {
// Ensure the menu links are up to date.
$this->menuLinkManager->rebuild();
// Ignore any database replicas temporarily.
db_ignore_replica();
} catch (\Exception $e) {
$transaction->rollback();
watchdog_exception('menu', $e);
}
$this->lock->release(__FUNCTION__);
} else {
// Wait for another request that is already doing this work.
// We choose to block here since otherwise the router item may not
// be available during routing resulting in a 404.
$this->lock->wait(__FUNCTION__);
}
}
开发者ID:nstielau,项目名称:drops-8,代码行数:24,代码来源:MenuRouterRebuildSubscriber.php
示例16: menuLinksRebuild
/**
* Perform menu-specific rebuilding.
*/
protected function menuLinksRebuild()
{
if ($this->lock->acquire(__FUNCTION__)) {
$transaction = db_transaction();
try {
// Ensure the menu links are up to date.
menu_link_rebuild_defaults();
// Clear the menu cache.
menu_cache_clear_all();
// Track which menu items are expanded.
_menu_update_expanded_menus();
} catch (\Exception $e) {
$transaction->rollback();
watchdog_exception('menu', $e);
}
$this->lock->release(__FUNCTION__);
} else {
// Wait for another request that is already doing this work.
// We choose to block here since otherwise the router item may not
// be available during routing resulting in a 404.
$this->lock->wait(__FUNCTION__);
}
}
开发者ID:alnutile,项目名称:drunatra,代码行数:26,代码来源:RouterRebuildSubscriber.php
示例17: testRebuildIfNecessary
/**
* Tests \Drupal\Core\Routing\RouteBuilder::rebuildIfNeeded() method.
*/
public function testRebuildIfNecessary()
{
$this->lock->expects($this->once())->method('acquire')->with('router_rebuild')->will($this->returnValue(TRUE));
$this->lock->expects($this->once())->method('release')->with('router_rebuild');
$this->routeBuilderIndicator->expects($this->once())->method('setRebuildNeeded');
$this->routeBuilderIndicator->expects($this->once())->method('setRebuildDone');
$this->routeBuilderIndicator->expects($this->exactly(2))->method('isRebuildNeeded')->will($this->onConsecutiveCalls(TRUE, FALSE));
$this->yamlDiscovery->expects($this->any())->method('findAll')->will($this->returnValue(array()));
$this->routeBuilder->setRebuildNeeded();
// This will trigger a successful rebuild.
$this->assertTrue($this->routeBuilder->rebuildIfNeeded());
// This will not trigger a rebuild.
$this->assertFalse($this->routeBuilder->rebuildIfNeeded());
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:17,代码来源:RouteBuilderTest.php
示例18: testDestruct
/**
* Tests the destruct method.
*
* @covers ::destruct
*/
public function testDestruct()
{
$this->activeTheme = $this->getMockBuilder('Drupal\\Core\\Theme\\ActiveTheme')->disableOriginalConstructor()->getMock();
$this->themeManager->expects($this->once())->method('getActiveTheme')->willReturn($this->activeTheme);
$this->activeTheme->expects($this->once())->method('getName')->willReturn('kitten_theme');
$this->libraryDiscoveryCollector = new LibraryDiscoveryCollector($this->cache, $this->lock, $this->libraryDiscoveryParser, $this->themeManager);
$this->libraryDiscoveryParser->expects($this->once())->method('buildByExtension')->with('test')->willReturn($this->libraryData);
$lock_key = 'library_info:kitten_theme:Drupal\\Core\\Cache\\CacheCollector';
$this->lock->expects($this->once())->method('acquire')->with($lock_key)->will($this->returnValue(TRUE));
$this->cache->expects($this->exactly(2))->method('get')->with('library_info:kitten_theme')->willReturn(FALSE);
$this->cache->expects($this->once())->method('set')->with('library_info:kitten_theme', array('test' => $this->libraryData), Cache::PERMANENT, ['library_info']);
$this->lock->expects($this->once())->method('release')->with($lock_key);
// This should get data and persist the key.
$this->libraryDiscoveryCollector->get('test');
$this->libraryDiscoveryCollector->destruct();
}
开发者ID:nstielau,项目名称:drops-8,代码行数:21,代码来源:LibraryDiscoveryCollectorTest.php
示例19: delete
/**
* Deletes data from the store for a given key and releases the lock on it.
*
* @param string $key
* The key of the data to delete.
*
* @return bool
* TRUE if the object was deleted or does not exist, FALSE if it exists but
* is not owned by $this->owner.
*/
public function delete($key)
{
$key = $this->createkey($key);
if (!($object = $this->storage->get($key))) {
return TRUE;
} elseif ($object->owner != $this->getOwner()) {
return FALSE;
}
if (!$this->lockBackend->acquire($key)) {
$this->lockBackend->wait($key);
if (!$this->lockBackend->acquire($key)) {
throw new TempStoreException(SafeMarkup::format("Couldn't acquire lock to delete item %key from %collection temporary storage.", array('%key' => $key, '%collection' => $this->storage->getCollectionName())));
}
}
$this->storage->delete($key);
$this->lockBackend->release($key);
return TRUE;
}
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:28,代码来源:PrivateTempStore.php
示例20: delete
/**
* Deletes data from the store for a given key and releases the lock on it.
*
* @param string $key
* The key of the data to delete.
*
* @return bool
* TRUE if the object was deleted or does not exist, FALSE if it exists but
* is not owned by $this->owner.
*/
public function delete($key)
{
$key = $this->createkey($key);
if (!($object = $this->storage->get($key))) {
return TRUE;
} elseif ($object->owner != $this->getOwner()) {
return FALSE;
}
if (!$this->lockBackend->acquire($key)) {
$this->lockBackend->wait($key);
if (!$this->lockBackend->acquire($key)) {
throw new TempStoreException("Couldn't acquire lock to delete item '{$key}' from '{$this->storage->getCollectionName()}' temporary storage.");
}
}
$this->storage->delete($key);
$this->lockBackend->release($key);
return TRUE;
}
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:28,代码来源:PrivateTempStore.php
注:本文中的Drupal\Core\Lock\LockBackendInterface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论