Last active
October 6, 2015 06:57
-
-
Save danquah/2954262 to your computer and use it in GitHub Desktop.
Remake tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#!/usr/bin/env drush | |
// add -dv to enable debugging | |
$drush_cmd = "drush"; | |
// local alias | |
$self_record = drush_sitealias_get_record('@self'); | |
$self_name = '@' . $self_record['#name']; | |
if (empty($self_record)) { | |
return drush_set_error('No bootstrapped site!'); | |
} else { | |
drush_print(dt('Rebuilding site for !name', array('!name' => $self_record['#name']))); | |
} | |
// prod alias | |
$prod_record = drush_sitealias_get_record('@' . $self_record['#group'] . '.prod'); | |
$prod_name = '@' . $prod_record['#name']; | |
// create a temp dir for sites/default | |
$tmp = drush_tempdir(); | |
drush_copy_dir('sites/default',$tmp.'/default'); | |
// ensure that we are in the root dir of site | |
$oldir = getcwd(); | |
chdir($self_record['root']); | |
// execute drush make | |
drush_log('Drush Making site from git', 'ok'); | |
$cmd = "$drush_cmd make --no-gitinfofile --working-copy -y 'https://raw.github.com/reload/Scleroseforeningen/develop/build_sclerosis.make?login=reload-deploy&token=803ab6f117f8ac471f6a068c7c9511b1' ."; | |
drush_shell_exec_interactive($cmd); | |
drush_log('Setting up git flow for repo in ' . $self_record['root'] . '/profiles/sclerosis', 'ok'); | |
// change path into the git checkout | |
chdir($self_record['root'] . '/profiles/sclerosis'); | |
drush_shell_exec('git flow init -d'); | |
drush_shell_exec('git checkout develop'); | |
drush_shell_exec('git branch --set-upstream develop origin/develop'); | |
// back to site root | |
chdir($self_record['root']); | |
// make just downloaded an aliases file, update it with the lastest info from aegir | |
drush_log("Updating prod alias from aegir via $prod_name", 'ok'); | |
$alias_file = $self_record['root'] . '/sites/all/drush/sclerosis.aliases.drushrc.php'; | |
if(!file_exists($alias_file)){ | |
drush_log("Error while updating alias-file from aegir, could not find " . $alias_file, 'error'); | |
return; | |
} | |
include($alias_file); | |
// Contact prod aegir and get a db dump. | |
$eval_array = `drush --ssh-options="-q" $prod_name exec drush provision-alias-export scleroseforeningen.dk`; | |
// Merge the new info into our template if we get anything. | |
if (strpos($eval_array, 'array') === 0) { | |
eval('$temp_array = ' . $eval_array); | |
$env = 'prod'; | |
$aliases[$env] = array_merge($aliases[$env], $temp_array); | |
} | |
// output the new alias file | |
copy($alias_file, $alias_file . '_backup'); | |
file_put_contents($alias_file, '<?php ' . "\n" . '$aliases = ' . var_export($aliases, TRUE) . ';'); | |
drush_log('Updated local alias from aegir', 'ok'); | |
// change back and fetch temp dir | |
chdir($oldir); | |
drush_copy_dir($tmp.'/default','sites/default',TRUE); | |
drush_delete_tmp_dir($tmp); | |
// Copy the database from production to local | |
drush_log("Synchronizing sql data from prod", 'ok'); | |
$cmd = "$drush_cmd -y sql-sync --no-cache $prod_name $self_name"; | |
drush_shell_exec_interactive($cmd); | |
// sync files folder | |
// defaults | |
drush_log("Configuring file paths", 'ok'); | |
$private_path = "sites/default/files"; | |
$public_path = "sites/default/files"; | |
drush_mkdir('sites/scleroseforeningen.dk/private/temp'); | |
$output = `$drush_cmd vget file_private_path --format=export`; | |
if (!empty($output)) { | |
eval($output); | |
$private_path = $variables['file_private_path']; | |
drush_mkdir($private_path); | |
} | |
$output = `$drush_cmd vget file_public_path --format=export`; | |
if (!empty($output)) { | |
eval($output); | |
$public_path = $variables['file_public_path']; | |
drush_mkdir($public_path); | |
} | |
drush_log("Rsyncing $prod_name:private/ $self_name:$private_path", 'ok'); | |
$cmd = "$drush_cmd -y rsync $prod_name:private/ $self_name:$private_path"; | |
drush_shell_exec_interactive($cmd); | |
drush_log("Rsyncing $prod_name:files/ $self_name:$public_path", 'ok'); | |
$cmd = "$drush_cmd -y rsync $prod_name:files/ $self_name:$public_path"; | |
drush_shell_exec_interactive($cmd); | |
// Disable modules | |
$modules = array( | |
'backup_migrate', | |
'googleanalytics', | |
'securepages', | |
); | |
foreach ($modules as $module) { | |
drush_log("Disabling module \"$module\"", 'ok'); | |
drush_shell_exec("$drush_cmd pm-disable $module -y"); | |
} | |
// Download modules | |
$modules_dl = array ('devel', 'search_api_db', 'ftools'); | |
foreach ($modules_dl as $module){ | |
drush_log("Downloading module \"$module\"", 'ok'); | |
drush_shell_exec("$drush_cmd -y dl $module"); | |
} | |
// Enable modules | |
$modules = array( | |
'search_api_db', | |
'devel', | |
'views_ui', | |
'features_tools', | |
); | |
foreach ($modules as $module) { | |
drush_log("Enabling module \"$module\"", 'ok'); | |
drush_shell_exec("$drush_cmd -y en $module"); | |
} | |
// Disable caching | |
drush_log("Disabling caching", 'ok'); | |
drush_shell_exec("$drush_cmd vset preprocess_js 0"); | |
drush_shell_exec("$drush_cmd vset cache 0"); | |
drush_shell_exec("$drush_cmd vset preprocess_css 0"); | |
// logging level | |
drush_shell_exec("$drush_cmd vset error_level 2"); | |
// set site name | |
drush_log("Setting site name to LOCAL SCL", 'ok'); | |
drush_shell_exec("$drush_cmd vset site_name 'LOCAL SCL'"); | |
drush_log("Setting up local Search Api server", 'ok'); | |
// insert new search server | |
drush_shell_exec("$drush_cmd sqlq \"INSERT INTO search_api_server (name, machine_name, description, class, options, enabled, status, module) VALUES ('Local DB', 'local_db', '', 'search_api_db_service', 'a:2:{s:8:\\\"database\\\";s:15:\\\"default:default\\\";s:9:\\\"min_chars\\\";s:1:\\\"1\\\";}', 1, 1, NULL)\""); | |
// switch index to use it | |
drush_shell_exec("$drush_cmd sqlq \"UPDATE search_api_index set server = 'local_db'\""); | |
// make sure to flush out anything in the caches | |
drush_log("Clearing cache", 'ok'); | |
drush_shell_exec("$drush_cmd cc all"); | |
drush_log('Rebuild complete', 'success'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what is this for?
have you see http://drupal.org/project/devshop ?