Notes

Update drupal/core Composer
# Verify pending updates
composer outdated drupal/*

# Update drupal core and dependencies
composer update drupal/core --with-dependencies

# Drupal site using drupal-composer/drupal-project
composer update drupal/core webflo/drupal-core-require-dev --with-dependencies

# Once I was forced to remove composer.lock and vendor/ then redo composer update with dependencies
rm -Rf composer.lock vendor/

 

Update-Database NuGet Package Manager on Azure

Firstly setup properly Azure DB firewall, then execute the following command within you Visual Studio,

 Update-Database -Configuration {Project_Namespace}.Migrations.Configuration -Verbose -ConnectionString "Server=tcp:{Azure_SQL_Server}.database.windows.net,1433;Initial Catalog={Azure_DB_Name};Persist Security Info=True;User ID={Azure_DB_Username};Password={Azure_DB_Password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" -ConnectionProviderName "System.Data.SqlClient"

 

Ifconfig inet addresses | nmap scan

ifconfig

/sbin/ifconfig | grep 'inet addr:' 

nmap

nmap -sP 192.168.1.0/24
Kill all processes on particular port
kill -9 $(lsof -t -i:4200)

 

Install your public key in a remote machine's authorized_keys
ssh-copy-id -i root@ip_address

 

Tar Linux Usage

Create compress files

tar -czvf NEW_FILE_NAME.tar.gz /PATH/TO/DIRECTORY-OR-FILE-TO-COMPRESS

Extract files

tar -xzvf FILE_NAME.tar.gz -C /tmp

 

Drupal 8 format date
\Drupal::service('date.formatter')->format($timestamp, $type, $format, $timezone, $langcode);
/* $type:  - One of the built-in formats: 
 *  'short', 'medium', 'long', 'html_datetime', 'html_date', 
 *  'html_time', 'html_yearless_date', 'html_week', 'html_month', 'html_year'. 
 */

 

Drupal 8 - Valid Email address
\Drupal::service('email.validator')->isValid($mail);

 

Drupal 8 Html::load()
/** @var string $html */
$html = <<<HTML
         <a href="/" title="home">Home</a>
HTML;
/** @var DOMElement $element */
foreach (Drupal\Component\Utility\Html::load($html)->getElementsByTagName('a') as $element) {
    $href = $element->getAttribute('href');
    $title = $element->getAttribute('title');
    echo "{$title} is redirecting to {$href}" . PHP_EOL;
}

 

Drupal 8: Re-run update N hook
UPDATE key_value SET value='i:8000;' WHERE collection = 'system.schema' AND name = 'module_name';

Or

\Drupal::keyValue('system.schema')->set('module_name', (int) 8000);

Even

drush ev "\Drupal::keyValue('system.schema')->set('module_name', (int) 8000)";

drush eval "drupal_set_installed_schema_version("module_name", 8000)"