protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $module = $input->getArgument('module'); $module_handler = $this->getModuleHandler(); if ($module != 'all') { $modules = [$module]; } else { $modules = $module_handler->getImplementations('cron'); } foreach ($modules as $module) { if ($module_handler->implementsHook($module, 'cron')) { $io->info(sprintf($this->trans('commands.cron.execute.messages.executing-cron'), $module)); try { $module_handler->invoke($module, 'cron'); } catch (\Exception $e) { watchdog_exception('cron', $e); $io->error($e->getMessage()); } } else { $io->warning(sprintf($this->trans('commands.cron.execute.messages.module-invalid'), $module)); } } $this->getChain()->addCommand('cache:rebuild', ['cache' => 'all']); }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $modules = $input->getArgument('module'); $module_handler = $this->getDrupalService('module_handler'); $lock = $this->getDrupalService('lock'); // Try to acquire cron lock. if (!$lock->acquire('cron', 900.0)) { $io->warning($this->trans('commands.cron.execute.messages.lock')); return; } if (in_array('all', $modules)) { $modules = $module_handler->getImplementations('cron'); } foreach ($modules as $module) { if ($module_handler->implementsHook($module, 'cron')) { $io->info(sprintf($this->trans('commands.cron.execute.messages.executing-cron'), $module)); try { $module_handler->invoke($module, 'cron'); } catch (\Exception $e) { watchdog_exception('cron', $e); $io->error($e->getMessage()); } } else { $io->warning(sprintf($this->trans('commands.cron.execute.messages.module-invalid'), $module)); } } // Set last time cron was executed \Drupal::state()->set('system.cron_last', REQUEST_TIME); // Release cron lock. $lock->release('cron'); $this->get('chain_queue')->addCommand('cache:rebuild', ['cache' => 'all']); $io->success($this->trans('commands.cron.execute.messages.success')); }
public function alterItems(array &$items) { // Prevent session information from being saved while indexing. drupal_save_session(FALSE); // Force the current user to anonymous to prevent access bypass in search // indexes. $original_user = $GLOBALS['user']; $GLOBALS['user'] = drupal_anonymous_user(); $entity_type = $this->index->getEntityType(); $entity_handler = panelizer_entity_plugin_get_handler($entity_type); foreach ($items as &$item) { $entity_id = entity_id($entity_type, $item); $item->search_api_panelizer_content = NULL; $item->search_api_panelizer_title = NULL; try { if ($render_info = $entity_handler->render_entity($item, 'page_manager')) { $item->search_api_panelizer_content = $render_info['content']; $item->search_api_panelizer_title = !empty($render_info['title']) ? $render_info['title'] : NULL; } } catch (Exception $e) { watchdog_exception('panelizer', $e, 'Error indexing Panelizer content for %entity_type with ID %entity_id', array('%entity_type' => $entity_type, '%entity_id' => $entity_id)); } } // Restore the user. $GLOBALS['user'] = $original_user; drupal_save_session(TRUE); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $modules = $input->getArgument('module'); if (!$this->lock->acquire('cron', 900.0)) { $io->warning($this->trans('commands.cron.execute.messages.lock')); return 1; } if (in_array('all', $modules)) { $modules = $this->moduleHandler->getImplementations('cron'); } foreach ($modules as $module) { if (!$this->moduleHandler->implementsHook($module, 'cron')) { $io->warning(sprintf($this->trans('commands.cron.execute.messages.module-invalid'), $module)); continue; } try { $io->info(sprintf($this->trans('commands.cron.execute.messages.executing-cron'), $module)); $this->moduleHandler->invoke($module, 'cron'); } catch (\Exception $e) { watchdog_exception('cron', $e); $io->error($e->getMessage()); } } $this->state->set('system.cron_last', REQUEST_TIME); $this->lock->release('cron'); $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); $io->success($this->trans('commands.cron.execute.messages.success')); return 0; }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { /** @var \Drupal\search_api\ServerInterface $server */ $server = $this->getEntity(); try { $server->deleteAllItems(); drupal_set_message($this->t('All indexed data was successfully deleted from the server.')); } catch (SearchApiException $e) { drupal_set_message($this->t('Indexed data could not be cleared for some indexes. Check the logs for details.'), 'error'); } $failed_reindexing = array(); $properties = array('status' => TRUE, 'read_only' => FALSE); foreach ($server->getIndexes($properties) as $index) { try { $index->reindex(); } catch (SearchApiException $e) { $args = array('%index' => $index->label()); watchdog_exception('search_api', $e, '%type while clearing index %index: @message in %function (line %line of %file).', $args); $failed_reindexing[] = $index->label(); } } if ($failed_reindexing) { $args = array('@indexes' => implode(', ', $failed_reindexing)); drupal_set_message($this->t('Failed to mark the following indexes for reindexing: @indexes. Check the logs for details.', $args), 'warning'); } $form_state->setRedirect('entity.search_api_server.canonical', array('search_api_server' => $server->id())); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, ServerInterface $search_api_server = NULL) { $form['#title'] = $this->t('List of configuration files found'); try { // Retrieve the list of available files. $files_list = SearchApiSolrUtility::getServerFiles($search_api_server); if (empty($files_list)) { $form['info']['#markup'] = $this->t('No files found.'); return $form; } $form['files_tabs'] = array('#type' => 'vertical_tabs'); // Generate a fieldset for each file. foreach ($files_list as $file_name => $file_info) { $file_date = format_date(strtotime($file_info['modified'])); $escaped_file_name = SafeMarkup::checkPlain($file_name); $form['files'][$file_name] = array('#type' => 'details', '#title' => $escaped_file_name, '#group' => 'files_tabs'); $data = '<h3>' . $escaped_file_name . '</h3>'; $data .= '<p><em>' . $this->t('Last modified: @time.', array('@time' => $file_date)) . '</em></p>'; if ($file_info['size'] > 0) { $file_data = $search_api_server->getBackend()->getFile($file_name); $data .= '<pre><code>' . SafeMarkup::checkPlain($file_data->getBody()) . '</code></pre>'; } else { $data .= '<p><em>' . $this->t('The file is empty.') . '</em></p>'; } $form['files'][$file_name]['data']['#markup'] = $data; } } catch (SearchApiException $e) { watchdog_exception('search_api_solr', $e, '%type while retrieving config files of Solr server @server: !message in %function (line %line of %file).', array('@server' => $search_api_server->label())); $form['info']['#markup'] = $this->t('An error occured while trying to load the list of files.'); } return $form; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $styles = $input->getArgument('styles'); $result = 0; $imageStyle = $this->entityTypeManager->getStorage('image_style'); $stylesNames = []; if (in_array('all', $styles)) { $styles = $imageStyle->loadMultiple(); foreach ($styles as $style) { $stylesNames[] = $style->get('name'); } $styles = $stylesNames; } foreach ($styles as $style) { try { $io->info(sprintf($this->trans('commands.image.styles.flush.messages.executing-flush'), $style)); $imageStyle->load($style)->flush(); } catch (\Exception $e) { watchdog_exception('image', $e); $io->error($e->getMessage()); $result = 1; } } $io->success($this->trans('commands.image.styles.flush.messages.success')); return $result; }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); /** @var \Drupal\embed\EmbedButtonInterface $button */ $button = $this->entity; $form_state->setTemporaryValue('embed_button', $button); $form['label'] = ['#title' => $this->t('Label'), '#type' => 'textfield', '#default_value' => $button->label(), '#description' => t('The human-readable name of this embed button. This text will be displayed when the user hovers over the CKEditor button. This name must be unique.'), '#required' => TRUE, '#size' => 30]; $form['id'] = ['#type' => 'machine_name', '#default_value' => $button->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#disabled' => !$button->isNew(), '#machine_name' => ['exists' => ['Drupal\\embed\\Entity\\EmbedButton', 'load']], '#description' => $this->t('A unique machine-readable name for this embed button. It must only contain lowercase letters, numbers, and underscores.')]; $form['type_id'] = ['#type' => 'select', '#title' => $this->t('Embed type'), '#options' => $this->embedTypeManager->getDefinitionOptions(), '#default_value' => $button->getTypeId(), '#required' => TRUE, '#ajax' => ['callback' => '::updateTypeSettings', 'effect' => 'fade'], '#disabled' => !$button->isNew()]; if (count($form['type_id']['#options']) == 0) { drupal_set_message($this->t('No embed types found.'), 'warning'); } // Add the embed type plugin settings. $form['type_settings'] = ['#type' => 'container', '#tree' => TRUE, '#prefix' => '<div id="embed-type-settings-wrapper">', '#suffix' => '</div>']; try { if ($plugin = $button->getTypePlugin()) { $form['type_settings'] = $plugin->buildConfigurationForm($form['type_settings'], $form_state); } } catch (PluginNotFoundException $exception) { drupal_set_message($exception->getMessage(), 'error'); watchdog_exception('embed', $exception); $form['type_id']['#disabled'] = FALSE; } $config = $this->config('embed.settings'); $upload_location = $config->get('file_scheme') . '://' . $config->get('upload_directory') . '/'; $form['icon_file'] = ['#title' => $this->t('Button icon'), '#type' => 'managed_file', '#description' => $this->t('Icon for the button to be shown in CKEditor toolbar. Leave empty to use the default Entity icon.'), '#upload_location' => $upload_location, '#upload_validators' => ['file_validate_extensions' => ['gif png jpg jpeg'], 'file_validate_image_resolution' => ['32x32', '16x16']]]; if ($file = $button->getIconFile()) { $form['icon_file']['#default_value'] = ['target_id' => $file->id()]; } return $form; }
/** * Import the culturefeed domains. */ public function import() { $this->client = new Client($this::END_POINT); try { $body = $this->client->get('heading_categorisation.xml')->send()->getBody(TRUE); $this->importHeadings(new SimpleXMLElement($body)); } catch (ClientErrorResponseException $e) { watchdog_exception('culturefeed_cnapi_import', $e); } }
/** * Registers the autoloader. */ public function onRequest(GetResponseEvent $event) { try { $this->registerAutoloader(); } catch (\RuntimeException $e) { if (PHP_SAPI !== 'cli') { watchdog_exception('search_api_solr', $e, NULL, array(), RfcLogLevel::WARNING); } } }
/** * Send the request to service. * * @param $identifiers * Pass requested identifiers. * @return mixed * Response object or error message. */ protected function sendRequest($identifiers) { $authInfo = array('authenticationUser' => $this->username, 'authenticationGroup' => $this->group, 'authenticationPassword' => $this->password); $client = new SoapClient($this->wsdlUrl); try { $response = $client->moreInfo(array('authentication' => $authInfo, 'identifier' => $identifiers)); } catch (Exception $e) { watchdog_exception('artesis_netarchive', $e); } return $response; }
/** * {@inheritdoc} */ public function fetchProjectData(array $project, $site_key = '') { $url = $this->buildFetchUrl($project, $site_key); $data = ''; try { $data = $this->httpClient->get($url, array('headers' => array('Accept' => 'text/xml')))->getBody(TRUE); } catch (RequestException $exception) { watchdog_exception('update', $exception); } return $data; }
/** * {@inheritdoc} */ public function getEmbedObject($url) { $embed = NULL; try { $response = $this->httpClient->get($this->getEmbedProviderURL($url), array('headers' => array('content-type' => 'application/json'))); $embed = json_decode($response->getBody()); } catch (GuzzleClientException $e) { watchdog_exception('ckeditor_media_embed', $e); } return $embed; }
/** * Import the culturefeed domains. */ public function import() { $this->client = new Client($this::END_POINT); try { // Cities. $body = $this->client->get('city')->send()->getBody(TRUE); $this->importCities(new SimpleXMLElement($body)); } catch (ClientErrorResponseException $e) { watchdog_exception('culturefeed_city_import', $e); } }
/** * @param string $title * * @return bool */ public static function isTitleInUse($title) { try { return (bool) static::loadByTitle($title); } catch (InvalidArgumentException $e) { return FALSE; } catch (NonUniqueResultException $e) { watchdog_exception('b2b_import', $e); return TRUE; } }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { /** @var \Drupal\search_api\IndexInterface $entity */ $entity = $this->getEntity(); try { $entity->clear(); } catch (SearchApiException $e) { drupal_set_message($this->t('Failed to clear the search index %name.', array('%name' => $entity->label())), 'error'); watchdog_exception('search_api', $e, '%type while trying to clear the index %name: @message in %function (line %line of %file)', array('%name' => $entity->label())); } $form_state->setRedirect('entity.search_api_index.canonical', array('search_api_index' => $entity->id())); }
public function delete($ids, \DatabaseTransaction $transaction = NULL) { $transaction = isset($transaction) ? $transaction : db_transaction(); try { parent::delete($ids, $transaction); db_delete('observers')->condition('observable_id', $ids, 'IN')->execute(); } catch (\Exception $e) { watchdog_exception($this->entityType, $e); $transaction->rollback(); throw $e; } }
/** * {@inheritdoc} */ public function getEmbedObject($url) { $embed = NULL; try { $response = $this->httpClient->get($this->getEmbedProviderURL($url), ['headers' => ['content-type' => 'application/json']]); $embed = json_decode($response->getBody()); } catch (TransferException $e) { drupal_set_message(t('Unable to retrieve @url at this time, please check again later.', ['@url' => $url]), 'warning'); watchdog_exception('ckeditor_media_embed', $e); } return $embed; }
protected function execute(InputInterface $input, OutputInterface $output) { /* drupal_set_installed_schema_version('sample', '8000'); exit();*/ include_once DRUPAL_ROOT . '/core/includes/install.inc'; include_once DRUPAL_ROOT . '/core/includes/update.inc'; $module = $input->getArgument('module'); $update_n = $input->getArgument('update-n'); $module_handler = $this->getModuleHandler(); drupal_load_updates(); update_fix_compatibility(); $updates = update_get_update_list(); if ($module != 'all') { if (!isset($updates[$module])) { $output->writeln('[-] <error>' . sprintf($this->trans('commands.update.execute.messages.no-module-updates'), $module) . '</error>'); return; } else { // filter to execute only a specific module updates $updates = [$module => $updates[$module]]; if ($update_n && !isset($updates[$module]['pending'][$update_n])) { $output->writeln('[-] <info>' . sprintf($this->trans('commands.update.execute.messages.module-update-function-not-found'), $module, $update_n) . '</info>'); } } } $output->writeln('[-] <info>' . $this->trans('commands.site.maintenance.description') . '</info>'); \Drupal::state()->set('system.maintenance_mode', true); foreach ($updates as $module_name => $module_updates) { foreach ($module_updates['pending'] as $update_number => $update) { if ($module != 'all' && $update_n != null and $update_n != $update_number) { continue; } //Executing all pending updates if ($update_n > $module_updates['start']) { $output->writeln('[-] <info>' . $this->trans('commands.update.execute.messages.executing-required-previous-updates') . '</info>'); } for ($update_index = $module_updates['start']; $update_index <= $update_number; $update_index++) { $output->writeln('[-] <info>' . sprintf($this->trans('commands.update.execute.messages.executing-update'), $update_index, $module_name) . '</info>'); try { $module_handler->invoke($module_name, 'update_' . $update_index); } catch (\Exception $e) { watchdog_exception('update', $e); $output->writeln('<error>' . $e->getMessage() . '</error>'); } //Update module schema version drupal_set_installed_schema_version($module_name, $update_index); } } } \Drupal::state()->set('system.maintenance_mode', false); $output->writeln('[-] <info>' . $this->trans('commands.site.maintenance.messages.maintenance-off') . '</info>'); $this->getHelper('chain')->addCommand('cache:rebuild', ['cache' => 'all']); }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $this->getDrupalHelper()->loadLegacyFile('/core/includes/install.inc'); $this->getDrupalHelper()->loadLegacyFile('/core/includes/update.inc'); $module = $input->getArgument('module'); $update_n = $input->getArgument('update-n'); $module_handler = $this->getModuleHandler(); drupal_load_updates(); update_fix_compatibility(); $updates = update_get_update_list(); if ($module != 'all') { if (!isset($updates[$module])) { $io->error(sprintf($this->trans('commands.update.execute.messages.no-module-updates'), $module)); return; } else { // filter to execute only a specific module updates $updates = [$module => $updates[$module]]; if ($update_n && !isset($updates[$module]['pending'][$update_n])) { $io->info(sprintf($this->trans('commands.update.execute.messages.module-update-function-not-found'), $module, $update_n)); } } } $io->info($this->trans('commands.site.maintenance.description')); $state = $this->getService('state'); $state->set('system.maintenance_mode', true); foreach ($updates as $module_name => $module_updates) { foreach ($module_updates['pending'] as $update_number => $update) { if ($module != 'all' && $update_n !== null && $update_n != $update_number) { continue; } //Executing all pending updates if ($update_n > $module_updates['start']) { $io->info($this->trans('commands.update.execute.messages.executing-required-previous-updates')); } for ($update_index = $module_updates['start']; $update_index <= $update_number; $update_index++) { $io->info(sprintf($this->trans('commands.update.execute.messages.executing-update'), $update_index, $module_name)); try { $module_handler->invoke($module_name, 'update_' . $update_index); } catch (\Exception $e) { watchdog_exception('update', $e); $io->error($e->getMessage()); } //Update module schema version drupal_set_installed_schema_version($module_name, $update_index); } } } $state->set('system.maintenance_mode', false); $io->info($this->trans('commands.site.maintenance.messages.maintenance-off')); $this->getChain()->addCommand('cache:rebuild', ['cache' => 'all']); }
public function autocomplete(Request $request) { $text = $request->query->get('q'); $client = new Client(['base_uri' => 'http://autocomplete.wunderground.com']); try { $response = $client->get('aq?query=' . $text)->getBody(); $data = json_decode($response->getContents()); // Extract key and value from the returned array. $results = []; foreach ($data->RESULTS as $result) { $results[] = ['value' => $result->name . ' [' . $result->l . ']', 'label' => $result->name]; } return new JsonResponse($results); } catch (RequestException $e) { watchdog_exception('wunderground_weather', $e); } }
public function alterItems(array &$items) { // Prevent session information from being saved while indexing. drupal_save_session(FALSE); // Force the current user to anonymous to prevent access bypass in search // indexes. $original_user = $GLOBALS['user']; $GLOBALS['user'] = drupal_anonymous_user(); $entity_type = $this->index->getEntityType(); $entity_handler = panelizer_entity_plugin_get_handler($entity_type); foreach ($items as &$item) { $entity_id = entity_id($entity_type, $item); $item->search_api_panelizer_content = NULL; $item->search_api_panelizer_title = NULL; // If Search API specifies a language to view the item in, force the // global language_content to be Search API item language. Fieldable // panel panes will render in the correct language. if (isset($item->search_api_language)) { global $language_content; $original_language_content = $language_content; $languages = language_list(); if (isset($languages[$item->search_api_language])) { $language_content = $languages[$item->search_api_language]; } else { $language_content = language_default(); } } try { if ($render_info = $entity_handler->render_entity($item, 'page_manager')) { $item->search_api_panelizer_content = $render_info['content']; $item->search_api_panelizer_title = !empty($render_info['title']) ? $render_info['title'] : NULL; } } catch (Exception $e) { watchdog_exception('panelizer', $e, 'Error indexing Panelizer content for %entity_type with ID %entity_id', array('%entity_type' => $entity_type, '%entity_id' => $entity_id)); } // Restore the language_content global if it was overridden. if (isset($original_language_content)) { $language_content = $original_language_content; } } // Restore the user. $GLOBALS['user'] = $original_user; drupal_save_session(TRUE); }
/** * Import the culturefeed domains. */ public function import() { $this->client = new Client($this::END_POINT); try { // Domains. $body = $this->client->get('domain')->send()->getBody(TRUE); $domains = $this->importDomains(new SimpleXMLElement($body)); // Clear them first. db_query('TRUNCATE {culturefeed_search_terms}'); // Import terms for every domain. foreach ($domains as $did) { $body = $this->client->get('domain/' . $did . '/classification')->send()->getBody(TRUE); $xmlElement = new SimpleXMLElement($body); $this->importTerms($xmlElement->categorisation->term); } } catch (ClientErrorResponseException $e) { watchdog_exception('culturefeed_domain_import', $e); } }
/** * Clone a module from drupal.org. * * @param string $project_name * The (machine) name of the module/project that needs to be downloaded. * @param string $branch * The branch that needs to be cloned. By default we will use the 8.x-1.x * branch. */ public static function retrieveModule($project_name, $branch = "8.x-1.x") { $branch = "origin/" . $branch; $path = self::getProjectDir($project_name); $url = self::DRUPAL_GIT_BASE_URL . '/' . $project_name; // Check if the repository is still available in the tmp folder. if (file_exists($path)) { $repository = new Repository($path); } else { $repository = Admin::cloneTo($path, $url, false); } try { $repository->getWorkingCopy()->checkout($branch); drupal_set_message(t('Successfully cloned branch @branch of @module.', array('@branch' => $branch, '@module' => $project_name))); } catch (\Exception $e) { drupal_set_message(t('Something went wrong while cloning the repository. Please check the logs for more information.'), 'error'); watchdog_exception('checkstyle', $e); } }
/** * Perform menu-specific rebuilding. */ protected function menuLinksRebuild() { if ($this->lock->acquire(__FUNCTION__)) { $transaction = db_transaction(); try { // Ensure the menu links are up to date. $this->menuLinkManager->rebuild(); // Ignore any database replicas temporarily. db_ignore_replica(); } catch (\Exception $e) { $transaction->rollback(); watchdog_exception('menu', $e); } $this->lock->release(__FUNCTION__); } else { // Wait for another request that is already doing this work. // We choose to block here since otherwise the router item may not // be available during routing resulting in a 404. $this->lock->wait(__FUNCTION__); } }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { /** @var QueueInterface $queue */ $queue = $this->queueFactory->get('manual_node_publisher'); /** @var QueueWorkerInterface $queue_worker */ $queue_worker = $this->queueManager->createInstance('manual_node_publisher'); while ($item = $queue->claimItem()) { try { $queue_worker->processItem($item->data); $queue->deleteItem($item); } catch (SuspendQueueException $e) { // If the worker indicates there is a problem with the whole queue, // release the item and skip to the next queue. $queue->releaseItem($item); break; } catch (\Exception $e) { // In case of any other kind of exception, log it and leave the item // in the queue to be processed again later. watchdog_exception('npq', $e); } } }
/** * {@inheritdoc} */ public function parse(FeedInterface $feed) { // Set our bridge extension manager to Zend Feed. Reader::setExtensionManager(\Drupal::service('feed.bridge.reader')); try { $channel = Reader::importString($feed->source_string); } catch (ExceptionInterface $e) { watchdog_exception('aggregator', $e); drupal_set_message(t('The feed from %site seems to be broken because of error "%error".', array('%site' => $feed->label(), '%error' => $e->getMessage())), 'error'); return FALSE; } $feed->setWebsiteUrl($channel->getLink()); $feed->setDescription($channel->getDescription()); if ($image = $channel->getImage()) { $feed->setImage($image['uri']); } // Initialize items array. $feed->items = array(); foreach ($channel as $item) { // Reset the parsed item. $parsed_item = array(); // Move the values to an array as expected by processors. $parsed_item['title'] = $item->getTitle(); $parsed_item['guid'] = $item->getId(); $parsed_item['link'] = $item->getLink(); $parsed_item['description'] = $item->getDescription(); $parsed_item['author'] = ''; if ($author = $item->getAuthor()) { $parsed_item['author'] = $author['name']; } $parsed_item['timestamp'] = ''; if ($date = $item->getDateModified()) { $parsed_item['timestamp'] = $date->getTimestamp(); } // Store on $feed object. This is where processors will look for parsed items. $feed->items[] = $parsed_item; } return TRUE; }
/** * Perform menu-specific rebuilding. */ protected function menuLinksRebuild() { if ($this->lock->acquire(__FUNCTION__)) { $transaction = db_transaction(); try { // Ensure the menu links are up to date. menu_link_rebuild_defaults(); // Clear the menu cache. menu_cache_clear_all(); // Track which menu items are expanded. _menu_update_expanded_menus(); } catch (\Exception $e) { $transaction->rollback(); watchdog_exception('menu', $e); } $this->lock->release(__FUNCTION__); } else { // Wait for another request that is already doing this work. // We choose to block here since otherwise the router item may not // be available during routing resulting in a 404. $this->lock->wait(__FUNCTION__); } }
protected function execute(InputInterface $input, OutputInterface $output) { $module = $input->getArgument('module'); $module_handler = $this->getModuleHandler(); if ($module != 'all') { $modules = [$module]; } else { $modules = $module_handler->getImplementations('cron'); } foreach ($modules as $module) { if ($module_handler->implementsHook($module, 'cron')) { $output->writeln('[-] <info>' . sprintf($this->trans('commands.cron.execute.messages.executing-cron'), $module) . '</info>'); try { $module_handler->invoke($module, 'cron'); } catch (\Exception $e) { watchdog_exception('cron', $e); $output->writeln('<error>' . $e->getMessage() . '</error>'); } } else { $output->writeln('<error>' . sprintf($this->trans('commands.cron.execute.messages.module-invalid'), $module) . '</error>'); } } $this->getHelper('chain')->addCommand('cache:rebuild', ['cache' => 'all']); }
/** * {@inheritdoc} */ public function parse(FeedInterface $feed, FetcherResultInterface $fetcher_result) { $result = new ParserResult(); Reader::setExtensionManager(\Drupal::service('feed.bridge.reader')); try { $channel = Reader::importString($fetcher_result->getRaw()); } catch (ExceptionInterface $e) { watchdog_exception('feeds', $e); drupal_set_message($this->t('The feed from %site seems to be broken because of error "%error".', array('%site' => $feed->label(), '%error' => $e->getMessage())), 'error'); return $result; } $result->title = $channel->getTitle(); $result->description = $channel->getDescription(); $result->link = $channel->getLink(); foreach ($channel as $item) { // Reset the parsed item. $parsed_item = array(); // Move the values to an array as expected by processors. $parsed_item['title'] = $item->getTitle(); $parsed_item['guid'] = $item->getId(); $parsed_item['url'] = $item->getLink(); $parsed_item['description'] = $item->getDescription(); if ($enclosure = $item->getEnclosure()) { $parsed_item['enclosures'][] = urldecode($enclosure->url); } if ($author = $item->getAuthor()) { $parsed_item['author_name'] = $author['name']; } if ($date = $item->getDateModified()) { $parsed_item['timestamp'] = $date->getTimestamp(); } $parsed_item['tags'] = $item->getCategories()->getValues(); $result->items[] = $parsed_item; } return $result; }