Пример #1
1
 /**
  * {@inheritdoc}
  */
 public function setCache($form_build_id, $form, $form_state)
 {
     // 6 hours cache life time for forms should be plenty.
     $expire = 21600;
     // Cache form structure.
     if (isset($form)) {
         if ($this->currentUser()->isAuthenticated()) {
             $form['#cache_token'] = $this->csrfToken->get();
         }
         $this->keyValueExpirableFactory->get('form')->setWithExpire($form_build_id, $form, $expire);
     }
     // Cache form state.
     // Store the known list of safe strings for form re-use.
     // @todo Ensure we are not storing an excessively large string list in:
     //   https://www.drupal.org/node/2295823
     $form_state['build_info']['safe_strings'] = SafeMarkup::getAll();
     if ($data = array_diff_key($form_state, array_flip($this->getUncacheableKeys()))) {
         $this->keyValueExpirableFactory->get('form_state')->setWithExpire($form_build_id, $data, $expire);
     }
 }
Пример #2
0
 /**
  * Creates a SharedTempStore for the current user or anonymous session.
  *
  * @param string $collection
  *   The collection name to use for this key/value store. This is typically
  *   a shared namespace or module name, e.g. 'views', 'entity', etc.
  * @param mixed $owner
  *   (optional) The owner of this SharedTempStore. By default, the
  *   SharedTempStore is owned by the currently authenticated user, or by the
  *   active anonymous session if no user is logged in.
  *
  * @return \Drupal\user\SharedTempStore
  *   An instance of the key/value store.
  */
 function get($collection, $owner = NULL)
 {
     // Use the currently authenticated user ID or the active user ID unless
     // the owner is overridden.
     if (!isset($owner)) {
         $owner = \Drupal::currentUser()->id() ?: session_id();
     }
     // Store the data for this collection in the database.
     $storage = $this->storageFactory->get("user.shared_tempstore.{$collection}");
     return new SharedTempStore($storage, $this->lockBackend, $owner, $this->requestStack, $this->expire);
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function setCache($form_build_id, $form, FormStateInterface $form_state)
 {
     // 6 hours cache life time for forms should be plenty.
     $expire = 21600;
     // Ensure that the form build_id embedded in the form structure is the same
     // as the one passed in as a parameter. This is an additional safety measure
     // to prevent legacy code operating directly with
     // \Drupal::formBuilder()->getCache() and \Drupal::formBuilder()->setCache()
     // from accidentally overwriting immutable form state.
     if (isset($form['#build_id']) && $form['#build_id'] != $form_build_id) {
         $this->logger->error('Form build-id mismatch detected while attempting to store a form in the cache.');
         return;
     }
     // Cache form structure.
     if (isset($form)) {
         if ($this->currentUser->isAuthenticated()) {
             $form['#cache_token'] = $this->csrfToken->get();
         }
         unset($form['#build_id_old']);
         $this->keyValueExpirableFactory->get('form')->setWithExpire($form_build_id, $form, $expire);
     }
     // Cache form state.
     if ($this->configFactory->get('system.performance')->get('cache.page.use_internal') && $this->isPageCacheable()) {
         $form_state->addBuildInfo('immutable', TRUE);
     }
     // Store the known list of safe strings for form re-use.
     // @todo Ensure we are not storing an excessively large string list in:
     //   https://www.drupal.org/node/2295823
     $form_state->addBuildInfo('safe_strings', SafeMarkup::getAll());
     if ($data = $form_state->getCacheableArray()) {
         $this->keyValueExpirableFactory->get('form_state')->setWithExpire($form_build_id, $data, $expire);
     }
 }
Пример #4
0
 /**
  * Constructor.
  *
  * @param array $configuration
  *   A configuration array containing information about the plugin instance.
  * @param string $plugin_id
  *   The plugin_id for the plugin instance.
  * @param mixed $plugin_definition
  *   The plugin implementation definition.
  * @param MigrationInterface $migration
  *   The migration.
  * @param EntityManagerInterface $entity_manager
  *   The entity manager.
  * @param KeyValueExpirableFactoryInterface $temp_store_factory
  *   The temp store factory.
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityManagerInterface $entity_manager, KeyValueExpirableFactoryInterface $temp_store_factory)
 {
     parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
     list($entity_type_id) = explode('__', $migration->id());
     $entity_type = $entity_manager->getDefinition($entity_type_id);
     $this->entityTypeId = $entity_type_id;
     $this->entityIdKey = $entity_type->getKey('id');
     $this->tempStore = $temp_store_factory->get('multiversion_migration_' . $this->entityTypeId);
 }
Пример #5
0
 /**
  * Handles an unsubscribe request.
  *
  * @param int $subscription_id
  *   The subscription entity id.
  * @param string $token
  *   The subscription token.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  *   The response challenge.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  *   Thrown if anything seems amiss.
  */
 protected function handleUnsubscribe($subscription_id, $token, Request $request)
 {
     // The subscription id already deleted, but waiting in the keyvalue store.
     $id = $token . ':' . $subscription_id;
     $subscription = $this->keyValueExpireFactory->get('feeds_push_unsubscribe')->get($id);
     if (!$subscription) {
         throw new NotFoundHttpException();
     }
     $this->keyValueExpireFactory->get('feeds_push_unsubscribe')->delete($id);
     return new Response(SafeMarkup::checkPlain($request->query->get('hub_challenge')), 200);
 }
Пример #6
0
 /**
  * Returns the info database update page.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  *
  * @return array
  *   A render array.
  */
 protected function info(Request $request)
 {
     // Change query-strings on css/js files to enforce reload for all users.
     _drupal_flush_css_js();
     // Flush the cache of all data for the update status module.
     $this->keyValueExpirableFactory->get('update')->deleteAll();
     $this->keyValueExpirableFactory->get('update_available_release')->deleteAll();
     $build['info_header'] = array('#markup' => '<p>' . $this->t('Use this utility to update your database whenever a new release of Drupal or a module is installed.') . '</p><p>' . $this->t('For more detailed information, see the <a href="https://www.drupal.org/upgrade">upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.') . '</p>');
     $info[] = $this->t("<strong>Back up your code</strong>. Hint: when backing up module code, do not leave that backup in the 'modules' or 'sites/*/modules' directories as this may confuse Drupal's auto-discovery mechanism.");
     $info[] = $this->t('Put your site into <a href=":url">maintenance mode</a>.', array(':url' => Url::fromRoute('system.site_maintenance_mode')->toString(TRUE)->getGeneratedUrl()));
     $info[] = $this->t('<strong>Back up your database</strong>. This process will change your database values and in case of emergency you may need to revert to a backup.');
     $info[] = $this->t('Install your new files in the appropriate location, as described in the handbook.');
     $build['info'] = array('#theme' => 'item_list', '#list_type' => 'ol', '#items' => $info);
     $build['info_footer'] = array('#markup' => '<p>' . $this->t('When you have performed the steps above, you may proceed.') . '</p>');
     $build['link'] = array('#type' => 'link', '#title' => $this->t('Continue'), '#attributes' => array('class' => array('button', 'button--primary')), '#url' => Url::fromUri('base://selection'));
     return $build;
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function deleteCache($form_build_id)
 {
     $this->keyValueExpirableFactory->get('form')->delete($form_build_id);
     $this->keyValueExpirableFactory->get('form_state')->delete($form_build_id);
 }
Пример #8
0
 /**
  * Creates a PrivateTempStore.
  *
  * @param string $collection
  *   The collection name to use for this key/value store. This is typically
  *   a shared namespace or module name, e.g. 'views', 'entity', etc.
  *
  * @return \Drupal\user\PrivateTempStore
  *   An instance of the key/value store.
  */
 function get($collection)
 {
     // Store the data for this collection in the database.
     $storage = $this->storageFactory->get("user.private_tempstore.{$collection}");
     return new PrivateTempStore($storage, $this->lockBackend, $this->currentUser, $this->requestStack, $this->expire);
 }
Пример #9
0
 /**
  * Constructor.
  *
  * @param array $configuration
  *   A configuration array containing information about the plugin instance.
  * @param string $plugin_id
  *   The plugin_id for the plugin instance.
  * @param mixed $plugin_definition
  *   The plugin implementation definition.
  * @param MigrationInterface $migration
  *   The migration.
  * @param EntityManagerInterface $entity_manager
  *   The entity manager.
  * @param KeyValueExpirableFactoryInterface $temp_store_factory
  *   The temp store factory.
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityManagerInterface $entity_manager, KeyValueExpirableFactoryInterface $temp_store_factory)
 {
     parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $entity_manager);
     $this->tempStore = $temp_store_factory->get('multiversion_migration_' . $this->entityTypeId);
 }