/**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Retrieve a list of modules to install and their dependencies.
     $modules = $this->buildModuleList($form_state);
     // Check if we have to install any dependencies. If there is one or more
     // dependencies that are not installed yet, redirect to the confirmation
     // form.
     if (!empty($modules['dependencies']) || !empty($modules['missing'])) {
         // Write the list of changed module states into a key value store.
         $account = $this->currentUser()->id();
         $this->keyValueExpirable->setWithExpire($account, $modules, 60);
         // Redirect to the confirmation form.
         $form_state->setRedirect('system.modules_list_confirm');
         // We can exit here because at least one modules has dependencies
         // which we have to prompt the user for in a confirmation form.
         return;
     }
     // Install the given modules.
     if (!empty($modules['install'])) {
         try {
             $this->moduleInstaller->install(array_keys($modules['install']));
             $module_names = array_values($modules['install']);
             drupal_set_message($this->formatPlural(count($module_names), 'Module %name has been enabled.', '@count modules have been enabled: %names.', array('%name' => $module_names[0], '%names' => implode(', ', $module_names))));
         } catch (PreExistingConfigException $e) {
             $config_objects = $e->flattenConfigObjects($e->getConfigObjects());
             drupal_set_message($this->formatPlural(count($config_objects), 'Unable to install @extension, %config_names already exists in active configuration.', 'Unable to install @extension, %config_names already exist in active configuration.', array('%config_names' => implode(', ', $config_objects), '@extension' => $modules['install'][$e->getExtension()])), 'error');
             return;
         } catch (UnmetDependenciesException $e) {
             drupal_set_message($e->getTranslatedMessage($this->getStringTranslation(), $modules['install'][$e->getExtension()]), 'error');
             return;
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Retrieve a list of modules to install and their dependencies.
     $modules = $this->buildModuleList($form_state);
     // Check if we have to install any dependencies. If there is one or more
     // dependencies that are not installed yet, redirect to the confirmation
     // form.
     if (!empty($modules['dependencies']) || !empty($modules['missing'])) {
         // Write the list of changed module states into a key value store.
         $account = $this->currentUser()->id();
         $this->keyValueExpirable->setWithExpire($account, $modules, 60);
         // Redirect to the confirmation form.
         $form_state->setRedirect('system.modules_list_confirm');
         // We can exit here because at least one modules has dependencies
         // which we have to prompt the user for in a confirmation form.
         return;
     }
     // Gets list of modules prior to install process.
     $before = $this->moduleHandler->getModuleList();
     // There seem to be no dependencies that would need approval.
     if (!empty($modules['install'])) {
         $this->moduleHandler->install(array_keys($modules['install']));
     }
     // Gets module list after install process, flushes caches and displays a
     // message if there are changes.
     if ($before != $this->moduleHandler->getModuleList()) {
         drupal_set_message(t('The configuration options have been saved.'));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Remove the key value store entry.
     $account = $this->currentUser()->id();
     $this->keyValueExpirable->delete($account);
     if (!empty($this->modules['install'])) {
         // Don't catch the exception that this can throw for missing dependencies:
         // the form doesn't allow modules with unmet dependencies, so the only way
         // this can happen is if the filesystem changed between form display and
         // submit, in which case the user has bigger problems.
         try {
             // Install the given modules.
             $this->moduleInstaller->install(array_keys($this->modules['install']));
         } catch (PreExistingConfigException $e) {
             $config_objects = $e->flattenConfigObjects($e->getConfigObjects());
             drupal_set_message($this->formatPlural(count($config_objects), 'Unable to install @extension, %config_names already exists in active configuration.', 'Unable to install @extension, %config_names already exist in active configuration.', array('%config_names' => implode(', ', $config_objects), '@extension' => $this->modules['install'][$e->getExtension()])), 'error');
             return;
         } catch (UnmetDependenciesException $e) {
             drupal_set_message($e->getTranslatedMessage($this->getStringTranslation(), $this->modules['install'][$e->getExtension()]), 'error');
             return;
         }
         $module_names = array_values($this->modules['install']);
         drupal_set_message($this->formatPlural(count($module_names), 'Module %name has been enabled.', '@count modules have been enabled: %names.', array('%name' => $module_names[0], '%names' => implode(', ', $module_names))));
     }
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
Example #4
0
 /**
  * @covers ::deleteCache
  */
 public function testDeleteCache()
 {
     $form_build_id = 'the_form_build_id';
     $this->formCacheStore->expects($this->once())->method('delete')->with($form_build_id);
     $this->formStateCacheStore->expects($this->once())->method('delete')->with($form_build_id);
     $this->formCache->deleteCache($form_build_id);
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Save all the values in an expirable key value store.
     $modules = $form_state->getValue('uninstall');
     $uninstall = array_keys(array_filter($modules));
     $account = $this->currentUser()->id();
     $this->keyValueExpirable->setWithExpire($account, $uninstall, 60);
     // Redirect to the confirm form.
     $form_state->setRedirect('system.modules_uninstall_confirm');
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Clear the key value store entry.
     $account = $this->currentUser()->id();
     $this->keyValueExpirable->delete($account);
     // Uninstall the modules.
     $this->moduleInstaller->uninstall($this->modules);
     drupal_set_message($this->t('The selected modules have been uninstalled.'));
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
Example #7
0
 /**
  * Deletes data from the store for a given key and releases the lock on it.
  *
  * Only delete the given key if it is owned by $this->owner.
  *
  * @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 deleteIfOwner($key)
 {
     if (!($object = $this->storage->get($key))) {
         return TRUE;
     } elseif ($object->owner == $this->owner) {
         $this->delete($key);
         return TRUE;
     }
     return FALSE;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     // Save all the values in an expirable key value store.
     $modules = $form_state['values']['uninstall'];
     $uninstall = array_keys(array_filter($modules));
     $account = $this->currentUser()->id();
     $this->keyValueExpirable->setWithExpire($account, $uninstall, 60);
     // Redirect to the confirm form.
     $form_state['redirect_route']['route_name'] = 'system.modules_uninstall_confirm';
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     // Clear the key value store entry.
     $account = $this->currentUser()->id();
     $this->keyValueExpirable->delete($account);
     // Uninstall the modules.
     $this->moduleHandler->uninstall($this->modules);
     drupal_set_message($this->t('The selected modules have been uninstalled.'));
     $form_state['redirect_route'] = $this->getCancelRoute();
 }
Example #10
0
 /**
  * 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'));
 }
Example #11
0
 /**
  * {@inheritdoc}
  */
 public function projectStorage($key)
 {
     $projects = array();
     // On certain paths, we should clear the data and recompute the projects for
     // update status of the site to avoid presenting stale information.
     $paths = array('admin/modules', 'admin/modules/update', 'admin/appearance', 'admin/appearance/update', 'admin/reports', 'admin/reports/updates', 'admin/reports/updates/update', 'admin/reports/status', 'admin/reports/updates/check');
     if (in_array(current_path(), $paths)) {
         $this->keyValueStore->delete($key);
     } else {
         $projects = $this->keyValueStore->get($key, array());
     }
     return $projects;
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function projectStorage($key)
 {
     $projects = array();
     // On certain paths, we should clear the data and recompute the projects for
     // update status of the site to avoid presenting stale information.
     $route_names = array('update.theme_update', 'system.modules_list', 'system.theme_install', 'update.module_update', 'update.module_install', 'update.status', 'update.report_update', 'update.report_install', 'update.settings', 'system.status', 'update.manual_status', 'update.confirmation_page', 'system.themes_page');
     if (in_array(\Drupal::routeMatch()->getRouteName(), $route_names)) {
         $this->keyValueStore->delete($key);
     } else {
         $projects = $this->keyValueStore->get($key, array());
     }
     return $projects;
 }
Example #13
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;
 }
Example #14
0
 /**
  * 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;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Remove the key value store entry.
     $account = $this->currentUser()->id();
     $this->keyValueExpirable->delete($account);
     // Gets list of modules prior to install process.
     $before = $this->moduleHandler->getModuleList();
     // Install the given modules.
     if (!empty($this->modules['install'])) {
         $this->moduleHandler->install(array_keys($this->modules['install']));
     }
     // Gets module list after install process, flushes caches and displays a
     // message if there are changes.
     if ($before != $this->moduleHandler->getModuleList()) {
         drupal_set_message($this->t('The configuration options have been saved.'));
     }
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
 /**
  * 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;
 }
 /**
  * @covers ::setCache
  */
 public function testSetCacheImmutableForm()
 {
     $form_build_id = 'the_form_build_id';
     $form = ['#form_id' => 'the_form_id'];
     $form_state = new FormState();
     $this->formCacheStore->expects($this->once())->method('setWithExpire')->with($form_build_id, $form, $this->isType('int'));
     $form_state_data = $form_state->getCacheableArray();
     $form_state_data['build_info']['safe_strings'] = [];
     // Ensure that the form is marked immutable.
     $form_state_data['build_info']['immutable'] = TRUE;
     $this->formStateCacheStore->expects($this->once())->method('setWithExpire')->with($form_build_id, $form_state_data, $this->isType('int'));
     // Rebuild the FormCache with a config factory that will return a config
     // object with the internal page cache enabled.
     $this->configFactory = $this->getConfigFactoryStub(['system.performance' => ['cache.page.use_internal' => TRUE]]);
     $this->formCache = $this->getMockBuilder('Drupal\\Core\\Form\\FormCache')->setConstructorArgs([$this->keyValueExpirableFactory, $this->moduleHandler, $this->account, $this->csrfToken, $this->logger, $this->configFactory, $this->requestStack, $this->requestPolicy])->setMethods(['isPageCacheable'])->getMock();
     $this->formCache->expects($this->once())->method('isPageCacheable')->willReturn(TRUE);
     $this->formCache->setCache($form_build_id, $form, $form_state);
 }
Example #18
0
 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     $source = $row->getSource();
     $this->tempStore->setWithExpire($source['uuid'], $source, $this->expire);
     return array($this->entityIdKey => $source[$this->entityIdKey]);
 }
Example #19
0
 /**
  * {@inheritdoc}
  */
 protected function initializeIterator()
 {
     $values = $this->tempStore->getAll();
     return new \ArrayIterator($values);
 }