Skip to content

Instantly share code, notes, and snippets.

View mandrius's full-sized avatar

Andrius mandrius

View GitHub Profile
@mandrius
mandrius / kill_page_cache
Created July 27, 2018 03:33
Kill page cache
\Drupal::service('page_cache_kill_switch')->trigger();
# Exec as root
docker-compose exec --user root -T php sh -c "chown -R www-data:www-data ."
# Exec as regular
docker-compose exec -T php sh -c "composer --version"
sudo certbot certonly --manual --preferred-challenges=http
# Start an app (in background) based on docker-compose.yml:
docker-compose up -d
# List of running containers (including names):
docker-compose ps
# Check logs:
docker-compose logs [CONTAINER_NAME]
# Stop an app:
rsync -a ~/dir1 username@remote_host:destination_directory
rsync -a username@remote_host:/home/username/dir1 place_to_sync_on_local_machine
scp -r eurocockpit.be:/home/euroco1q/eurocockpit.be/db/eurocockpit.be-master-2019-01-05-0731.sql.gz ~/www
// PHP $_POST
$name = $_POST['name']; // form param
// Drupal 8 $_POST
$name = \Drupal::request()->request->get('name'); // form param
// Drupal 8 $_GET
$query = \Drupal::request()->query->get('name');
// Get HOST
Cache keys
Cache keys are unique identifiers for a specific variation of a thing that is being cached. This provides the cache API with the information it needs to be able to retrieve the specific item from whatever storage is being used for cached data.
When rendering a node (data being displayed) in the teaser view mode (configuration indicating a specific representation), the cache keys would be e.g. ['node', 5, 'teaser']
Cache tags
Cache tags vary the cache based on the data that was used to build the element. For example, entities, users, or configuration.
Using cache tags you could associate some cached data with a specific node. When that node is edited, and the content of it changes, the related cached data becomes outdated and no longer valid.
@mandrius
mandrius / .gitlab-ci.yml
Last active March 19, 2018 08:49
GitLab CI/CD auto deploy (Drupal 8).
stages:
- deploy
dev-deployment:
stage: deploy
script:
- ssh HOST 'bash -s' < dev-deployment.sh
only:
- develop
@mandrius
mandrius / CustomDataResource.php
Last active March 19, 2018 08:37
Custom data response plugin.
<?php
namespace Drupal\[custom_module]\Plugin\rest\resource;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
use Drupal\user\UserStorageInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;