Skip to content
This repository has been archived by the owner on Jun 3, 2019. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into CD-43-header-footer
Browse files Browse the repository at this point in the history
* origin/develop:
  ES-141: Set initial value for high-water mark
  ES-141: Use high-water mark for locations
  ES-141: Use high-water mark
  Fix typo in reliefweb sync
  ES-141: CS
  ES-141: Check source field length, add logging
  OPS-4872: Add Maintenance 200 module
  • Loading branch information
rupl committed Aug 9, 2018
2 parents ea5a8c0 + 6fca300 commit d27330c
Show file tree
Hide file tree
Showing 11 changed files with 561 additions and 4 deletions.
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -36,6 +36,7 @@
"drupal/l10n_update": "^2.2",
"drupal/libraries": "^2.3",
"drupal/locale_translation_context": "^1.1",
"drupal/maintenance200": "^1.1",
"drupal/markdown": "^1.5",
"drupal/modernizr": "^3.11",
"drupal/moment": "^2.0",
Expand Down
339 changes: 339 additions & 0 deletions html/sites/all/modules/contrib/maintenance200/LICENSE.txt

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions html/sites/all/modules/contrib/maintenance200/README.txt
@@ -0,0 +1,24 @@
Maintenance 200 Module

Description
--------------
The Maintenance 200 module allows a site to return a Status code of 200 rather
than the default 503 (Service Unavailable) code. "But wait," you ask, "why
would I want that? The site is truly in a 503 state and should report that." The
reason you'd want to return a 200 is so that your CDN or caching layer (e.g., Varnish)
will cache the maintenance page and serve it to new requests rather than passing
the request down to your origin server.

Admittedly, this is kind of a double edge sword, since once the page is in cache
you'll have to flush your cache to bring the site back up, which may incur more origin
load that is spared by caching the maintenance page, but c'est la vie.

Installation
--------------
Just like any other Drupal module.

Configuration
-----------------
The module adds a set of radio buttons to the core Maintenance Mode form.
Simply select the desired HTTP status code and that value will be returned when
the site is in maintenance mode.
14 changes: 14 additions & 0 deletions html/sites/all/modules/contrib/maintenance200/maintenance200.info
@@ -0,0 +1,14 @@
name = "Maintenance 200"
description = "Allows the maintenance page to return a Status of 200 rather than the standard 503 code."
core = "7.x"

configure = admin/config/development/maintenance

files[] = maintenance200.test

; Information added by Drupal.org packaging script on 2015-03-08
version = "7.x-1.1"
core = "7.x"
project = "maintenance200"
datestamp = "1425773226"

@@ -0,0 +1,40 @@
<?php
/**
* @file
* Code for the Maintenance 200 module.
*/

/**
* Implements hook_preprocess_HOOK().
*
* Set the Status header to the selected code when the maintenance page
* is preprocessed.
*/
function maintenance200_preprocess_maintenance_page(&$vars) {
drupal_add_http_header('Status', variable_get('maintenance_mode_status', '200 OK'));
}

/**
* Implements hook_form_FORM_ID_alter().
*
* Add elements for setting the maintenance mode status code to the maintenance form.
*/
function maintenance200_form_system_site_maintenance_mode_alter(&$form, $form_state, $form_id) {
$form['maintenance_mode_status'] = array(
'#type' => 'radios',
'#title' => t('Maintenance mode response code'),
'#description' => t('This option controls what HTTP Status is returned when the site is in maintenance mode. 503 is the Drupal default.'),
'#default_value' => variable_get('maintenance_mode_status', '200 OK'),
'#options' => array(
'200 OK' => '200 OK',
'500 Internal Server Error' => '500 Internal Server Error',
'501 Not Implemented' => '501 Not Implemented',
'502 Bad Gateway' => '502 Bad Gateway',
'503 Service Unavailable' => '503 Service Unavailable',
'504 Gateway Time-out' => '504 Gateway Time-out',
),
);

// Drive the maintenance_mode_message input down below the status input.
$form['maintenance_mode_message']['#weight'] = 1;
}
39 changes: 39 additions & 0 deletions html/sites/all/modules/contrib/maintenance200/maintenance200.test
@@ -0,0 +1,39 @@
<?php
/**
* @file
*
* Tests functionality of the Maintenance 200 module.
*/

/**
* Tests functionality of the Maintenance 200 module.
*/
class Maintenance200TestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Maintenance 200',
'description' => 'Ensure that the Maintenance 200 module returns the selected HTTP Status when maintenance mode is enabled.',
'group' => 'Maintenance 200',
);
}

public function setUp() {
// Enable the Maintenance 200 module.
parent::setUp('maintenance200');

// Login as an admin user.
$admin = $this->drupalCreateUser(array('administer site configuration'));
$this->drupalLogin($admin);

// Put the site into mainenance mode and set the status to 200.
$form = array();
$form['maintenance_mode'] = 1;
$this->drupalPost('admin/config/development/maintenance', $form, t('Save configuration'));
}

public function testMaintenance200Status() {
$this->assertTrue(variable_get('maintenance_mode', FALSE), 'Site is in maintenance mode.');
$this->drupalGet('');
$this->assertResponse(200, 'Site returns a 200 Status code.');
}
}
Expand Up @@ -28,6 +28,7 @@ function ev_migrate_events_from_hrinfo() {
$url .= '/' . $page;
$url .= '/' . $timestamp;
$url .= '/' . $hash;
$url .= '/' . variable_get('ev_migrate_highwater_mark_hrinfo', 0);

// Get data.
$request = drupal_http_request($url);
Expand All @@ -50,9 +51,13 @@ function ev_migrate_events_from_hrinfo() {

return;
}
else {
_ev_migrate_send_chat_message_line('No more events to import, sleeping for a while', array('hrinfo'));
}
}

variable_set('ev_migrate_stop_processing_hrinfo', TRUE);
variable_set('ev_migrate_highwater_mark_hrinfo', REQUEST_TIME);
};

/**
Expand Down Expand Up @@ -157,6 +162,10 @@ function ev_migrate_process_row_from_hrinfo($row, $prefix = '') {
$event->field_event_source_updated[LANGUAGE_NONE][0]['value'] = $row['changed'];
$event->changed = $row['changed'];

if (strlen($row['url']) > 255) {
$parsed_url = parse_url($row['url']);
$row['url'] = $parsed_url['scheme'] . '://' . $parsed_url['host'] . '/node/' . $row['nid'];
}
$needs_update = $needs_update || !isset($event->field_event_source_url[LANGUAGE_NONE][0]['value']) || $event->field_event_source_url[LANGUAGE_NONE][0]['value'] != $row['url'];
$event->field_event_source_url[LANGUAGE_NONE][0]['value'] = $row['url'];

Expand Down
70 changes: 67 additions & 3 deletions html/sites/all/modules/custom/ev_migrate/ev_migrate.module
Expand Up @@ -57,12 +57,24 @@ function _ev_migrate_events_from_reliefweb() {
$data = _ev_migrate_reliefweb_fetch($limit, $offset);
if (!empty($data)) {
foreach ($data as $row) {
ev_migrate_process_row_reliefweb($row, 'reliefweb-');
try {
ev_migrate_process_row_reliefweb($row, 'reliefweb-');
}
catch (PDOException $e) {
_ev_migrate_send_chat_message_line('Unexpected database error::' . $e->getMessage(), array('reliefweb', 'error'));
return;
}
catch (Exception $e) {
_ev_migrate_send_chat_message_line('Unexpected error::' . $e->getMessage(), array('reliefweb', 'error'));
return;
}

}
$page++;
variable_set('ev_migrate_page_reliefweb', $page++);
}
else {
_ev_migrate_send_chat_message_line('No more events to import, sleeping for a while', array('reliefweb'));
variable_set('ev_migrate_stop_processing_reliefweb', TRUE);
}
}
Expand All @@ -74,7 +86,7 @@ function _ev_migrate_events_from_reliefweb() {
taxonomy_term_save($source_term);
}

variable_set('ev_migrate_last_run_hrinfo', REQUEST_TIME);
variable_set('ev_migrate_last_run_reliefweb', REQUEST_TIME);
}

/**
Expand All @@ -99,7 +111,17 @@ function _ev_migrate_events_from_hrinfo() {

// Migrate n batches.
for ($i = 0; $i < variable_get('ev_migrate_num_of_runs', 10); $i++) {
ev_migrate_events_from_hrinfo();
try {
ev_migrate_events_from_hrinfo();
}
catch (PDOException $e) {
_ev_migrate_send_chat_message_line('Unexpected database error::' . $e->getMessage(), array('hrinfo', 'error'));
return;
}
catch (Exception $e) {
_ev_migrate_send_chat_message_line('Unexpected error::' . $e->getMessage(), array('hrinfo', 'error'));
return;
}
}

variable_set('ev_migrate_last_run_hrinfo', REQUEST_TIME);
Expand Down Expand Up @@ -244,3 +266,45 @@ function _ev_migrate_system_retrieve_file($url, $destination = NULL, $managed =

return $local;
}

/**
* Send message to chat.
*/
function _ev_migrate_send_chat_message($message_lines, $tags = array()) {
if (!variable_get('ev_migrate_chat_send_enabled', FALSE)) {
return;
}

if (empty(variable_get('ev_migrate_chat_url', ''))) {
return;
}

$tags[] = 'events';

$message = implode("\n", $message_lines);
$url = variable_get('ev_migrate_chat_url', '');
$data = array(
'event' => 'message',
'content' => $message,
'tags' => $tags,
);

$options = array(
'method' => 'POST',
'data' => json_encode($data),
'timeout' => 15,
'headers' => array(
'Content-Type' => 'application/json',
'Accept' => 'application/json',
),
);

drupal_http_request($url, $options);
}

/**
* Send single line to chat.
*/
function _ev_migrate_send_chat_message_line($line, $tags = array()) {
_ev_migrate_send_chat_message(array($line), $tags);
}
Expand Up @@ -100,6 +100,10 @@ function ev_migrate_process_row_reliefweb($row, $prefix = '') {
$event->field_event_source_updated[LANGUAGE_NONE][0]['value'] = strtotime($row['fields']['date']['changed']);
$event->changed = strtotime($row['fields']['date']['changed']);

if (strlen($row['fields']['url']) > 255) {
$parsed_url = parse_url($row['fields']['url']);
$row['fields']['url'] = $parsed_url['scheme'] . '://' . $parsed_url['host'] . '/node/' . $row['nid'];
}
$needs_update = $needs_update || !isset($event->field_event_source_url[LANGUAGE_NONE][0]['value']) || $event->field_event_source_url[LANGUAGE_NONE][0]['value'] != $row['fields']['url'];
$event->field_event_source_url[LANGUAGE_NONE][0]['value'] = $row['fields']['url'];

Expand Down
Expand Up @@ -85,8 +85,25 @@ function events_config_update_7009() {
}

/**
* Enable Modernizr.
* Enable Maintenance 200.
*/
function events_config_update_7010() {
module_enable(array('maintenance200'));

variable_set('maintenance_mode_status', '203 Non-Authoritative Information');
}

/**
* Set initial values for high-water mark.
*/
function events_config_update_7011() {
variable_set('ev_migrate_highwater_mark_hrinfo', REQUEST_TIME - 30 * 86400);
variable_set('ev_migrate_highwater_mark_hrinfo_locations', REQUEST_TIME - 30 * 86400);
}

/**
* Enable Modernizr.
*/
function events_config_update_7012() {
module_enable(array('modernizr'));
}
Expand Up @@ -578,6 +578,7 @@ function events_config_fetch_and_sync_locations() {
cache_clear_all('events_event:locations', 'cache');
cache_clear_all('events_event:edit-locations', 'cache');
variable_set('events_config_fetch_and_sync_locations_last_run', REQUEST_TIME);
variable_set('ev_migrate_highwater_mark_hrinfo_locations', REQUEST_TIME);
}
}

Expand All @@ -590,6 +591,11 @@ function events_config_fetch_and_sync_locations_endpoint($endpoint, $parent_need

while (TRUE) {
$fetch_url = $url . '&page=' . $page;

// Add high-water mark.
$fetch_url .= '&filter[changed][value]=' . variable_get('ev_migrate_highwater_mark_hrinfo_locations', 0) . '&filter[changed][operator]=>';
$fetch_url .= '&sort=changed,id';

_events_config_log('Fetching ' . $fetch_url);
$request = drupal_http_request($fetch_url);
if (isset($request->data)) {
Expand Down

0 comments on commit d27330c

Please sign in to comment.