Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
- Modules updates
- Performance script
  • Loading branch information
attiks committed Jul 13, 2016
2 parents 167fca1 + e9ac53d commit 2d9ba10
Show file tree
Hide file tree
Showing 99 changed files with 6,272 additions and 1,393 deletions.
236 changes: 167 additions & 69 deletions sites/all/modules/contrib/advagg/README.txt

Large diffs are not rendered by default.

168 changes: 156 additions & 12 deletions sites/all/modules/contrib/advagg/advagg.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ function advagg_admin_settings_form($form, $form_state) {
'#description' => t('If <a href="@link">HTTPRL</a> is installed, advagg will use it to generate aggregates on the fly in a background parallel process.', array('@link' => 'http://drupal.org/project/httprl')),
);
$form['global']['advagg_browser_dns_prefetch'] = array(
'#type' => 'checkbox',
'#type' => 'radios',
'#title' => t('Use DNS Prefetch for external CSS/JS.'),
'#default_value' => variable_get('advagg_browser_dns_prefetch', ADVAGG_BROWSER_DNS_PREFETCH),
'#description' => t('Start the DNS lookup for external CSS and JavaScript files as soon as possible.'),
'#description' => t('Start the DNS lookup for external CSS and JavaScript files as soon as possible. If you have css and/or js files being loaded right after the "charset=utf-8" meta tag, you need to use the "above charset=utf-8" option in order for dns-prefetch to work; Optimizely is an example that would need this other option.'),
'#options' => array(
0 => t('Disabled'),
1 => t('Enabled, below charset=utf-8 (recommended)'),
2 => t('Enabled, above charset=utf-8'),
),
);

$aggressive_cache_conflicts = advagg_aggressive_cache_conflicts();
Expand All @@ -71,11 +76,12 @@ function advagg_admin_settings_form($form, $form_state) {
'#title' => t('AdvAgg Cache Settings'),
'#default_value' => variable_get('advagg_cache_level', ADVAGG_CACHE_LEVEL),
'#options' => $options,
'#description' => t("As a reference, core takes about 25 ms to run. Development will scan all files for a change on every page load. Normal and the render cache is fine for all use cases. Aggressive should be fine for most use cases. If your inline css/js changes based off of a variable then the cache hit ratio will be low; if that is the case consider using Drupal.settings for a better cache hit ratio when using the render cache. The aggressive render cache will cache the output from js_alter and css_alter.", array(
'#description' => t("As a reference, core takes about 25 ms to run. Development will scan all files for a change on every page load. Normal and the render cache is fine for all use cases. Aggressive should be fine for most use cases. If your inline css/js changes based off of a variable then the cache hit ratio will be low; if that is the case consider using Drupal.settings for a better cache hit ratio when using the render cache. The aggressive render cache will cache the output from js_alter and css_alter. !description", array(
'@information' => url($config_path . '/advagg/info', array(
'fragment' => 'edit-hooks-implemented',
)),
)) . ' ' . $description,
'!description' => $description,
)),
);

$form['global']['dev_container'] = array(
Expand Down Expand Up @@ -182,6 +188,7 @@ function advagg_admin_settings_form($form, $form_state) {
'#type' => 'select',
'#options' => $long_times,
'#title' => 'Delete aggregates accessed/modified more than a set time ago.',
// @codingStandardsIgnoreLine
'#default_value' => variable_get('drupal_stale_file_threshold', 2592000),
'#description' => t('The default value for this is %value.', array('%value' => format_interval(2592000))),
);
Expand Down Expand Up @@ -259,6 +266,12 @@ function advagg_admin_settings_form($form, $form_state) {
),
),
);
$form['global']['obscure']['advagg_skip_file_create_url_inside_css'] = array(
'#type' => 'checkbox',
'#title' => t('Do not run CSS url() values through file_create_url().'),
'#default_value' => variable_get('advagg_skip_file_create_url_inside_css', ADVAGG_SKIP_FILE_CREATE_URL_INSIDE_CSS),
'#description' => t('If checked, the processing of url() values within CSS will be handled more like core than the CDN module. This has the advantage of not converting relative paths in your source CSS to absolute paths in the aggregated CSS.'),
);

$form['css'] = array(
'#type' => 'fieldset',
Expand Down Expand Up @@ -391,7 +404,7 @@ function advagg_admin_operations_form($form, $form_state) {
$form['cron'] = array(
'#type' => 'fieldset',
'#title' => t('Cron Maintenance Tasks'),
'#description' => t('The following 4 operations are ran on cron but you can run them manually here.'),
'#description' => t('The following 6 operations are ran on cron but you can run them manually here.'),
);
$form['cron']['smart_file_flush'] = array(
'#type' => 'fieldset',
Expand All @@ -405,6 +418,20 @@ function advagg_admin_operations_form($form, $form_state) {
'#value' => t('Remove All Stale Files'),
'#submit' => array('advagg_admin_flush_stale_files_button'),
);

$form['cron']['delete_orphaned_aggregates'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Delete orphaned aggregates'),
'#description' => t('Scan CSS/JS advagg dir and remove file if there is no associated db record.'),
);
$form['cron']['delete_orphaned_aggregates']['advagg_delete_orphaned_aggregates'] = array(
'#type' => 'submit',
'#value' => t('Delete orphaned aggregates'),
'#submit' => array('advagg_admin_delete_orphaned_aggregates_button'),
);

$form['cron']['remove_missing_files'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
Expand All @@ -417,6 +444,7 @@ function advagg_admin_operations_form($form, $form_state) {
'#value' => t('Clear Missing Files From Database'),
'#submit' => array('advagg_admin_remove_missing_files_from_db_button'),
);

$form['cron']['remove_old_aggregates'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
Expand All @@ -429,6 +457,7 @@ function advagg_admin_operations_form($form, $form_state) {
'#value' => t('Delete Unused Aggregates From Database'),
'#submit' => array('advagg_admin_remove_old_unused_aggregates_button'),
);

$form['cron']['cleanup_semaphore_table'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
Expand All @@ -438,10 +467,38 @@ function advagg_admin_operations_form($form, $form_state) {
);
$form['cron']['cleanup_semaphore_table']['advagg_cleanup_semaphore_table'] = array(
'#type' => 'submit',
'#value' => t('Delete Unused Aggregates From Database'),
'#value' => t('Delete Orphaned Semaphore Locks'),
'#submit' => array('advagg_admin_cleanup_semaphore_table_button'),
);

$form['cron']['cleanup_temp_files'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Delete leftover temporary files'),
'#description' => t('Delete old temporary files from the filesystem.'),
);
$form['cron']['cleanup_temp_files']['advagg_remove_temp_files'] = array(
'#type' => 'submit',
'#value' => t('Delete leftover temporary files'),
'#submit' => array('advagg_admin_cleanup_temp_files_button'),
);

if (module_exists('locale')) {
$form['cron']['refresh_locale_files'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Refresh all locale files'),
'#description' => t('Run all js files in the advagg_files table through locale_js_alter; loop for each enabled language.'),
);
$form['cron']['refresh_locale_files']['advagg_refresh_all_locale_files'] = array(
'#type' => 'submit',
'#value' => t('Refresh all locale files'),
'#submit' => array('advagg_admin_refresh_locale_files_button'),
);
}

// Hide drastic measures as they should not be done unless you really need it.
$form['drastic_measures'] = array(
'#type' => 'fieldset',
Expand Down Expand Up @@ -685,7 +742,7 @@ function advagg_admin_info_form($form, $form_state) {
$form['get_info_about_agg']['tip'] = array(
'#markup' => '<p>' . t('Takes input like "@css_file" or a full aggregate name like "@advagg_js"', array(
'@css_file' => $css_file,
'@advagg_js' => advagg_install_get_first_advagg_file($js_path[1]),
'@advagg_js' => advagg_install_get_first_advagg_file($js_path[1], 'js'),
)) . '</p>',
);
$form['get_info_about_agg']['wrapper'] = array(
Expand All @@ -695,15 +752,37 @@ function advagg_admin_info_form($form, $form_state) {
return $form;
}

/**
* Add various advagg settings to the system_performance_settings form.
*/
function advagg_admin_system_performance_settings_form(&$form, $form_state) {
$msg = t('NOTE: If you wish to bypass aggregation for a set amount of time, you can go to the <a href="@operations">AdvAgg operations</a> page and press the "aggregation bypass cookie" button.', array(
'@operations' => url('admin/config/development/performance/advagg/operations'),
)) . ' ';
if (user_access('bypass advanced aggregation')) {
$msg .= t('You can also selectively bypass aggregation by adding <code>@code</code> to the URL of any page.', array(
'@code' => '?advagg=0',
));
}
else {
$msg .= t('You do not have the <a href="@permission">bypass advanced aggregation permission</a> so adding <code>@code</code> to the URL will not work at this time for you; either grant this permission to your user role or use the bypass cookie if you wish to selectively bypass aggregation.', array(
'@permission' => url('admin/people/permissions', array('fragment' => 'module-advagg')),
'@code' => '?advagg=0',
));
}

$form['bandwidth_optimization']['advagg_note'] = array(
'#markup' => $msg,
);
}

// Submit callback.
/**
* Clear out the advagg cache bin when the save configuration button is pressed.
*/
function advagg_admin_settings_form_submit($form, &$form_state) {
$cache_bins = advagg_flush_caches();
foreach ($cache_bins as $bin) {
cache_clear_all('*', $bin, TRUE);
}
// Clear caches.
advagg_cache_clear_admin_submit();
}

// Callbacks for buttons.
Expand Down Expand Up @@ -733,6 +812,7 @@ function advagg_admin_toggle_bypass_cookie($form, &$form_state) {
* Display file info in a drupal message.
*/
function advagg_admin_get_file_info_submit($form, &$form_state) {
// @codingStandardsIgnoreLine
if (!empty($form_state['input']['ajax_page_state'])) {
return;
}
Expand Down Expand Up @@ -868,6 +948,14 @@ function advagg_admin_get_file_info($filename) {
* Perform a smart flush.
*/
function advagg_admin_flush_cache_button() {
// Clear the libraries cache.
if (function_exists('libraries_flush_caches')) {
$cache_tables = libraries_flush_caches();
foreach ($cache_tables as $table) {
cache_clear_all('*', $table, TRUE);
}
}

// Run the command.
module_load_include('inc', 'advagg', 'advagg.cache');
$flushed = advagg_push_new_changes();
Expand Down Expand Up @@ -907,6 +995,14 @@ function advagg_admin_flush_cache_button() {
* Clear out all advagg cache bins.
*/
function advagg_admin_clear_all_caches_button() {
// Clear the libraries cache.
if (function_exists('libraries_flush_caches')) {
$cache_tables = libraries_flush_caches();
foreach ($cache_tables as $table) {
cache_clear_all('*', $table, TRUE);
}
}

// Run the command.
module_load_include('inc', 'advagg', 'advagg.cache');
advagg_flush_all_cache_bins();
Expand Down Expand Up @@ -969,6 +1065,22 @@ function advagg_admin_increment_global_counter() {
drupal_set_message(t('Global counter is now set to %new_value', array('%new_value' => $new_value)));
}

/**
* Scan CSS/JS advagg dir and remove file if there is no associated db record.
*/
function advagg_admin_delete_orphaned_aggregates_button() {
module_load_include('inc', 'advagg', 'advagg.cache');

// Remove aggregates that include missing files.
$deleted = advagg_delete_orphaned_aggregates();
if (empty($deleted[0]) && empty($deleted[1])) {
drupal_set_message(t('All files have an associated db record; nothing was deleted.'));
}
else {
drupal_set_message(t('Some files had no associated db record and could be safely deleted from the file system. @raw', array('@raw' => print_r($deleted[1], TRUE))));
}
}

/**
* Scan for missing files and remove the associated entries in the database.
*/
Expand Down Expand Up @@ -1013,6 +1125,38 @@ function advagg_admin_cleanup_semaphore_table_button() {
drupal_set_message(t('No orphaned advagg semaphore database table locks discovered. Nothing was deleted.'));
}
else {
drupal_set_message(t('Some orphaned advagg semaphore database table locks discovered were found. A total of %count database entries were removed.', array('%count' => $count)));
drupal_set_message(format_plural($count, '1 orphaned advagg semaphore database table lock was found. A total of 1 database entry was removed.', 'Some orphaned advagg semaphore database table locks were found. A total of @count database entries were removed.'));
}
}

/**
* Delete orphaned/expired advagg locks from the semaphore database table.
*/
function advagg_admin_refresh_locale_files_button() {
module_load_include('inc', 'advagg', 'advagg.cache');

// Refresh all locale files.
$locale_files = advagg_refresh_all_locale_files();
if (empty($locale_files)) {
drupal_set_message(t('No locale files are being used.'));
}
else {
drupal_set_message(t('The following locale files are being used: <pre>@files</pre>', array('@files' => print_r($locale_files, TRUE))));
}
}

/**
* Delete leftover temp files.
*/
function advagg_admin_cleanup_temp_files_button() {
module_load_include('inc', 'advagg', 'advagg.cache');

// Delete orphaned/expired advagg locks from the semaphore database table.
$count = advagg_remove_temp_files();
if (empty($count)) {
drupal_set_message(t('No leftover temp files found. Nothing was deleted.'));
}
else {
drupal_set_message(format_plural($count, '1 leftover temp files from advagg was found. A total of 1 temp files was removed.', 'Some leftover temp files from advagg were found. A total of %count temp files were removed.'));
}
}
18 changes: 9 additions & 9 deletions sites/all/modules/contrib/advagg/advagg.admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
/**
* Test to see if the given string contains unicode.
*
* @param int interval
* @param {int} interval
* String to test.
* @param int granularity
* @param {int} granularity
* String to test.
* @param string langcode
* @param {string} langcode
* Language used in translation.
*
* @return
* @return {bool}
* true if string contains non ASCII characters.
* false if string only contains ASCII characters.
*/
Drupal.formatInterval = function(interval, granularity, langcode) {
Drupal.formatInterval = function (interval, granularity, langcode) {
"use strict";
granularity = typeof granularity !== 'undefined' ? granularity : 2;
langcode = typeof langcode !== 'undefined' ? langcode : null;
Expand Down Expand Up @@ -66,14 +66,14 @@ Drupal.formatInterval = function(interval, granularity, langcode) {
/**
* Test to see if the given string contains unicode.
*
* @param str
* @param {string} str
* String to test.
*
* @return
* @return {bool}
* true if string contains non ASCII characters.
* false if string only contains ASCII characters.
*/
function advagg_is_unicode(str){
function advagg_is_unicode(str) {
"use strict";
for (var i = 0, n = str.length; i < n; i++) {
if (str.charCodeAt(i) > 255) {
Expand All @@ -86,7 +86,7 @@ function advagg_is_unicode(str){
/**
* Toggle the advagg cookie.
*
* @return
* @return {bool}
* true if hostname contains unicode.
* false so the form does not get submitted.
*/
Expand Down
Loading

0 comments on commit 2d9ba10

Please # to comment.