/** * 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 buildForm(array $form, FormStateInterface $form_state) { $account = $this->currentUser()->id(); $this->modules = $this->keyValueExpirable->get($account); // Redirect to the modules list page if the key value store is empty. if (!$this->modules) { return $this->redirect('system.modules_list'); } $items = $this->buildMessageList(); $form['message'] = array('#theme' => 'item_list', '#items' => $items); return parent::buildForm($form, $form_state); }
/** * {@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; }
/** * {@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; }
/** * {@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; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $account = $this->currentUser()->id(); $this->modules = $this->keyValueExpirable->get($account); // Redirect to the modules list page if the key value store is empty. if (!$this->modules) { return $this->redirect('system.modules_list'); } $items = array(); // Display a list of required modules that have to be installed as well but // were not manually selected. foreach ($this->modules['dependencies'] as $module => $dependencies) { $items[] = $this->formatPlural(count($dependencies), 'You must enable the @required module to install @module.', 'You must enable the @required modules to install @module.', array('@module' => $this->modules['install'][$module], '@required' => implode(', ', $dependencies))); } $form['message'] = array('#theme' => 'item_list', '#items' => $items); return parent::buildForm($form, $form_state); }
/** * 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; }
/** * 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; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { // Retrieve the list of modules from the key value store. $account = $this->currentUser()->id(); $this->modules = $this->keyValueExpirable->get($account); // Prevent this page from showing when the module list is empty. if (empty($this->modules)) { return new RedirectResponse('/admin/modules/uninstall'); } $data = system_rebuild_module_data(); $form['text']['#markup'] = '<p>' . $this->t('The following modules will be completely uninstalled from your site, and <em>all data from these modules will be lost</em>!') . '</p>'; $form['modules'] = array('#theme' => 'item_list', '#items' => array_map(function ($module) use($data) { return $data[$module]->info['name']; }, $this->modules)); // List the dependent entities. $this->addDependencyListsToForm($form, 'module', $this->modules, $this->configManager, $this->entityManager); return parent::buildForm($form, $form_state); }
/** * {@inheritdoc} */ public function buildForm(array $form, array &$form_state) { // Retrieve the list of modules from the key value store. $account = $this->currentUser()->id(); $this->modules = $this->keyValueExpirable->get($account); // Prevent this page from showing when the module list is empty. if (empty($this->modules)) { return new RedirectResponse('/admin/modules/uninstall'); } $data = system_rebuild_module_data(); $form['text']['#markup'] = '<p>' . $this->t('The following modules will be completely uninstalled from your site, and <em>all data from these modules will be lost</em>!') . '</p>'; $form['modules'] = array('#theme' => 'item_list', '#items' => array_map(function ($module) use($data) { return $data[$module]->info['name']; }, $this->modules)); $form['entities'] = array('#type' => 'details', '#title' => $this->t('Configuration deletions'), '#description' => $this->t('The listed configuration will be deleted.'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#access' => FALSE); // Get the dependent entities. $entity_types = array(); $dependent_entities = $this->configManager->findConfigEntityDependentsAsEntities('module', $this->modules); foreach ($dependent_entities as $entity) { $entity_type_id = $entity->getEntityTypeId(); if (!isset($form['entities'][$entity_type_id])) { $entity_type = $this->entityManager->getDefinition($entity_type_id); // Store the ID and label to sort the entity types and entities later. $label = $entity_type->getLabel(); $entity_types[$entity_type_id] = $label; $form['entities'][$entity_type_id] = array('#theme' => 'item_list', '#title' => $label, '#items' => array()); } $form['entities'][$entity_type_id]['#items'][] = $entity->label(); } if (!empty($dependent_entities)) { $form['entities']['#access'] = TRUE; // Add a weight key to the entity type sections. asort($entity_types, SORT_FLAG_CASE); $weight = 0; foreach ($entity_types as $entity_type_id => $label) { $form['entities'][$entity_type_id]['#weight'] = $weight; // Sort the list of entity labels alphabetically. sort($form['entities'][$entity_type_id]['#items'], SORT_FLAG_CASE); $weight++; } } return parent::buildForm($form, $form_state); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { // Retrieve the list of modules from the key value store. $account = $this->currentUser()->id(); $this->modules = $this->keyValueExpirable->get($account); // Prevent this page from showing when the module list is empty. if (empty($this->modules)) { drupal_set_message($this->t('The selected modules could not be uninstalled, either due to a website problem or due to the uninstall confirmation form timing out. Please try again.'), 'error'); return $this->redirect('system.modules_uninstall'); } $data = system_rebuild_module_data(); $form['text']['#markup'] = '<p>' . $this->t('The following modules will be completely uninstalled from your site, and <em>all data from these modules will be lost</em>!') . '</p>'; $form['modules'] = array('#theme' => 'item_list', '#items' => array_map(function ($module) use($data) { return $data[$module]->info['name']; }, $this->modules)); // List the dependent entities. $this->addDependencyListsToForm($form, 'module', $this->modules, $this->configManager, $this->entityManager); return parent::buildForm($form, $form_state); }