Skip to content

Instantly share code, notes, and snippets.

View mmenavas's full-sized avatar

Maximo Mena mmenavas

  • Lullabot
  • San Tan Valley, Arizona, USA
View GitHub Profile
<?php
$users = array(
'username1',
'username2',
);
foreach ($users as $username) {
$user = user_load_by_name($username);
$role = user_role_load_by_name("event coordinator");
@mmenavas
mmenavas / drupal7-add-email-address-to-users.php
Created July 17, 2017 20:46
Use this script to fill in the 'mail' field in the users table.
<?php
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'user', '=');
$query->propertyCondition('mail', NULL);
$query->propertyCondition('uid', 0, '>');
$query_result = $query->execute();
if (isset($query_result['user'])) {
<?php
$num_updated = db_update('users')
->fields(array(
'timezone' => 'America/Phoenix',
))
->execute();
drupal_set_message(t('@var users where updated.', array('@var' => $num_updated)), 'status');
@mmenavas
mmenavas / settings.local.php
Last active May 23, 2017 20:35
Get hash salt from Drupal 8 site in Pantheon using terminus
<?php
$databases['default']['default'] = array (
'database' => '',
'username' => '',
'password' => '',
'host' => 'localhost',
'port' => '3306',
'driver' => 'mysql',
'prefix' => '',
PHP 7.1
valet stop && brew services stop php56 && brew unlink php56 && brew link php71 && brew services start php71 && valet start
valet stop && brew unlink php56 && brew link php71 && brew services start php71 && valet start
PHP 5.6
valet stop && brew services stop php71 && brew unlink php71 && brew link php56 && brew services start php56 && valet start
valet stop && brew unlink php71 && brew link php56 && brew services start php56 && valet start
@mmenavas
mmenavas / rename.php
Created May 19, 2014 16:19
CLI PHP script to non-recursively rename files
<?php
/**
* Script to non-recursevly rename files in the directory where the script is.
* TODO:
* - Provide help flag (option -h or -help)
* - Check special characters
*/
// Search and replace parameters