How to set Airbrake with drupal 8 - drupal

I'm trying to use Airbrake with my drupal 8 project, I follow this GitHub page https://github.com/akalsey/airbrake-drupal. I create an account and install the Airbrake using Composer composer require airbrake/phpbrake. Then it says that I should copy this snippet into your PHP app
$notifier = new Airbrake\Notifier(array(
'projectId' => ****,
'projectKey' => '****'
));
Airbrake\Instance::set($notifier);
$handler = new Airbrake\ErrorHandler($notifier);
$handler->register();
But I don't know in which file I past it?
Any help?

Related

How to replace silex in a project and adapt it to php8

I have this in my project php.
$app = new Silex\Application();
$app->register(new DerAlex\Silex\YamlConfigServiceProvider(realpath(__DIR__ . '/config/settings.yml')));
$app->register(new \Knp\Provider\MigrationServiceProvider(), array(
'migration.path' => __DIR__.'/../migration',
));
I need to update the code to use php8.
All package are abandoned / archived.
I could replace silex/silex by spryker/silexphp.
I dont know how to replace this package to get settings.yml configutarion.
DerAlex\Silex\YamlConfigServiceProvider
Someone knows how can i do this?

Drupal 8.6 Commerce: in .install file without module_uninstall() remove tables from database. Why?

When uninstall module then why delete all table from database without module_uninstall() function in .install file.
Also, why create table without module_install() function
.install file code is only:
function commerce_quickpay_schema() {
$schema['webc_crypto_meta'] = [
'description' => 'Custom Cryptography Meta',
'fields' => [...],
'primary key' => ['wcm_id'],
];
$schema['webc_crypto_payment'] = [
'description' => 'Custom Cryptography Payment',
'fields' => [...],
'primary key' => ['wcp_id'],
];
return $schema;
}
Also, please, CREATE TABLE IF NOT EXISTS condition in .install file.
This is how it behaves, the tables defined in hook_schema will be created or removed from the database when the module is installed or uninstalled, the hook_install() or hook_uninstall() hooks should be used when you want to do something extra.
It is simply assumed that the database schema should be removed when a module is uninstalled and come back when installed, if you think about it, it makes perfect sense.
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Database%21database.api.php/function/hook_schema/8.7.x
"The tables declared by this hook will be automatically created when
the module is installed, and removed when the module is uninstalled.
This happens before hook_install() is invoked, and after
hook_uninstall() is invoked, respectively."

How to run Drupal 8 functions from an external PHP file

Is there any way to execute Drupal 8 functions from an external PHP file.
You can include/call Drupal's bootstrap in your script and after that call Drupal's functions. Used that for D7, but didn't try for D8. However it should work:
https://drupal.stackexchange.com/questions/174474/bootstrap-from-external-script
And to copy code from that page:
define('DRUPAL_DIR', '/usr/share/nginx/html');
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
require_once DRUPAL_DIR . '/core/includes/database.inc';
require_once DRUPAL_DIR . '/core/includes/schema.inc';
// Specify relative path to the drupal root.
$autoloader = require_once DRUPAL_DIR . '/autoload.php';
$request = Request::createFromGlobals();
// Bootstrap drupal to different levels
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$kernel->boot();
$kernel->prepareLegacyRequest($request);
$em = $kernel->getContainer()->get('entity.manager');
$entity = $em->getStorage('node')->create(
array(
'type' => "article",
'title'=> "test entity",
'body' => "body body body",
));
$entity->save();
If you have Drush, you can run "drush scr [filename]" which will execute the file as well as bootstrap Drupal. I did a blog post about this - https://www.oliverdavi.es/blog/dont-bootstrap-drupal-use-drush.
I'd only use this for simple local test scripts though to test things out before moving the code into proper functions/classes/controllers/services etc.
You can run any php code either drupal or non-drupal using Devel and Kint module like this.[Use Devel and Kint module] like this
https://i.stack.imgur.com/RUKv6.png

Shopify: How to delete database entry fast after uninstall web-hook response, so the merchant uninstall and re-install quickly?

This is my code in callbackController.php file
$url = 'https://' . $_GET['shop'] . '/admin/webhooks.json';
$webhookData = [
'webhook' => [
'topic' => 'app/uninstalled',
'address' => config('app.url').'uninstall.php?shop='.$shop,
'format' => 'json'
]
];
$uninstall = $sh->appUninstallHook($accessToken, $url, $webhookData);
This is my uninstall.php file code , these file is in laravel root folder.
$connection = new mysqli("localhost", "username", "******", "database");
$delete_shop = "DELETE FROM tablename WHERE store_name= '".$_GET['shop']."'";
$connection->query($delete_shop);
I found solution here, but i can't understand how it works.
Thanks !!
If you get an uninstall Webhook, there is no rush to suddenly delete the store from your DB before the merchant re-installs.
First off, merchants don't uninstall re-install Apps unless they are really outliers. Most just uninstall and never come back.
Second, if a merchant did uninstall, and then re-install, and you recognized their shop, they would be coming to you with a new token. You can therefore tell that this is a new install, and you could therefore decide to keep the same data, and just update the token, or do whatever you want.
But there is no need to rush to delete. That is you being the frog in the game Frogger :)

Example algolia and Symfony

I use this documentation for install algolia:
https://www.algolia.com/doc/api-client/symfony/setup/
this configuration is already done:
composer require algolia/algolia-search-bundle
And
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Algolia\AlgoliaSearchBundle\AlgoliaAlgoliaSearchBundle(),
);
configuration.yml:
algolia:
application_id: YOUR_APP_ID
api_key: YOUR_API_KEY
but I don't understand , I need a example for implementation in my project.
Please your help
1-) you should install algolia-search-bundle with Composer;
composer require algolia/algolia-search-bundle
2-) add line this -> Algolia\AlgoliaSearchBundle\AlgoliaAlgoliaSearchBundle() at app/AppKernel.php file into $bundles array.
3-)you should add your api keys at app/config/config.yml file;
algolia:
application_id: YOUR_APP_ID
api_key: YOUR_API_KEY
That's enough.

Resources