Skip to content

Commit

Permalink
Merge pull request #1 from ec-europa/nept-2332
Browse files Browse the repository at this point in the history
NEPT-2332: Remove "check scope" button.
  • Loading branch information
Fefaine authored Jul 31, 2019
2 parents 77d76aa + 8f65855 commit 2e6da06
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 48 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ The option **`A specific list of regex`** allows defining a set of regex matchi

The field description provides hints for testing validity of the regex you entered in the field.

The `Check scope` button allows evaluating if the regex is built to return the paths you would expect to clear.

After setting up a rule you need to submit it by clicking the **'Save'** button.
If the regular expression you entered is not valid, the following warning will be shown
```
Expand Down Expand Up @@ -189,6 +187,6 @@ Therefore, if you entered a rule in a previous version and this rule does not ma
in place, a warning will appear :
```
Please check your varnish rules , the regex ^an-already-inserted/rule you are trying to flush is not valid.
We suggest you review and save your regex rules again using the documentation available and the
"Check Scope" button. In case of doubt, please contact your site administrator or the devops team.
We suggest you review and save your regex rules again using the documentation available.
In case of doubt, please contact your site administrator or the devops team.
```
2 changes: 1 addition & 1 deletion nexteuropa_varnish.module
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ function _nexteuropa_varnish_purge_paths($paths) {
else {
drupal_set_message(
t(
'Please !check_config, the regex %regex you are trying to flush is not valid. We suggest you review and save your regex rules again using <a href="@doc">the documentation available</a> and the "Check Scope" button. In case of doubt, please contact your site administrator or the devops team.',
'Please !check_config, the regex %regex you are trying to flush is not valid. We suggest you review and save your regex rules again using <a href="@doc">the documentation available</a>. In case of doubt, please contact your site administrator or the devops team.',
array(
'!check_config' => l(
t('check your varnish rules'),
Expand Down
43 changes: 0 additions & 43 deletions nexteuropa_varnish.rules.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ function nexteuropa_varnish_cache_purge_rule_form($form, &$form_state, $purge_ru
'#prefix' => '<div id="specifics-for-cache-purge-type">',
'#suffix' => '</div>',
);
// Code here to populate the scope container.
// @TODO views paths?
if (isset($form_state['scope'])) {
$warning = '<h2>Here is the 100 first results matching your regex</h2>';
$warning .= '<h3>Your rule was not saved, to save it click "Save" button</h3>';
$form['scope']['#prefix'] = '<div class="messages status">';
$form['scope']['#suffix'] = '</div>';
$form['scope']['#markup'] = $warning . $form_state['scope'];
}

$current_rule_type = isset($form_state['values']['rule_type']) ? $form_state['values']['rule_type'] : $type_default_value;

Expand All @@ -68,12 +59,6 @@ function nexteuropa_varnish_cache_purge_rule_form($form, &$form_state, $purge_ru
'#required' => TRUE,
'#description' => _nexteuropa_varnish_paths_description(),
);
$form['specifics']['actions']['check_scope'] = array(
'#type' => 'submit',
'#value' => t('Check scope'),
'#submit' => array('_nexteuropa_varnish_check_scope'),
'#weight' => 41,
);
$form['#validate'][] = '_nexteuropa_varnish_regex_validate';
}

Expand Down Expand Up @@ -104,33 +89,6 @@ function _nexteuropa_varnish_regex_validate($form, &$form_state) {
}
}

/**
* Custom function checks which site URLs match the regex pattern.
*/
function _nexteuropa_varnish_check_scope(&$form, &$form_state) {
$output = '';
$regex = _nexteuropa_varnish_gather_expressions($form_state['values']['paths']);
$query = db_select('url_alias', 'u')
->fields('u');
$or = db_or();
$or->condition('alias', $regex, 'REGEXP');
$query->condition($or);
$query = $query->extend('PagerDefault')->limit(100);
$results = $query->execute();

$headers = array('URL alias');
$rows = array();
foreach ($results as $u) {
$rows[] = array($u->alias);
}
if (!empty($rows)) {
$output = theme('table', array('header' => $headers, 'rows' => $rows)) . theme('pager');
}

$form_state['rebuild'] = TRUE;
$form_state['scope'] = $output;
}

/**
* Custom function that gather the regex entered into one single expression.
*/
Expand All @@ -156,7 +114,6 @@ function nexteuropa_varnish_cache_purge_rule_type_selection($form, $form_state)
function _nexteuropa_varnish_paths_description() {
$regex_descriptions = array(
t('Add ^ at the begining of each path, unless you want to match using part of the path. <br>Example : ^content\/article\/(how-to-.*|faqs\/.*) will match <b>content/article/how-to-use-regex</b> and <b>content/article/faqs/using-regex</b> but not <b>my-content/article/how-to-use-regex</b>'),
t('You can test your site URLs matching the regex by clicking the <b>Check scope</b> button.'),
t('Regex validation is done at save. For example, if you try saving <b>*</b> alone, you will get an error.'),
);

Expand Down

0 comments on commit 2e6da06

Please sign in to comment.