[1.0.x] Bing Indexing API

Created on 11 December 2024, 11 days ago

Module page: https://www.drupal.org/project/bing_indexing_api →

What does the module do?

The module provides Bing Submission Tool API solution that allows websites to notify Bing whenever website contents is updated or created allowing instant crawling, indexing and discovery of your site content.

From Bing documentation:

Bing recommends using the URL submission tool to get web content indexed (as soon as it is published) or updated online. As a webmaster, you can submit URLs to Bing programmatically through the Submit URLs API or the URL submission feature in Bing Webmasters Tools. It allows you to submit up to 10,000 URLs per day for most sites, for (potential) immediate crawls and indexation – depending on a variety of signals available to Bing. We reset the quota every day at midnight GMT. It is also recommended to refresh Sitemaps at least once a day to help Bing discover all relevant (fresh and non-fresh) URLs of your website.

Microsoft Bing | Webmaster Tool:

Bing Indexing API module UI:




Testing:

Usage:

1. Reindexing single or multiple Urls with service:

\Drupal::service('bing_indexing_api.client')->reindexUrl('https://example.com/foo/boo');
\Drupal::service('bing_indexing_api.client')->reindexUrl([
'https://example.com/foo/boo', 
'https://example.com/foo/moo'
]);

2. Defining when to trigger URL submission at Settings form (/admin/config/services/bing-index-api/settings)
3. Using Bulk form for multiple URLs submission.

📌 Task
Status

Needs review

Component

module

Created by

🇺🇦Ukraine Anna D

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Anna D
  • 🇺🇦Ukraine Anna D
  • 🇮🇳India vishal.kadam Mumbai

    Thank you for applying!

    Please read Review process for security advisory coverage: What to expect → for more details and Security advisory coverage application checklist → to understand what reviewers look for. Tips for ensuring a smooth review → gives some hints for a smoother review.

    The important notes are the following.

    • If you have not done it yet, you should run phpcs --standard=Drupal,DrupalPractice on the project, which alone fixes most of what reviewers would report.
    • For the time this application is open, only your commits are allowed.
    • The purpose of this application is giving you a new drupal.org role that allows you to opt projects into security advisory coverage, either projects you already created, or projects you will create. The project status won't be changed by this application and no other user will be able to opt projects into security advisory policy.
    • We only accept an application per user. If you change your mind about the project to use for this application, or it is necessary to use a different project for the application, please update the issue summary with the link to the correct project and the issue title with the project name and the branch to review.

    To the reviewers

    Please read How to review security advisory coverage applications → , Application workflow → , What to cover in an application review → , and Tools to use for reviews → .

    The important notes are the following.

    • It is preferable to wait for a Code Review Administrator before commenting on newly created applications. Code Review Administrators will do some preliminary checks that are necessary before any change on the project files is suggested.
    • Reviewers should show the output of a CLI tool → only once per application.
    • It may be best to have the applicant fix things before further review.

    For new reviewers, I would also suggest to first read In which way the issue queue for coverage applications is different from other project queues → .

  • 🇮🇳India vishal.kadam Mumbai
  • 🇮🇳India vishal.kadam Mumbai

    1. FILE: src/Form/BingBulkUpdateForm.php

      /**
       * Constructor.
       */
      public function __construct(protected BingIndexingApiInterface $bingIndexingApi) {

    FILE: src/Service/BingIndexingApi.php

      /**
       * Constructs BingIndexingApi.
       *
       * @param \Drupal\Core\Config\ConfigFactoryInterface $config
       *   The State Service.
       * @param \Psr\Log\LoggerInterface $logger
       *   The Logging Service.
       * @param \GuzzleHttp\ClientInterface $client
       *   Http Client.
       */
      public function __construct(protected ConfigFactoryInterface $config, protected LoggerInterface $logger, protected ClientInterface $client) {

    The documentation comment for constructors is not mandatory anymore, If it is given, the description must be Constructs a new [class name] object. where [class name] includes the class namespace.

    2. FILE: bing_indexing_api.module

    /**
     * @file
     * Contains hook implementations for bing_indexing_api module.
     */

    The usual description for a .module file is Hook implementations for the [module name] module. where [module name] is the module name given in the .info.yml file.

  • 🇺🇦Ukraine Anna D

    Thank you, @vishal.kadam, for the review.

    The issues have been fixed in the 1.0.x branch.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • 🇮🇳India vishal.kadam Mumbai

    Rest looks fine to me.

    Let’s wait for a Code Review Administrator to take a look and if everything goes fine, you will get the role.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    • The following points are just a start and don't necessarily encompass all the changes that may be necessary
    • A specific point may just be an example and may apply in other places
    • A review is about code that does not follow the coding standards, contains possible security issues, or does not correctly use the Drupal API; the single points are not ordered, not even by importance

    src/Service/BingIndexingApi.php

        if (!$base_domain || !$api_key) {
          $this->logger->error($this->t('Check the Bing API settings: the domain or API key is missing.'));
          return NULL;
        }
    
        catch (\Exception | GuzzleException $exception) {
          $this->logger->error($exception->getMessage());
        }
    

    The first argument passed to error(), warning(), and similar logger methods must be a literal string.

    To log exceptions, there is watchdog_exception() or the class method described in that documentation page.

    Alternatively, a logger method can be used, but the exception message must be added as placeholder, not concatenating it with a literal string, nor passing it directly as first parameter of the logger methods.

    src/Form/BingBulkUpdateForm.php

        if (!empty($urls)) {
          $result = $this->bingIndexingApi->reindexUrl($urls);
          $this->messenger()->addMessage($result['message'], $result['success'] ? MessengerInterface::TYPE_STATUS : MessengerInterface::TYPE_ERROR);
        }
        else {
          $this->messenger()->addMessage($this->t('No valid URLs to reindex.'));
        }
    

    The first parameter of the messenger methods like addMessage() must be a translatable string.

    src/Form/BingCredentialsForm.php

        $form['api_key'] = [
          '#type' => 'textfield',
          '#title' => $this->t('API Key'),
          '#default_value' => $config->get('api_key'),
          '#description' => $this->t('Follow @instruction_link to configure Bing and get API key.', [
            '@instruction_link' => Link::fromTextAndUrl($this->t('instruction'), Url::fromUri('https://learn.microsoft.com/en-us/bingwebmaster/getting-access#using-api-key'))
              ->toString(),
          ]),
    

    Links are added in a translatable string using :variable placeholders.

  • 🇺🇦Ukraine Anna D

    Thank you @avpaderno,

    1. Fixed the use of translatable strings in logger methods.
    2. $result['message'] now returns a translatable string for both successful and failed cases.
    3. Used \Drupal\Core\Utility\Error::logException() to log exceptions.
    4. Removed placeholder for link in src/Form/BingCredentialsForm.php.
    I reviewed the example for using links on the page https://www.drupal.org/docs/7/api/localization-api/dynamic-or-static-lin... → .

    I was close to using the following approach:

    $this->t('Follow <a href="@instruction_link">the instruction</a> to configure Bing and get API key.', [
            '@instruction_link' => 'https://learn.microsoft.com/en-us/bingwebmaster/getting-access#using-api-key',
          ]),
    

    This would help avoid losing translation for the string in case the instruction link changes. However, I decided not to use a placeholder in case a different language for the link is needed (currently it is en-us).

    Merged changes to 1.0.x branch

Production build 0.71.5 2024