Skip to content

Instantly share code, notes, and snippets.

View achraf-jeday's full-sized avatar
🏠
Working from home

Achraf Jeday achraf-jeday

🏠
Working from home
View GitHub Profile
@achraf-jeday
achraf-jeday / hook_update_N.txt
Last active November 21, 2019 10:54
Drupal 8: To run a mymodule_update_8004() multiple times in development enivrements use these queries:
SELECT * FROM key_value WHERE collection="system.schema";
UPDATE key_value SET value='s:4:"8003";' WHERE collection="system.schema" AND name="mymodule";
How to "revert" a custom module's update 'N value'
D7 only: If you need to execute an update hook another time when testing it locally you can "revert" a custom module's update 'N value' with:
UPDATE system SET schema_version = [last_successful_update_ID] WHERE name = '[name_of_module]';
Replace the square brackets plus its content. See https://drupal.stackexchange.com/a/69841/19480.
Examples:
@achraf-jeday
achraf-jeday / slave.sh
Last active October 4, 2019 16:01
Jenkins deployment script (Drupal 8 and Vue.js)
#!/bin/bash
cd /home/ubuntu/docker
sudo rm -rf dhm-it-docker-backup/
cp -r dhm-it-docker dhm-it-docker-backup
datetime=$(date +"%Y_%m_%d_%I_%M_%p")
docker exec dhmit_mariadb /usr/bin/mysqldump -u dhmit --password=dhmit123 drupal > /home/ubuntu/docker/dhm-it-docker-backup/docker/etc/mysql/$datetime.sql
cd dhm-it-docker
docker-compose stop
docker-compose rm -f
docker volume rm $(docker volume ls -q)
@achraf-jeday
achraf-jeday / Login.vue
Created September 23, 2019 14:25
Vuejs Drupal 8 Login
<template>
<div class="login">
<div class="container">
<form id="loginForm" v-on:submit.prevent="login">
<div class="col-12 content-block">
<div class="content-block-text">
<h2>Aanmelden</h2>
</div>
<div class="content-block-text">
<hr>
@achraf-jeday
achraf-jeday / Login.html
Last active September 9, 2019 14:34
Javascript Linkedin Social Login Button for OAuth.io https://oauth.io/, https://www.linkedin.com/developers/
<html>
<header>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"></script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdn.rawgit.com/oauth-io/oauth-js/c5af4519/dist/oauth.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-social/4.12.0/bootstrap-social.min.css">
</header>
<body>
@achraf-jeday
achraf-jeday / mysql-docker.sh
Last active September 4, 2019 07:59 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
# Added current date and time to generated file name.
docker exec preprod_safefood_vitrine_mariadb /usr/bin/mysqldump -u safefood_vitrine --password=safefood_vitrine123 drupal > $(date +"%Y_%m_%d_%I_%M_%p").sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@achraf-jeday
achraf-jeday / chmod Symbols
Last active August 29, 2019 09:06
chmod Symbols
7 rwx
6 rw-
5 r-x
4 r--
3 -wx
2 -w-
1 --x
0 ---
@achraf-jeday
achraf-jeday / ExampleModuleController.php
Created July 2, 2019 09:50 — forked from crittermike/ExampleModuleController.php
Example of overriding a route controller in Drupal 8
<?php
/**
* @file
* Contains \Drupal\example_module\Controller\ExampleModuleController.
*/
// THIS FILE BELONGS AT /example_module/src/Controller/ExampleModuleController.php
namespace Drupal\example_module\Controller;
@achraf-jeday
achraf-jeday / UserTokenService.php
Created June 28, 2019 10:09
Dependency injection of a service that is already in the container (Symfony 4)
<?php
namespace CoreBundle\Service;
use CoreBundle\Entity\User;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\Cache\Adapter\AdapterInterface;
class UserTokenService
@achraf-jeday
achraf-jeday / FrontController.php
Last active June 25, 2019 15:54
Drupal 8 and GuzzleHttp 6: Basic HTTP authentication.
$credentials = base64_encode("admin:SuperSecret123");
$apiResponse = $this->client->get("{$this->container->getParameter('api')}jwt/token",
[
'verify' => false,
'headers' => [
'Authorization' => 'Basic ' . $credentials,
],
]);
@achraf-jeday
achraf-jeday / Curl.sh
Last active June 18, 2019 15:23
curl --insecure: For development purposes only you can pass the --insecure argument to curl, to skip cert check (self signed certificate).
curl --insecure -X POST -H "Content-Type: application/json" https://front.site-dev.fr:8002/api/login_check -d '{"username":"johndoe","password":"test"}'