/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $io->newLine(); $io->comment($this->trans('commands.node.access.rebuild.messages.rebuild')); $batch = $input->getOption('batch'); try { node_access_rebuild($batch); } catch (\Exception $e) { $io->error($e->getMessage()); return 1; } $needs_rebuild = $this->state->get('node.node_access_needs_rebuild') ?: false; if ($needs_rebuild) { $io->error($this->trans('commands.node.access.rebuild.messages.failed')); return 1; } $io->success($this->trans('commands.node.access.rebuild.messages.completed')); return 0; }
/** * {@inheritdoc} */ public function regenerateBatchFinished($success, $results, $operations, $elapsed) { if ($success && $this->state->get('xmlsitemap_regenerate_needed') == FALSE) { $this->state->set('xmlsitemap_generated_last', REQUEST_TIME); drupal_set_message(t('The sitemaps were regenerated.')); // Show a watchdog message that the sitemap was regenerated. watchdog('xmlsitemap', 'Finished XML sitemap generation in @elapsed. Memory usage: @memory-peak.', array('@elapsed' => $elapsed, '@memory-peak' => format_size(memory_get_peak_usage(TRUE))), WATCHDOG_NOTICE); } else { drupal_set_message(t('The sitemaps were not successfully regenerated.'), 'error'); } }
/** * Tests migration events. */ public function testMigrateEvents() { // Run a simple little migration, which should trigger one of each event // other than map_delete. $definition = ['migration_tags' => ['Event test'], 'source' => ['plugin' => 'embedded_data', 'data_rows' => [['data' => 'dummy value']], 'ids' => ['data' => ['type' => 'string']]], 'process' => ['value' => 'data'], 'destination' => ['plugin' => 'dummy']]; $migration = new Migration([], uniqid(), $definition); $executable = new MigrateExecutable($migration, new MigrateMessage()); // As the import runs, events will be dispatched, recording the received // information in state. $executable->import(); // Validate from the recorded state that the events were received. $event = $this->state->get('migrate_events_test.pre_import_event', []); $this->assertIdentical($event['event_name'], MigrateEvents::PRE_IMPORT); $this->assertIdentical($event['migration']->id(), $migration->id()); $event = $this->state->get('migrate_events_test.post_import_event', []); $this->assertIdentical($event['event_name'], MigrateEvents::POST_IMPORT); $this->assertIdentical($event['migration']->id(), $migration->id()); $event = $this->state->get('migrate_events_test.map_save_event', []); $this->assertIdentical($event['event_name'], MigrateEvents::MAP_SAVE); // Validating the last row processed. $this->assertIdentical($event['fields']['sourceid1'], 'dummy value'); $this->assertIdentical($event['fields']['destid1'], 'dummy value'); $this->assertIdentical($event['fields']['source_row_status'], 0); $event = $this->state->get('migrate_events_test.map_delete_event', []); $this->assertIdentical($event, []); $event = $this->state->get('migrate_events_test.pre_row_save_event', []); $this->assertIdentical($event['event_name'], MigrateEvents::PRE_ROW_SAVE); $this->assertIdentical($event['migration']->id(), $migration->id()); // Validating the last row processed. $this->assertIdentical($event['row']->getSourceProperty('data'), 'dummy value'); $event = $this->state->get('migrate_events_test.post_row_save_event', []); $this->assertIdentical($event['event_name'], MigrateEvents::POST_ROW_SAVE); $this->assertIdentical($event['migration']->id(), $migration->id()); // Validating the last row processed. $this->assertIdentical($event['row']->getSourceProperty('data'), 'dummy value'); $this->assertIdentical($event['destination_id_values']['value'], 'dummy value'); // Generate a map delete event. $migration->getIdMap()->delete(['data' => 'dummy value']); $event = $this->state->get('migrate_events_test.map_delete_event', []); $this->assertIdentical($event['event_name'], MigrateEvents::MAP_DELETE); $this->assertIdentical($event['source_id'], ['data' => 'dummy value']); }
/** * Submit callback for the fields error form. */ public function submitFieldAttach(array &$form, FormStateInterface $form_state) { $this->state->set('ds.disabled', $this->state->get('ds.disabled', FALSE) ? FALSE : TRUE); drupal_set_message(t('The configuration options have been saved.')); }
/** * Perform the anonymous user redirection, if needed. * * This method is called whenever the KernelEvents::REQUEST event is * dispatched. * * @param GetResponseEvent $event */ public function redirect(GetResponseEvent $event) { // Skip if maintenance mode is enabled. if ($this->state->get('system.maintenance_mode')) { return; } // Skip if running from the command-line. if (PHP_SAPI === 'cli') { return; } // Skip if no paths are configured for redirecting. if (!($paths = $this->paths()) || empty($paths['include'])) { return; } // Skip if the user is not anonymous. if (!$this->current_user->isAnonymous()) { return; } // Determine the current path and alias. $current = [ 'path' => $this->path_current->getPath(), 'alias' => \Drupal::request()->getRequestUri(), ]; // Ignore PHP file requests. if (substr($current['path'], -4) == '.php') { return; } // Ignore the user login page. if ($current['path'] == '/user/login') { return; } // Convert the path to the front page token, if needed. $current['path'] = ($current['path'] != '/') ? $current['path'] : '<front>'; // Track if we should redirect. $redirect = FALSE; // Iterate the current path and alias. foreach ($current as &$check) { // Remove the leading slash. $check = substr($check, 1); // Check if there is a trailer slash. if (substr($check, -1) == '/') { // Remove it. $check = substr($check, 0, strlen($check) - 1); } // Redirect if the path is a match for included paths. if ($this->path_matcher->matchPath($check, implode("\n", $paths['include']))) { $redirect = TRUE; } // Do not redirect if the path is a match for excluded paths. if ($this->path_matcher->matchPath($check, implode("\n", $paths['exclude']))) { $redirect = FALSE; // Matching an excluded path is a hard-stop. break; } } // See if we're going to redirect. if ($redirect) { // See if we have a message to display. if ($message = $this->config_factory->get('anonymous_login.settings')->get('message')) { // @todo: translation? // @todo: This does not show after the redirect.. drupal_set_message($message); } // Redirect to the login, keeping the requested alias as the destination. $response = new RedirectResponse('/user/login?destination=' . $current['alias']); $response->send(); exit(); } }