/**
  * {@inheritdoc}
  */
 public function stopTracking(IndexInterface $index, array $datasource_ids = NULL)
 {
     $valid_tracker = $index->hasValidTracker();
     if (!isset($datasource_ids)) {
         $this->state->delete($this->getIndexStateKey($index));
         if ($valid_tracker) {
             $index->getTrackerInstance()->trackAllItemsDeleted();
         }
         return;
     }
     // Catch the case of being called with an empty array of datasources.
     if (!$datasource_ids) {
         return;
     }
     // If no state is saved, this will return NULL, making the following unset()
     // statements no-ops.
     $index_state = $this->getIndexState($index, FALSE);
     foreach ($datasource_ids as $datasource_id) {
         unset($index_state['pages'][$datasource_id]);
         if ($valid_tracker) {
             $index->getTrackerInstance()->trackAllItemsDeleted($datasource_id);
         }
     }
     // If we had an index state saved, update it now.
     if (isset($index_state)) {
         if (empty($index_state['pages'])) {
             $this->state->delete($this->getIndexStateKey($index));
         } else {
             $this->state->set($this->getIndexStateKey($index), $index_state);
         }
     }
 }
 /**
  * Utility submit function to reset the demo.
  *
  * @param array $form
  *   FormAPI form.
  * @param FormStateInterface $form_state
  *   FormAPI form state.
  *
  * @todo Note this does NOT clear any managed file references in Drupal's DB.
  *       It might be a good idea to add this.
  */
 public function handleResetSession(array &$form, FormStateInterface $form_state)
 {
     $this->state->delete('file_example_default_file');
     $this->state->delete('file_example_default_directory');
     $this->clearStoredData();
     drupal_set_message('Session reset.');
 }
Exemple #3
0
 /**
  * Retrieves the methods called on the test server.
  *
  * @param bool $reset
  *   (optional) Whether to reset the list after the called methods are
  *   retrieved.
  *
  * @return string[]
  *   The methods called on the test server since the last reset.
  */
 protected function getCalledServerMethods($reset = TRUE) {
   $key = 'search_api_test_backend.methods_called.' . $this->server->id();
   $methods_called = $this->state->get($key, array());
   if ($reset) {
     $this->state->delete($key);
   }
   return $methods_called;
 }
 /**
  * {@inheritdoc}
  */
 public function deleteAll()
 {
     $this->state->delete('drupal_css_cache_files');
     $delete_stale = function ($uri) {
         // Default stale file threshold is 30 days.
         if (REQUEST_TIME - filemtime($uri) > \Drupal::config('system.performance')->get('stale_file_threshold')) {
             file_unmanaged_delete($uri);
         }
     };
     file_scan_directory('public://css', '/.*/', array('callback' => $delete_stale));
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $name = $input->getArgument('name');
     if (!$name) {
         $io->error($this->trans('commands.state.delete.messages.enter-name'));
         return 1;
     }
     if (!$this->state->get($name)) {
         $io->error(sprintf($this->trans('commands.state.delete.messages.state-not-exists'), $name));
         return 1;
     }
     try {
         $this->state->delete($name);
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return 1;
     }
     $io->success(sprintf($this->trans('commands.state.delete.messages.deleted'), $name));
     return 0;
 }
 /**
  * Submission handler for the confirmation form.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  */
 public function submitConfirmForm(array &$form, FormStateInterface $form_state)
 {
     $storage = $form_state->getStorage();
     if (isset($storage['upgrade_option']) && $storage['upgrade_option'] == static::MIGRATE_UPGRADE_ROLLBACK) {
         $query = $this->entityStorage->getQuery();
         $names = $query->execute();
         // Order the migrations according to their dependencies.
         /** @var \Drupal\migrate\Entity\MigrationInterface[] $migrations */
         $migrations = $this->entityStorage->loadMultiple($names);
         // Assume we want all those tagged 'Drupal %'.
         foreach ($migrations as $migration_id => $migration) {
             $keep = FALSE;
             $tags = $migration->get('migration_tags');
             foreach ($tags as $tag) {
                 if (strpos($tag, 'Drupal ') === 0) {
                     $keep = TRUE;
                     break;
                 }
             }
             if (!$keep) {
                 unset($migrations[$migration_id]);
             }
         }
         // Roll back in reverse order.
         $migrations = array_reverse($migrations);
         $batch = ['title' => $this->t('Rolling back upgrade'), 'progress_message' => '', 'operations' => [[[MigrateUpgradeRunBatch::class, 'run'], [array_keys($migrations), 'rollback']]], 'finished' => [MigrateUpgradeRunBatch::class, 'finished']];
         batch_set($batch);
         $form_state->setRedirect('migrate_upgrade.upgrade');
         $this->state->delete('migrate_upgrade.performed');
     } else {
         $migration_template = $storage['migration_template'];
         $migration_ids = $this->createMigrations($migration_template);
         $batch = ['title' => $this->t('Running upgrade'), 'progress_message' => '', 'operations' => [[[MigrateUpgradeRunBatch::class, 'run'], [$migration_ids, 'import']]], 'finished' => [MigrateUpgradeRunBatch::class, 'finished']];
         batch_set($batch);
         $form_state->setRedirect('<front>');
         $this->state->set('migrate_upgrade.performed', REQUEST_TIME);
     }
 }
Exemple #7
0
 /**
  * {@inheritdoc}
  */
 public function delete($key)
 {
     $this->state->delete($key);
 }