Commit 622e2a27 authored by Liam Morland's avatar Liam Morland
Browse files

Coding standards

parent 9782a21b
......@@ -840,4 +840,4 @@ UW Base Profile 7.x-2.0.0-beta1 through -beta3
TBD as this file wasn't updated for these releases. Beta1 represents all changes from 7.x-1.12.3 to convert to 2.0.x.
NOTE: Changelogs for the 1.x branch can be found in the 1.x branch, as it is separately maintained since 7.x-1.12.3.
\ No newline at end of file
NOTE: Changelogs for the 1.x branch can be found in the 1.x branch, as it is separately maintained since 7.x-1.12.3.
......@@ -18,63 +18,66 @@ $items = array(
);
$sites = array(
// University of Waterloo
// University of Waterloo.
'uwaterloo.ca',
'*.uwaterloo.ca',
// Bootstrap
// Bootstrap.
'maxcdn.bootstrapcdn.com',
// Google
// Google.
'*.google.com',
'*.google-analytics.com',
'*.googleapis.com',
'*.gstatic.com',
'*.googletagmanager.com',
'*.googleusercontent.com',
'stats.g.doubleclick.net', // Google Analytics
'6263835.fls.doubleclick.net', // Google's DoubleClick, for MSI's use
// Google Analytics.
'stats.g.doubleclick.net',
// Google's DoubleClick, for MSI's use.
'6263835.fls.doubleclick.net',
// CDNjs (Cloudflare)
'cdnjs.cloudflare.com',
// Twitter
// Twitter.
'*.twitter.com',
'*.twimg.com',
'twitter-widgets.s3.amazonaws.com',
// FaceBook
// FaceBook.
'*.facebook.com',
'*.facebook.net',
// YouTube
// YouTube.
'*.youtube.com',
'*.youtube-nocookie.com',
// Livestream
// Livestream.
'*.livestream.com',
// WebSpellChecker.net
// WebSpellChecker.net.
'*.webspellchecker.net',
// MathJax
// MathJax.
'cdn.mathjax.org',
// storify.com
// storify.com.
'storify.com',
// AddToAny
// AddToAny.
'*.addtoany.com',
// Vimeo
// Vimeo.
'*.vimeo.com',
'*.vimeocdn.com',
// Tint
// Tint.
'*.tintup.com',
'*.71n7.com', // RT#456523
// Tint; RT#456523.
'*.71n7.com',
'd36hc0p18k1aoc.cloudfront.net',
// Maps
// Maps.
'cdn.leafletjs.com',
'cdn-geoweb.s3.amazonaws.com',
'cdn.maptiks.com',
'api.tiles.mapbox.com',
'd591zijq8zntj.cloudfront.net',
// LibAnswers. RT#429697
// LibAnswers. RT#429697.
'*.libanswers.com',
// Skype. RT#429697
// Skype. RT#429697.
'secure.skype.com',
// Domains required for Lightning Bolt, used by MSI. RT#563158
// Domains required for Lightning Bolt, used by MSI. RT#563158.
'cdn-akamai.mookie1.com',
'*.tiqcdn.com',
// Eyereturn, used by CBET. RT#569453
// Eyereturn, used by CBET. RT#569453.
'o2.eyereturn.com',
);
while ($site = array_shift($sites)) {
......
<?php
// Show all errors on most servers. On live, these are turned off in host_settings.php.
/**
* @file
* Show all errors on most servers. On live, these are turned off in host_settings.php.
*/
$conf['error_level'] = 2;
foreach (array('db', 'host', 'network', 'cache', 'password') as $file) {
$file_path = DRUPAL_ROOT . '/config/' . $file. '_settings.php';
$file_path = DRUPAL_ROOT . '/config/' . $file . '_settings.php';
if (file_exists($file_path)) {
require_once($file_path);
require_once $file_path;
}
}
unset($file);
......@@ -62,7 +66,8 @@ $conf['user_picture_style'] = 'thumbnail';
// Other.
$conf['shortcut_max_slots'] = 12;
$conf['user_register'] = 0; // Same value as constant USER_REGISTER_ADMINISTRATORS_ONLY. Constant not yet defined.
// Same value as constant USER_REGISTER_ADMINISTRATORS_ONLY. Constant not yet defined.
$conf['user_register'] = 0;
$conf['scheduler_publisher_user'] = 'specific_user';
$conf['scheduler_date_popup_minute_increment'] = 15;
$conf['update_check_disabled'] = TRUE;
......@@ -107,7 +112,7 @@ if (isset($UWsec)) {
}
// Fast 404 settings - documented in modules/contrib/fast_404/README.txt.
include_once('modules/contrib/fast_404/fast_404.inc');
include_once 'modules/contrib/fast_404/fast_404.inc';
$conf['fast_404_exts'] = '/^(?!help\/)(?!robots).*\.(txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/';
$conf['fast_404_allow_anon_imagecache'] = TRUE;
$conf['fast_404_html'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL was not found on this server.</p></body></html>';
......
......@@ -9,12 +9,12 @@
* CALL THIS from your profile_install_tasks_alter() hook function.
*/
function install_from_db_install_tasks_alter(&$tasks, $install_state) {
// prevent cron from running when finished
// Prevent cron from running when finished.
$tasks['install_finished']['function'] = 'install_from_db_install_finished';
// redirect the drupal install_profile_modules step to our own function
// Redirect the drupal install_profile_modules step to our own function.
$tasks['install_profile_modules']['function'] = 'install_from_db_install_profile_modules';
// add the new quickstart step to the installer
// Add the new quickstart step to the installer.
$quickstart = array(
'display_name' => st('Choose installation method'),
'type' => 'form',
......@@ -42,21 +42,21 @@ function install_from_db_install_tasks_alter(&$tasks, $install_state) {
'install_from_db_features_revert_all_batch', $features_revert_all_batch);
$tasks = _install_from_db_insert_after_key($tasks, 'install_profile_modules',
'install_from_db_update_batch', $update_batch);
//$tasks = _install_from_db_insert_after_key($tasks, 'install_profile_update_batch',
// 'install_from_db_features_revert_all_batch', $features_revert_all_batch);
// $tasks = _install_from_db_insert_after_key($tasks, 'install_profile_update_batch',
// 'install_from_db_features_revert_all_batch', $features_revert_all_batch);.
}
/**
* Helper function to insert a key/value pair before an existing key
* Used to re-order the install tasks array
* Used to re-order the install tasks array.
*/
function _install_from_db_insert_before_key($originalArray, $originalKey, $insertKey, $insertValue) {
$newArray = array();
$inserted = false;
$inserted = FALSE;
foreach ($originalArray as $key => $value) {
if (!$inserted && ($key === $originalKey)) {
$newArray[$insertKey] = $insertValue;
$inserted = true;
$inserted = TRUE;
}
$newArray[$key] = $value;
}
......@@ -65,16 +65,16 @@ function _install_from_db_insert_before_key($originalArray, $originalKey, $inser
/**
* Helper function to insert a key/value pair after an existing key
* Used to re-order the install tasks array
* Used to re-order the install tasks array.
*/
function _install_from_db_insert_after_key($originalArray, $originalKey, $insertKey, $insertValue) {
$newArray = array();
$inserted = false;
$inserted = FALSE;
foreach ($originalArray as $key => $value) {
if (!$inserted && ($key === $originalKey)) {
$newArray[$key] = $value;
$newArray[$insertKey] = $insertValue;
$inserted = true;
$inserted = TRUE;
}
else {
$newArray[$key] = $value;
......@@ -94,7 +94,7 @@ function install_from_db_update_batch() {
print "Running pending database updates\n";
}
// Load update include file to run updates.
require_once (DRUPAL_ROOT . '/includes/update.inc');
require_once DRUPAL_ROOT . '/includes/update.inc';
$operations = array();
$starting_updates = array();
$pending_updates = update_get_update_list();
......@@ -131,7 +131,7 @@ function install_from_db_update_batch() {
$functions[] = $function;
$operations[] = array('update_do_one', array($update['module'], $update['number'], $dependency_map[$function]));
}
$batch = array (
$batch = array(
'operations' => $operations,
'title' => st('Updating site database'),
'init_message' => st('Starting site database updates'),
......@@ -156,7 +156,7 @@ function install_from_db_update_batch() {
}
/**
* Report the batch is completed
* Report the batch is completed.
*/
function install_from_db_update_batch_finished() {
global $install_state;
......@@ -169,16 +169,17 @@ function install_from_db_update_batch_finished() {
drupal_set_message($message);
}
}
/**
* Feature revert all features
* Feature revert all features.
*/
function install_from_db_features_revert_all_batch() {
global $install_state;
if (!empty($install_state['parameters']['quickstart']) && $install_state['parameters']['quickstart'] == 'quick') {
module_load_include('inc', 'features', 'features.export');
include_once(drupal_get_path('module', 'features') . '/features.module');
include_once drupal_get_path('module', 'features') . '/features.module';
$operations = array();
//$restore_states = array(FEATURES_OVERRIDDEN, FEATURES_NEEDS_REVIEW);
// $restore_states = array(FEATURES_OVERRIDDEN, FEATURES_NEEDS_REVIEW);.
$restore_states = array(FEATURES_OVERRIDDEN, FEATURES_REBUILDABLE, FEATURES_NEEDS_REVIEW);
// Clear cache because an database update might have change something.
......@@ -206,7 +207,7 @@ function install_from_db_features_revert_all_batch() {
watchdog('install', count($operations) . ' features to revert.', array(), WATCHDOG_INFO);
print count($operations) . " features have components to revert.\n";
}
$batch = array (
$batch = array(
'operations' => $operations,
'title' => st('Revert overridden/needs review features components'),
'init_message' => st('Starting to revert overidden or needs review components.'),
......@@ -218,7 +219,7 @@ function install_from_db_features_revert_all_batch() {
}
/**
* Report the batch is completed
* Report the batch is completed.
*/
function install_from_db_features_revert_all_batch_finished() {
global $install_state;
......@@ -231,6 +232,7 @@ function install_from_db_features_revert_all_batch_finished() {
drupal_set_message($message);
}
}
/**
* Prompt user to select normal or quick installation method
* TODO: Check db to be sure it is mysql, or provide mechanism for
......@@ -241,14 +243,14 @@ function install_from_db_features_revert_all_batch_finished() {
*/
function install_from_db_form($form, &$form_state, &$install_state) {
$profile = $install_state['parameters']['profile'];
// find database dump in the /db folder within the profile
// TODO: support different database dump formats
// Find database dump in the /db folder within the profile
// TODO: support different database dump formats.
$filename = DRUPAL_ROOT . '/profiles/' . $profile . '/db/' . $profile . '.mysql';
$conn = Database::getConnection('default');
if (!file_exists($filename) || !$conn || ($conn->driver() !== 'mysql')) {
// can't do quickstart if no db dump exists
// also only allow quickstart for mysql databases currently
// also only allow quickstart for mysql databases currently.
unset($install_state['parameters']['quickstart']);
$form_state['executed'] = TRUE;
return;
......@@ -256,14 +258,14 @@ function install_from_db_form($form, &$form_state, &$install_state) {
$install_state['parameters']['db_import_filename'] = $filename;
if ($install_state['interactive'] && !empty($install_state['parameters']['quickstart'])) {
// if url argument is already specified, then just use it
// If url argument is already specified, then just use it.
$form_state['input']['quickstart'] = $install_state['parameters']['quickstart'];
$form_state['executed'] = TRUE;
return;
}
if (!$install_state['interactive'] && !isset($form_state['values']['quickstart'])) {
// default non-interactive to quickstart
// Default non-interactive to quickstart.
$install_state['parameters']['quickstart'] = 'quick';
$form_state['input']['quickstart'] = 'quick';
}
......@@ -285,7 +287,7 @@ function install_from_db_form($form, &$form_state, &$install_state) {
'#parents' => array('quickstart'),
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => st('Save and continue'),
);
......@@ -310,11 +312,10 @@ function install_from_db_form_submit($form, &$form_state) {
$install_state['parameters']['quickstart'] = $form_state['input']['quickstart'];
}
/**
* overrides install_profile_modules()
* Overrides install_profile_modules()
* For quick install, load database from sql dump
* otherwise install normally
* otherwise install normally.
*/
function install_from_db_install_profile_modules(&$install_state) {
if (!empty($install_state['parameters']['quickstart']) && ($install_state['parameters']['quickstart'] === 'quick') && !empty($install_state['parameters']['db_import_filename'])) {
......@@ -323,10 +324,10 @@ function install_from_db_install_profile_modules(&$install_state) {
watchdog('install', $message, array(), WATCHDOG_INFO);
print $message . "\n";
}
// bypass normal module installation
// Bypass normal module installation
// load database dump instead
// uses batch because normal module install task uses batch
// and it's also good for this potentially time consuming db restore
// and it's also good for this potentially time consuming db restore.
$operations = array();
$defer_operations = array();
$system_sql = '';
......@@ -334,9 +335,9 @@ function install_from_db_install_profile_modules(&$install_state) {
if (file_exists($filename)) {
$file = fopen($filename, 'rb');
if ($file) {
while (($line = _install_from_db_read_sql_batch($file, $table)) !== false) {
while (($line = _install_from_db_read_sql_batch($file, $table)) !== FALSE) {
if (!empty($line)) {
// don't process blank lines
// don't process blank lines.
if (in_array($table, array('system'))) {
$defer_operations[] = array('_install_from_db_install_db_import', array($line, $table));
}
......@@ -389,7 +390,7 @@ function _install_from_db_cc_all() {
if (!$install_state['interactive']) {
print t("Clean Up commencing. Clearing caches, rebuilding registry and loading the modules files as if we just installed them.") . "\n";
}
// load the module files as if we just installed them
// Load the module files as if we just installed them.
cache_clear_all('lookup_cache', 'cache_bootstrap');
cache_clear_all('variables', 'cache_bootstrap');
cache_clear_all('module_implements', 'cache_bootstrap');
......@@ -419,7 +420,7 @@ function _install_from_db_install_db_import($line, $table, &$context) {
global $conf;
if ($table === 'variable') {
// save/restore some variables needed by installer or unique to new site
// save/restore some variables needed by installer or unique to new site.
$saved_vars = array('install_task', 'install_current_batch', 'cron_key', 'drupal_private_key');
foreach ($saved_vars as $var) {
$saved_values[$var] = variable_get($var, '');
......@@ -434,12 +435,12 @@ function _install_from_db_install_db_import($line, $table, &$context) {
$stmt->closeCursor();
if ($table === 'variable') {
// restore saved variables
// Restore saved variables.
foreach ($saved_vars as $var) {
variable_set($var, $saved_values[$var]);
}
}
else if ($table === 'system') {
elseif ($table === 'system') {
// Flush all caches to complete the module installation process. Subsequent
// installation tasks will now have full access to the profile's modules.
_install_from_db_cc_all();
......@@ -448,8 +449,12 @@ function _install_from_db_install_db_import($line, $table, &$context) {
/**
* Read a batch of sql commands (ending in commit)
* @param $file - name of file to read from
* @param $table - name of table referenced in sql statements is returned
*
* @param $file
* - name of file to read from
* @param $table
* - name of table referenced in sql statements is returned
*
* @return - string containing sql commands for a single table.
*/
function _install_from_db_read_sql_batch($file, &$table) {
......@@ -457,49 +462,50 @@ function _install_from_db_read_sql_batch($file, &$table) {
$line = '';
$table = '';
$skip = FALSE;
$skip_tables = array('batch', 'cache', 'sessions', 'queue', 'semaphore'); // 'users',
while (($newline = _install_from_db_read_sql_command_from_file($file)) !== false) {
// process the line read.
// 'users',.
$skip_tables = array('batch', 'cache', 'sessions', 'queue', 'semaphore');
while (($newline = _install_from_db_read_sql_command_from_file($file)) !== FALSE) {
// Process the line read.
$newline_prefix = _install_from_db_replace_prefix($newline, $conn);
// block of SQL starts with a Table structure comment
// Block of SQL starts with a Table structure comment.
if (preg_match('/Table structure for table `([^`]+)`/', $newline, $matches)) {
$new_table = $matches[1];
if (!empty($table) && ($new_table !== $table)) {
// close out the previous table
// put this line back into the read buffer for the next time
// Close out the previous table
// put this line back into the read buffer for the next time.
_install_from_db_read_sql_command_from_file($file, $newline);
break;
}
$table = $new_table;
if (!$skip) {
// EDIT: drupal does not rebuild some of the cache_* (ie cache_block). $skip
//if (in_array($table, $skip_tables) || (strpos($table, 'cache_') === 0)) {
// if (in_array($table, $skip_tables) || (strpos($table, 'cache_') === 0)) {.
if (in_array($table, $skip_tables) || (strpos($table, 'cache_bootstrap') === 0)) {
// skip listed tables, along with any cache_* table
// Skip listed tables, along with any cache_* table
// has to be commented out or allow table to be created but nothing inserted.
$skip = TRUE;
}
}
}
if (preg_match('/\A(CREATE TABLE )`([^`]+)`/', $newline, $matches)) {
// always check first before creating tables
// Always check first before creating tables.
$newline_prefix = preg_replace('/\ACREATE TABLE/', 'CREATE TABLE IF NOT EXISTS', $newline_prefix);
if ($skip) {
// make sure skipped tables are still created
// Make sure skipped tables are still created.
$line .= $newline_prefix;
}
}
if (!empty($newline) && substr($newline, 0, 2) == '--') {
// otherwise skip comments
// Otherwise skip comments.
$newline_prefix = '';
}
if (!$skip && !empty($newline_prefix)) {
$line .= $newline_prefix;
}
// block of SQL ends with a commit command.
// Block of SQL ends with a commit command.
if ($newline === 'commit;') {
// be sure to turn autocommit back on for Drupal batch system and other database
// queries to work properly
// Be sure to turn autocommit back on for Drupal batch system and other database
// queries to work properly.
$line .= 'set autocommit=1;';
}
}
......@@ -513,30 +519,30 @@ function _install_from_db_read_sql_batch($file, &$table) {
* Read a multiline sql command from a file.
*
* Supports the formatting created by mysqldump, but won't handle multiline comments.
* Taken from backup_migrate module
* Taken from backup_migrate module.
*/
function _install_from_db_read_sql_command_from_file($file, $save_line = '') {
static $save_for_later = '';
if (!empty($save_for_later)) {
// check if a previous line was saved
// Check if a previous line was saved.
$out = $save_for_later;
$save_for_later = '';
return trim($out);
}
if (!empty($save_line)) {
// save this text for the next time we read from file
// used to stuff the previous line back into the read buffer
// Save this text for the next time we read from file
// used to stuff the previous line back into the read buffer.
$save_for_later = $save_line;
return;
}
$out = '';
while (($line = fgets($file)) !== false) {
while (($line = fgets($file)) !== FALSE) {
$line = trim($line);
if (empty($out) && !empty($line) && substr($line, 0, 2) == '--') {
// return single line comments
// Return single line comments.
return trim($line);
}
// Otherwise, ignore single line comments within a sql statement.
......@@ -555,7 +561,7 @@ function _install_from_db_read_sql_command_from_file($file, $save_line = '') {
}
/**
* Apply the correct prefix to tables in the SQL statement
* Apply the correct prefix to tables in the SQL statement.
*/
function _install_from_db_replace_prefix($line, $conn) {
$patterns = array(
......@@ -567,7 +573,7 @@ function _install_from_db_replace_prefix($line, $conn) {
'UPDATE',
);
foreach ($patterns as $pattern) {
// handle lines like this: /*!40000 ALTER TABLE `actions` ENABLE KEYS */;
// Handle lines like this: /*!40000 ALTER TABLE `actions` ENABLE KEYS */;.
$find = '#\A((/\*\!\d+ )?' . $pattern . ' )`([^`]+)`#';
// NOTE: We need to replace `tablename` with the new prefixed table name
// We cannot run $conn->prefixQuery on the entire $line because it will mess
......@@ -608,7 +614,7 @@ function install_from_db_install_finished(&$install_state) {
// Remember the profile which was used.
variable_set('install_profile', drupal_get_profile());
// Installation profiles are always loaded last
// Installation profiles are always loaded last.
db_update('system')
->fields(array('weight' => 1000))
->condition('type', 'module')
......@@ -627,7 +633,7 @@ function install_from_db_install_finished(&$install_state) {
//
// drupal_cron_run();
//
// Mark cron as run so it doesn't run on next page load either
// Mark cron as run so it doesn't run on next page load either.
variable_set('cron_last', REQUEST_TIME);
return $output;
......
......@@ -5,7 +5,7 @@
* Provides ability for installation profiles to install core modules from a
* database dump.
*
* Subprofiles module can extend the features to install afterwards
* Subprofiles module can extend the features to install afterwards.
*
* For interactive installs, the install from database can be selected before the
* profile dependencies are install. If the install from database is not selected
......@@ -15,5 +15,5 @@
// Include only when in install mode. MAINTENANCE_MODE is defined in
// install.php and in drush_core_site_install().
if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install') {
include_once('install_from_db.install.inc');
include_once 'install_from_db.install.inc';
}
<?php
/**
* @file
*/
/**
* Implements hook_install().
*
......
<?php
// Add global for $install_from_db so it gets referenced correctly in a later function.
/**
* @file
* Add global for $install_from_db so it gets referenced correctly in a later function.
*/
global $install_from_db;
// Set to FALSE to create a new database export.
$install_from_db = FALSE;
if ($install_from_db) {
include_once('install_from_db/install_from_db.install.inc');
include_once 'install_from_db/install_from_db.install.inc';
}
/**
......@@ -63,24 +68,24 @@ function uw_base_profile_install_tasks(&$install_state) {
/*
// Revert all features.
$tasks['uw_base_profile_features_revert_all'] = array(
'type' => 'normal',
'type' => 'normal',
);
// Set default permissions.
$tasks['uw_base_profile_set_permissions'] = array(
'type' => 'normal',
'type' => 'normal',
);
// Rebuild node access.
$tasks['uw_base_profile_node_access_rebuid'] = array(
'type' => 'normal',
'type' => 'normal',
);
*/
*/
// Skip tasks of installing site controller and all interactive form if using quickstart.
if (!empty($install_state['parameters']['quickstart']) && $install_state['parameters']['quickstart'] == 'quick') {
foreach ($tasks as $task_name => $task) {
$tasks['uw_base_profile_install_site_controller']['run'] = INSTALL_TASK_SKIP;
if (isset($tasks[$task_name]['type']) && $tasks[$task_name]['type'] == 'form') {
$tasks['uw_base_profile_install_site_controller']['run'] = INSTALL_TASK_SKIP;
if (isset($tasks[$task_name]['type']) && $tasks[$task_name]['type'] == 'form') {
$tasks[$task_name]['run'] = INSTALL_TASK_SKIP;
}
}
}
}
return $tasks;
......@@ -98,7 +103,7 @@ function uw_base_profile_install_tasks_alter(&$tasks, $install_state) {
/**
* Task callback: installs the site controller.
*/
*/
function uw_base_profile_install_site_controller() {
$success = module_enable(array('uw_site_fdsu'));
if (!$success) {
......@@ -113,9 +118,9 @@ function uw_base_profile_features_revert_all() {
global $install_state;
drupal_set_time_limit(0);
// Revert specific feature sections before reverting them all.
//features_revert(array(
// features_revert(array(
// 'feature_name' => array('feature_section1', 'feature_section2'),
//));
// ));.
features_revert();
}
......@@ -140,7 +145,7 @@ function uw_select_site_features_form() {
'#title' => st('Select the authentication type:'),
'#options' => array(
0 => st('Closed: do not create Drupal accounts for any CAS login'),