Skip to content

Instantly share code, notes, and snippets.

@opi
Forked from davereid/custom_local.drush.inc
Created January 26, 2013 08:26
Show Gist options
  • Save opi/4641035 to your computer and use it in GitHub Desktop.
Save opi/4641035 to your computer and use it in GitHub Desktop.
<?php
/**
* Implements hook_drush_command().
*/
function custom_local_drush_command() {
$items['files-fix-permissions'] = array(
'description' => 'Fix file permissions',
'aliases' => array('ffp'),
);
$items['schema-version-get'] = array(
'description' => 'Get schema version',
'aliases' => array('svg'),
);
$items['schema-version-set'] = array(
'description' => 'Set schema version',
'aliases' => array('svs'),
);
$items['whereis'] = array(
'description' => 'Find module or theme location',
);
return $items;
}
function drush_custom_local_files_fix_permissions() {
$paths = _core_path_aliases();
$files_dir = realpath($paths['%files']);
drush_op_system('sudo chown -R $USER "' . $files_dir . '"');
drush_op_system('sudo chgrp -R www-data "' . $files_dir . '"');
drush_op_system('sudo chmod -R 775 "' . $files_dir . '"');
$files = array('.ht.sqlite');
foreach ($files as $file) {
$file = $files_dir . '/' . $file;
if (file_exists($file)) {
drush_op_system('sudo chown $USER "' . $file . '"');
drush_op_system('sudo chgrp www-data "' . $file . '"');
drush_op_system('sudo chmod 775 "' . $file . '"');
}
}
}
function drush_custom_local_schema_version_get($module) {
// Ensure that install.inc will be included.
module_load_install($module);
$version = drupal_get_installed_schema_version($module);
if ($version > SCHEMA_UNINSTALLED) {
drush_print("Module $module is currently at schema version $version.");
}
else {
drush_print("Module $module not installed or available.");
}
}
function drush_custom_local_schema_version_set($module, $version) {
// Ensure that install.inc will be included.
module_load_install($module);
$version = (int) $version;
drupal_set_installed_schema_version($module, $version);
$new_version = drupal_get_installed_schema_version($module);
if ($new_version == $version) {
drush_print("Updated $module to schema version $version.");
}
else {
drush_print("Unable to set schema to $version, or module $module not installed or available.");
}
}
function drush_custom_local_whereis($target) {
$path = drush_core_find_project_path($target);
drush_print($target . ': ' . $path);
}
/**
* Add support for clearing the bootstrap cache.
*/
function custom_local_drush_cache_clear(&$types) {
if (drush_drupal_major_version() >= 7) {
$types['bootstrap'] = 'custom_local_drush_cache_clear_bootstrap';
$types['entity-info'] = 'custom_local_drush_cache_clear_entity_info';
$types['field-info'] = 'custom_local_drush_cache_clear_field_info';
}
}
function custom_local_drush_cache_clear_bootstrap() {
cache_clear_all('*', 'cache_bootstrap', TRUE);
}
function custom_local_drush_cache_clear_entity_info() {
entity_info_cache_clear();
}
function custom_local_drush_cache_clear_field_info() {
field_info_cache_clear();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment