Skip to content

Commit

Permalink
Fix for deprecated method watchdog_exception()
Browse files Browse the repository at this point in the history
  • Loading branch information
divya-intelli committed Oct 10, 2023
1 parent 5be41b8 commit 44f4ebc
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 45 deletions.
11 changes: 5 additions & 6 deletions apigee_edge.module
Original file line number Diff line number Diff line change
Expand Up @@ -869,9 +869,9 @@ function apigee_edge_form_user_form_api_connection_validate(array $form, FormSta
'@user_email' => $form_state->getValue('mail'),
'@message' => (string) $exception,
];
// @todo watchdog_exception() function has been deprecated for Drupal 10.1 https://www.drupal.org/node/2932520
// @phpstan-ignore-next-line
watchdog_exception('apigee_edge', $exception, 'Could not create/update Drupal user: @user_email, because there was no connection to Apigee Edge. @message %function (line %line of %file). <pre>@backtrace_string</pre>', $context);

$logger = \Drupal::logger('apigee_edge');
Error::logException($logger, $exception, 'Could not create/update Drupal user: @user_email, because there was no connection to Apigee Edge. @message %function (line %line of %file). <pre>@backtrace_string</pre>', $context);
$form_state->setError($form, t('User registration is temporarily unavailable. Try again later or contact the site administrator.'));
}
}
Expand Down Expand Up @@ -950,9 +950,8 @@ function apigee_edge_form_user_register_form_developer_email_validate(array $for
$sendNotifications->set($account->getEmail(), $result);
}
catch (TempStoreException $e) {
// @todo watchdog_exception() function has been deprecated for Drupal 10.1 https://www.drupal.org/node/2932520
// @phpstan-ignore-next-line
watchdog_exception(__FUNCTION__, $e);
$logger = \Drupal::logger(__FUNCTION__);
Error::logException($logger, $e);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/Form/AppAnalyticsFormBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\Core\Url;
use Drupal\Core\Utility\Error;
use League\Period\Period;
use Moment\MomentException;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -379,9 +380,9 @@ protected function generateResponse(array &$form, AppInterface $app, string $met
catch (\Exception $e) {
$this->messenger()
->addError($this->t('Unable to retrieve analytics data. Please try again.'));
// @todo watchdog_exception() function has been deprecated for Drupal 10.1 https://www.drupal.org/node/2932520
// @phpstan-ignore-next-line
watchdog_exception('apigee_edge', $e);

$logger = \Drupal::logger('apigee_edge');
Error::logException($logger, $e);
}

$date_time_zone = new \DateTimeZone(date_default_timezone_get());
Expand Down
6 changes: 3 additions & 3 deletions src/JobExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Drupal\apigee_edge\Job\Job;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Utility\Error;
use Drupal\Core\Queue\QueueFactory;

/**
Expand Down Expand Up @@ -151,9 +152,8 @@ public function call(Job $job, bool $update = TRUE) {
$job->setStatus($result ? Job::IDLE : Job::FINISHED);
}
catch (\Exception $ex) {
// @todo watchdog_exception() function has been deprecated for Drupal 10.1 https://www.drupal.org/node/2932520
// @phpstan-ignore-next-line
watchdog_exception('apigee_edge_job', $ex);
$logger = \Drupal::logger('apigee_edge_job');
Error::logException($logger, $ex);
$job->recordException($ex);
$job->setStatus($job->shouldRetry($ex) && $job->consumeRetry() ? Job::RESCHEDULED : Job::FAILED);
}
Expand Down
6 changes: 3 additions & 3 deletions src/KeyEntityFormEnhancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use Drupal\Core\Messenger\MessengerTrait;
use Drupal\Core\Render\Element\StatusMessages;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Utility\Error;
use Drupal\key\Form\KeyFormBase;
use Drupal\key\KeyInterface;
use Drupal\key\Plugin\KeyProviderSettableValueInterface;
Expand Down Expand Up @@ -349,9 +350,8 @@ public function validateForm(array &$form, FormStateInterface $form_state): void
drupal_flush_all_caches();
}
catch (\Exception $exception) {
// @todo watchdog_exception() function has been deprecated for Drupal 10.1 https://www.drupal.org/node/2932520
// @phpstan-ignore-next-line
watchdog_exception('apigee_edge', $exception);
$logger = \Drupal::logger('apigee_edge');
Error::logException($logger, $exception);

$form_state->setError($form, $this->t('@suggestion Error message: %response', [
'@suggestion' => $this->createSuggestion($exception, $test_key),
Expand Down
6 changes: 3 additions & 3 deletions src/Plugin/Field/FieldType/ApigeeEdgeDeveloperIdFieldItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Drupal\apigee_edge\Entity\Developer;
use Drupal\Core\Field\FieldItemList;
use Drupal\Core\TypedData\ComputedItemListTrait;
use Drupal\Core\Utility\Error;

/**
* Definition of Apigee Edge Developer ID computed field for User entity.
Expand Down Expand Up @@ -52,9 +53,8 @@ protected function computeValue() {
$this->list[0] = $this->createItem(0, $value);
}
catch (\Exception $exception) {
// @todo watchdog_exception() function has been deprecated for Drupal 10.1 https://www.drupal.org/node/2932520
// @phpstan-ignore-next-line
watchdog_exception('apigee_edge', $exception);
$logger = \Drupal::logger('apigee_edge');
Error::logException($logger, $exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Apigee\Edge\Exception\ApiException;
use Drupal\Component\Utility\Random;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Utility\Error;

/**
* Implements hook_entity_insert().
Expand Down Expand Up @@ -36,15 +37,13 @@ function apigee_edge_test_app_keys_developer_app_insert(EntityInterface $entity)
$dacc->create("{$prefix}-{$random->name()}", "{$prefix}-{$random->name()}");
}
catch (ApiException $e) {
// @todo watchdog_exception() function has been deprecated for Drupal 10.1 https://www.drupal.org/node/2932520
// @phpstan-ignore-next-line
watchdog_exception('apigee_edge', $e, 'Unable to create new API key on Apigee Edge for @app app. !message', ['@app' => $entity->id()]);
$logger = \Drupal::logger('apigee_edge');
Error::logException($logger, $e, 'Unable to create new API key on Apigee Edge for @app app. !message', ['@app' => $entity->id()]);
}
}
catch (ApiException $e) {
// @todo watchdog_exception() function has been deprecated for Drupal 10.1 https://www.drupal.org/node/2932520
// @phpstan-ignore-next-line
watchdog_exception('apigee_edge', $e, 'Unable to delete auto-generated key of @app app on Apigee Edge. !message', ['@app' => $entity->id()]);
$logger = \Drupal::logger('apigee_edge');
Error::logException($logger, $e, 'Unable to delete auto-generated key of @app app on Apigee Edge. !message', ['@app' => $entity->id()]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Drupal\apigee_edge\Entity\Controller\DeveloperAppCredentialControllerFactoryInterface;
use Drupal\apigee_edge\Event\AppCredentialGenerateEvent;
use Drupal\Component\Utility\Random;
use Drupal\Core\Utility\Error;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
Expand Down Expand Up @@ -89,29 +90,25 @@ public function overrideAppKeyOnGenerate(AppCredentialGenerateEvent $event) {
$credential_controller->addProducts($new_consumer_key, $products);
}
catch (ApiException $e) {
// @todo watchdog_exception() function has been deprecated for Drupal 10.1 https://www.drupal.org/node/2932520
// @phpstan-ignore-next-line
watchdog_exception('apigee_edge', $e, 'Unable to assign API products to the newly generated API key on Apigee Edge for @app app. !message', ['@app' => "{$event->getOwnerId()}:{$event->getAppName()}"]);
$logger = \Drupal::logger('apigee_edge');
Error::logException($logger, $e, 'Unable to assign API products to the newly generated API key on Apigee Edge for @app app. !message', ['@app' => "{$event->getOwnerId()}:{$event->getAppName()}"]);
try {
$credential_controller->delete($new_consumer_key);
}
catch (ApiException $e) {
// @todo watchdog_exception() function has been deprecated for Drupal 10.1 https://www.drupal.org/node/2932520
// @phpstan-ignore-next-line
watchdog_exception('apigee_edge', $e, 'Unable to delete newly generated API key after API product re-association has failed on Apigee Edge for @app app. !message', ['@app' => "{$event->getOwnerId()}:{$event->getAppName()}"]);
$logger = \Drupal::logger('apigee_edge');
Error::logException($logger, $e, 'Unable to delete newly generated API key after API product re-association has failed on Apigee Edge for @app app. !message', ['@app' => "{$event->getOwnerId()}:{$event->getAppName()}"]);
}
}
}
catch (ApiException $e) {
// @todo watchdog_exception() function has been deprecated for Drupal 10.1 https://www.drupal.org/node/2932520
// @phpstan-ignore-next-line
watchdog_exception('apigee_edge', $e, 'Unable to create new API key on Apigee Edge for @app app. !message', ['@app' => "{$event->getOwnerId()}:{$event->getAppName()}"]);
$logger = \Drupal::logger('apigee_edge');
Error::logException($logger, $e, 'Unable to create new API key on Apigee Edge for @app app. !message', ['@app' => "{$event->getOwnerId()}:{$event->getAppName()}"]);
}
}
catch (ApiException $e) {
// @todo watchdog_exception() function has been deprecated for Drupal 10.1 https://www.drupal.org/node/2932520
// @phpstan-ignore-next-line
watchdog_exception('apigee_edge', $e, 'Unable to delete auto-generated key of @app app on Apigee Edge. !message', ['@app' => "{$event->getOwnerId()}:{$event->getAppName()}"]);
$logger = \Drupal::logger('apigee_edge');
Error::logException($logger, $e, 'Unable to delete auto-generated key of @app app on Apigee Edge. !message', ['@app' => "{$event->getOwnerId()}:{$event->getAppName()}"]);
}
}

Expand Down
8 changes: 5 additions & 3 deletions tests/src/Kernel/ApigeeEdgeKernelTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

namespace Drupal\Tests\apigee_edge\Kernel;

use Drupal\Core\Utility\Error;

/**
* Provides common functionality for the Apigee Edge kernel test classes.
*/
Expand All @@ -35,9 +37,9 @@ trait ApigeeEdgeKernelTestTrait {
*/
protected function logException(\Exception $exception, string $suffix = '') {
$ro = new \ReflectionObject($this);
// @todo watchdog_exception() function has been deprecated for Drupal 10.1 https://www.drupal.org/node/2932520
// @phpstan-ignore-next-line
watchdog_exception("{$ro->getShortName()}{$suffix}", $exception);

$logger = \Drupal::logger("{$ro->getShortName()}{$suffix}");
Error::logException($logger, $exception);
}

}
6 changes: 3 additions & 3 deletions tests/src/Kernel/Util/ApigeeEdgeManagementCliServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Apigee\Edge\Exception\ClientErrorException;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceModifierInterface;
use Drupal\Core\Utility\Error;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\apigee_mock_api_client\Traits\ApigeeMockApiClientHelperTrait;

Expand Down Expand Up @@ -145,9 +146,8 @@ protected function tearDown(): void {
}
}
catch (\Exception $exception) {
// @todo watchdog_exception() function has been deprecated for Drupal 10.1 https://www.drupal.org/node/2932520
// @phpstan-ignore-next-line
watchdog_exception('apigee_edge', $exception);
$logger = \Drupal::logger('apigee_edge');
Error::logException($logger, $exception);
}

parent::tearDown();
Expand Down
6 changes: 3 additions & 3 deletions tests/src/Traits/ApigeeEdgeFunctionalTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Drupal\apigee_edge\Entity\ApiProduct;
use Drupal\apigee_edge\Entity\Developer;
use Drupal\apigee_edge\Entity\DeveloperApp;
use Drupal\Core\Utility\Error;
use Drupal\Tests\apigee_mock_api_client\Traits\ApigeeMockApiClientHelperTrait;
use Drupal\user\Entity\User;
use Drupal\user\UserInterface;
Expand Down Expand Up @@ -299,9 +300,8 @@ protected static function fixUrl(string $url): string {
*/
protected function logException(\Exception $exception, string $suffix = '') {
$ro = new \ReflectionObject($this);
// @todo watchdog_exception() function has been deprecated for Drupal 10.1 https://www.drupal.org/node/2932520
// @phpstan-ignore-next-line
watchdog_exception("{$ro->getShortName()}{$suffix}", $exception);
$logger = \Drupal::logger("{$ro->getShortName()}{$suffix}");
Error::logException($logger, $exception);
}

/**
Expand Down

0 comments on commit 44f4ebc

Please sign in to comment.