/**
  * Autocomplete the label of an entity.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object that contains the typed tags.
  * @param string $target_type
  *   The ID of the target entity type.
  * @param string $selection_handler
  *   The plugin ID of the entity reference selection handler.
  * @param string $selection_settings_key
  *   The hashed key of the key/value entry that holds the selection handler
  *   settings.
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  *   The matched entity labels as a JSON response.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
  *   Thrown if the selection settings key is not found in the key/value store
  *   or if it does not match the stored data.
  */
 public function handleAutocomplete(Request $request, $target_type, $selection_handler, $selection_settings_key)
 {
     $matches = array();
     // Get the typed string from the URL, if it exists.
     if ($input = $request->query->get('q')) {
         $typed_string = Tags::explode($input);
         $typed_string = Unicode::strtolower(array_pop($typed_string));
         // Selection settings are passed in as a hashed key of a serialized array
         // stored in the key/value store.
         $selection_settings = $this->keyValue->get($selection_settings_key, FALSE);
         if ($selection_settings !== FALSE) {
             $selection_settings_hash = Crypt::hmacBase64(serialize($selection_settings) . $target_type . $selection_handler, Settings::getHashSalt());
             if ($selection_settings_hash !== $selection_settings_key) {
                 // Disallow access when the selection settings hash does not match the
                 // passed-in key.
                 throw new AccessDeniedHttpException('Invalid selection settings key.');
             }
         } else {
             // Disallow access when the selection settings key is not found in the
             // key/value store.
             throw new AccessDeniedHttpException();
         }
         $matches = $this->matcher->getMatches($target_type, $selection_handler, $selection_settings, $typed_string);
     }
     return new JsonResponse($matches);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function deleteMultiple(array $keys)
 {
     foreach ($keys as $key) {
         unset($this->cache[$key]);
     }
     $this->keyValueStore->deleteMultiple($keys);
 }
Ejemplo n.º 3
0
 /**
  * Filters out already executed update functions by module.
  *
  * @param string $module
  *   The module name.
  */
 public function filterOutInvokedUpdatesByModule($module)
 {
     $existing_update_functions = $this->keyValue->get('existing_updates', []);
     $remaining_update_functions = array_filter($existing_update_functions, function ($function_name) use($module) {
         return strpos($function_name, "{$module}_{$this->updateType}_") !== 0;
     });
     $this->keyValue->set('existing_updates', array_values($remaining_update_functions));
 }
Ejemplo n.º 4
0
 /**
  * @covers ::delete
  * @covers ::doDelete
  */
 public function testDeleteNothing()
 {
     $this->setUpKeyValueEntityStorage();
     $this->moduleHandler->expects($this->never())->method($this->anything());
     $this->keyValueStore->expects($this->never())->method('delete');
     $this->keyValueStore->expects($this->never())->method('deleteMultiple');
     $this->entityStorage->delete(array());
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function getAll()
 {
     if (!static::$all) {
         $this->cache = $this->keyValueStore->getAll();
         static::$all = TRUE;
     }
     return $this->cache;
 }
Ejemplo n.º 6
0
 /**
  * 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);
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function processFetchTask($project)
 {
     global $base_url;
     // This can be in the middle of a long-running batch, so REQUEST_TIME won't
     // necessarily be valid.
     $request_time_difference = time() - REQUEST_TIME;
     if (empty($this->failed)) {
         // If we have valid data about release history XML servers that we have
         // failed to fetch from on previous attempts, load that.
         $this->failed = $this->tempStore->get('fetch_failures');
     }
     $max_fetch_attempts = $this->updateSettings->get('fetch.max_attempts');
     $success = FALSE;
     $available = array();
     $site_key = Crypt::hmacBase64($base_url, $this->privateKey->get());
     $fetch_url_base = $this->updateFetcher->getFetchBaseUrl($project);
     $project_name = $project['name'];
     if (empty($this->failed[$fetch_url_base]) || $this->failed[$fetch_url_base] < $max_fetch_attempts) {
         $data = $this->updateFetcher->fetchProjectData($project, $site_key);
     }
     if (!empty($data)) {
         $available = $this->parseXml($data);
         // @todo: Purge release data we don't need. See
         //   https://www.drupal.org/node/238950.
         if (!empty($available)) {
             // Only if we fetched and parsed something sane do we return success.
             $success = TRUE;
         }
     } else {
         $available['project_status'] = 'not-fetched';
         if (empty($this->failed[$fetch_url_base])) {
             $this->failed[$fetch_url_base] = 1;
         } else {
             $this->failed[$fetch_url_base]++;
         }
     }
     $frequency = $this->updateSettings->get('check.interval_days');
     $available['last_fetch'] = REQUEST_TIME + $request_time_difference;
     $this->availableReleasesTempStore->setWithExpire($project_name, $available, $request_time_difference + 60 * 60 * 24 * $frequency);
     // Stash the $this->failed data back in the DB for the next 5 minutes.
     $this->tempStore->setWithExpire('fetch_failures', $this->failed, $request_time_difference + 60 * 5);
     // Whether this worked or not, we did just (try to) check for updates.
     $this->stateStore->set('update.last_check', REQUEST_TIME + $request_time_difference);
     // Now that we processed the fetch task for this project, clear out the
     // record for this task so we're willing to fetch again.
     $this->fetchTaskStore->delete($project_name);
     return $success;
 }
Ejemplo n.º 8
0
 /**
  * Tests fetching the derivatives on a view with a local task and a parent.
  *
  * The parent is defined by another module, not views.
  */
 public function testGetDerivativeDefinitionsWithExistingLocalTask()
 {
     $executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->getMock();
     $storage = $this->getMockBuilder('Drupal\\views\\Entity\\View')->disableOriginalConstructor()->getMock();
     $storage->expects($this->any())->method('id')->will($this->returnValue('example_view'));
     $storage->expects($this->any())->method('getExecutable')->willReturn($executable);
     $executable->storage = $storage;
     $this->viewStorage->expects($this->any())->method('load')->with('example_view')->willReturn($storage);
     $display_plugin = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\PathPluginBase')->setMethods(array('getOption', 'getPath'))->disableOriginalConstructor()->getMockForAbstractClass();
     $display_plugin->expects($this->exactly(2))->method('getOption')->with('menu')->will($this->returnValue(array('type' => 'tab', 'weight' => 12, 'title' => 'Example title')));
     $display_plugin->expects($this->once())->method('getPath')->will($this->returnValue('path/example'));
     $executable->display_handler = $display_plugin;
     $result = [['example_view', 'page_1']];
     $this->localTaskDerivative->setApplicableMenuViews($result);
     // Mock the view route names state.
     $view_route_names = array();
     $view_route_names['example_view.page_1'] = 'view.example_view.page_1';
     $this->state->expects($this->exactly(2))->method('get')->with('views.view_route_names')->will($this->returnValue($view_route_names));
     // Mock the route provider.
     $route_collection = new RouteCollection();
     $route_collection->add('test_route', new Route('/path'));
     $this->routeProvider->expects($this->any())->method('getRoutesByPattern')->with('/path')->will($this->returnValue($route_collection));
     // Setup the existing local task of the test_route.
     $definitions['test_route_tab'] = $other_tab = array('route_name' => 'test_route', 'title' => 'Test route', 'base_route' => 'test_route');
     $definitions += $this->localTaskDerivative->getDerivativeDefinitions($this->baseDefinition);
     // Setup the prefix of the derivative.
     $definitions['views_view:view.example_view.page_1'] = $definitions['view.example_view.page_1'];
     unset($definitions['view.example_view.page_1']);
     $this->localTaskDerivative->alterLocalTasks($definitions);
     $plugin = $definitions['views_view:view.example_view.page_1'];
     $this->assertCount(2, $definitions);
     // Ensure the other local task was not changed.
     $this->assertEquals($other_tab, $definitions['test_route_tab']);
     $this->assertEquals('view.example_view.page_1', $plugin['route_name']);
     $this->assertEquals(12, $plugin['weight']);
     $this->assertEquals('Example title', $plugin['title']);
     $this->assertEquals($this->baseDefinition['class'], $plugin['class']);
     $this->assertEquals('test_route', $plugin['base_route']);
 }
Ejemplo n.º 9
0
 /**
  * Stores the entity type's field storage definitions in the application state.
  *
  * @param string $entity_type_id
  *   The entity type identifier.
  * @param \Drupal\Core\Field\FieldStorageDefinitionInterface[] $storage_definitions
  *   An array of field storage definitions.
  */
 protected function setLastInstalledFieldStorageDefinitions($entity_type_id, array $storage_definitions)
 {
     $this->installedDefinitions->set($entity_type_id . '.field_storage_definitions', $storage_definitions);
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 protected function has($id, EntityInterface $entity)
 {
     return $this->keyValueStore->has($id);
 }