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

Commit

Permalink
Preparing to release petitions-7.x-3.0-alpha1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Rose committed Jun 22, 2015
1 parent af3aa17 commit 1a4ccb0
Show file tree
Hide file tree
Showing 138 changed files with 12,779 additions and 4,204 deletions.
96 changes: 2 additions & 94 deletions ABOUT-7.x-3.x.md
Original file line number Diff line number Diff line change
@@ -1,98 +1,6 @@
The 7.x-3.x branch of petitions aims to remove the application's dependency on
Mongo DB and run on MySQL. Between now and whenever 7.x-3.0 is released this
branch will be building out and refining a proof-of-concept for what will likely
turn out to be mysql-based petition nodes and signature entities.
Mongo DB and run on MySQL.

For a stable Mongo-based petitions application, please use the 7.x-2.x branch.


Technical notes on phasing out Mongo dependencies
-------------------------------------------------

Modules to be removed by the code base by 7.x-3.0 (more modules may get added
to this list):
- wh_petitions
- petitions_data

Any new code added to the 7.x-3.x branch is being written in anticipation of
mongo storage being turned off, and petition nodes and signature_mail entities
based on a mysql back end. Here are some examples of how we're keeping things
organized in anticipation of mongo going away:

### Example #1: Keeping things organized in mymodule.mongo2mysql.inc

Store functions that are intended to be deleted when mongo gets shut off in
mymodule.mongo2mysql.inc.

Name any new functions created in *.mongo2mysql.inc with mongo2mysql in the
function name. This way, when it's time to shut mongo off, all we have to do
is (1) find any files with mongo2mysql in the name and delete them, then (2)
grep through the code for mongo2mysql, and remove those function calls.


### Example #2: Calling mongo-dependent functions and checking related shunt trips

While we're in transition phasing mongo out, application functionality
should be decoupled from a specific storage backend as much as possible.
If myslq-based data is available, it's authoritiative. But don't assume it's
available. If mysql-based data is NOT available, try getting mongo-based
data. But don't assume that's available either. Eventually it will get shut
off. For example:

```php

function mymodule_does_something_with_petitions() {

// Load a petition.

// First try mysql (petition nodes).
$petition_is_enabled = module_exists('petition');
$mysql_shunt_is_tripped = shunt_is_enabled('petition_mysql_save');
if ($petition_is_enabled && !$mysql_shunt_is_tripped) {
$petition = node_load($nid);
}

// *******************************************************************
// * Note: This entire block of code can simply be deleted after *
// * mysql is "turned on" and mongo is turned off. *
// *******************************************************************
//
// If mysql data isn't available or we need to do something with mongo
// data for some reason, get it from mongo like this.
$mongo_shunt_is_tripped = shunt_is_enabled('wh_petitions_petition_create');
if (!$mongo_shunt_is_tripped) {
$petition_from_mongo = petitions_data_mongo2mysql_get_petition($mongo_petition_id);
}
// Format petition data like a petition node, reconcile the two
// different petition objects, or throw watchdog errors.
$petition = mymodule_mongo2mysql_transitional_reconciling_and_formatting_happens_here($petition, $petition2);

// Now proceed to do stuff with your $petition node (or node-like
// object)...

}

```

For a more complex real-world example of ^^ this, see signatures_queue/includes/process_signatures.inc.


### Example #3: Phasing out mongo-dependent functions.

To phase out mongo-dependent functions or anything else that's meant to be removed:
- Move functions intended to be removed into example.mongo2myql.inc files
- Rename functions like this: example_get_example() -> example_mongo2mysql_get_example()
- Replace calls to example_get_example() throughout the codebase with example_mongo2mysql_get_example()
- In example.mongo2mysql.inc provide the legacy function, but throw an error explaining what's going on

See petitions_data_get_petition and petitions_data_mongo2mysql_get_petition
as an example here:
https://github.com/bryanhirsch/_petitions/commit/453e2f96793e9ce8a95edbc325497bfebd298942

Note: Lines like this [here](https://github.com/bryanhirsch/_petitions/commit/453e2f96793e9ce8a95edbc325497bfebd298942#diff-325f9f5d1e9e226e082ddc1c205b536eR47)
are NOT safe and future proofed as described in example #2.
Developers/Contributors, wherever possible, please code defensively and
write things like #2 along the way so there's less housekeeping to do when it's time to grep for things like
[this](https://github.com/bryanhirsch/_petitions/commit/453e2f96793e9ce8a95edbc325497bfebd298942#diff-325f9f5d1e9e226e082ddc1c205b536eR47)
and replace it with its mysql equivalents.

This document has been moved to an internal doc. Please contact us through the github issue queue to get involved: github.com/Whitehouse/petitions .
60 changes: 11 additions & 49 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,22 @@ INSTALL.md
**Contents**

* "Alpha" software status
* Install MongoDB for local development
* Installing and configuring Petitions
* Manual Rules import
* MongoDB configuration in settings.php


"Alpha" software status
--------------------------------

"Alpha" means we cannot promise to provide an upgrade path to users who build sites on the current code base.

Later releases will remove this application's dependence on MongoDB. Our intention is to evolve this code base into an install profile that others can easily reuse, extend and contribute to. This is not the state of the current application, which was made specifically for the White House's particular use cases and hosting environment.
Our intention is to evolve this code base into an install profile that others can easily reuse, extend and contribute to. This is not the state of the current application, which was made specifically for the White House's particular use cases and hosting environment.

These instructions will help you install Drupal, get Drupal talking to MySQL and MongoDB, and let you try out the existing code base.
These instructions will help you install Drupal, get Drupal talking to MySQL, and let you try out the existing code base.

Where the application still has dependencies on configuration stored in the site's database, these are areas where the install profile remains a work in progress. We will release improvements as we make them on GitHub. In the meanwhile, patches are welcome too.


Install MongoDB for local development
-------------------------------------

For local development on Mac OSX with MAMP (similar with XAMPP), install Homebrew, then do this:

```
$ brew versions mongo
$ cd /usr/local/Cellar
$ git checkout dae14ec /usr/local/Library/Formula/mongodb.rb
$ brew install mongo
$ /Applications/MAMP/bin/php/php5.3.6/bin/pecl install mongo
$ mkdir /data/db
$ mongod # This starts mongo.
$ mongo # This starts the mongo client.
```
At times the application may encounter issues due to expecting a MongoDB connection. These issues are artifacts of the previous architecture of the application, and the plan is to remove them in future releases.


Installing and configuring Petitions
Expand All @@ -57,34 +39,6 @@ drush -y make --no-core --contrib-destination=. drupal-org.make

5) Follow the normal Drupal installation process. When prompted to select
a profile, select "Petitions." Drupal will rewrite your settings.php file.
After it does, you will be prompted to add a snippet like this to the end
of settings.php. Do this before you visit your site, otherwise Drupal will
be unhappy:

```php
// Set mongo configuration
$mongo_host = '127.0.0.1';
$mongo_db_name = 'petition';
$conf['mongodb_connections'] = array(
'default' => array('host' => $mongo_host, 'db' => $mongo_db_name),
'petition_tool' => array('host' => $mongo_host, 'db' => $mongo_db_name),
'petition_tool_archive' => array('host' => $mongo_host, 'db' => $mongo_db_name),
'petition_tool_response' => array('host' => $mongo_host, 'db' => $mongo_db_name),
'petition_tool_signatures' => array('host' => $mongo_host, 'db' => $mongo_db_name),
);
$conf['mongodb_collections'] = array(
'petitions' => 'petition_tool',
'archive_petitions' => 'petition_tool_archive',
'petition_response' => 'petition_tool_response',
'petition_signatures' => 'petition_tool_signatures',
);

# (Optional):
# $conf['mongodb_options'] = array(
# 'replicaSet' => 'petitions',
# 'timeout' => 1,
# );
```

6) **IMPORTANT!** Configure second database for signature processing:

Expand Down Expand Up @@ -297,3 +251,11 @@ Import the user_submit rule here (check "Overwrite"):
// "white screen of death" (WSOD) pages.
ini_set('display_startup_errors', TRUE);
```

13) The simplified signing functionality requires 4 cron jobs to be configured:
* initiate_signature_validation
* preprocess_signatures
* process_signatures
* archive_signatures

These jobs can be executed via drush by using the `signatures-queue-invoke-workflow` command.
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Drupal 7 code base used to build an application that lets users create and sign petitions.

This application is under active development and will continue to be modified and improved over time. The current release is an "alpha" pending changes that will remove its dependency on MongoDB (see “Roadmap” section below).
This application is under active development and will continue to be modified and improved over time. The current release is an "alpha".

## Goals

Expand All @@ -18,13 +18,12 @@ Releasing the source code for this application is meant to empower other governm

* Drupal 7.x
* MySQL 5.x
* MongoDB 2.2.4
* PHP 5.2 or 5.3

*Recommended:*

* RAM +512 M
* Dedicated MongoDB server (this dependency will be removed soon, see “Roadmap”)
* Dedicated Solr server

## Usage

Expand All @@ -36,6 +35,8 @@ For installation instructions, see INSTALL.md.

NOTE: Setting up the application and configuring it for use in your organization’s context requires Drupal development experience. The application ships with a similar design (theme) to what is used on petitions.whitehouse.gov and needs to be customized for use by others using standard Drupal 7 themeing conventions. The application also ships with various user interface elements, user account settings, and other configurations that users should expect to customize using standard Drupal 7 techniques and conventions.

Keys for the write API are issued, validated, and rate limited by a third-party service.

## Roadmap

Have an idea or question about future features for We the People? Let us know by opening a ticket on GitHub, emailing us directly at [email protected], or tweeting @WHWeb.
Expand All @@ -44,12 +45,6 @@ We the People is a work in progress and currently exists at a very basic level o

The following descriptions are for informational purposes only and should not be interpreted as commitments or guarantees of future code releases in any way.

*Move from MongoDB to MySQL*

The current release depends on MongoDB. When we first created the application, we wanted to make sure we had a highly scalable application and database to meet our anticipated performance needs under high loads. We have been running MongoDB in production for over a year, but we have decided that the performance benefits it provides are outweighed by the complexity of trying to extend Drupal features backed by MongoDB.

We are currently moving to a fully MySQL-backed application to increase the speed the development of new features and other aspects of maintaining the Drupal application. Our next release will be a dev branch that will be fully backed by MySQL, and once there is a tag for that branch, we will no longer maintain the MongoDB branch.

*Install Profile*

The codebase is released as-is and currently supports a specific, standalone website. In the future we would like to provide an install profile that supports a wider range of applications.
Expand Down
7 changes: 1 addition & 6 deletions build-petitions.make
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ core = 7.x
; @see http://drupal.org/node/972536
;
; --------------------------------------
projects[drupal][version] = 7.32
projects[drupal][version] = 7.35
projects[drupal][patch][] = http://drupal.org/files/drupal-menu-int-972536-83-D7.patch

; Patch correcting database switching within a Simpletest run.
; @see https://drupal.org/node/2155023
; -------------------------------
projects[drupal][patch][] = https://drupal.org/files/issues/drupal-insertassert_exception-2155023-3.patch

; Petitions installation profile
; -------------------------------
projects[petitions][type] = profile
Expand Down
26 changes: 24 additions & 2 deletions drupal-org.make
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,29 @@ defaults[projects][subdir] = contrib

projects[advanced_help][version] = 1.0

projects[apachesolr][version] = 1.7
projects[apachesolr][patch][1764352-2] = https://www.drupal.org/files/issues/decouple_cron-1764352-2.patch
projects[apachesolr][patch][2457953] = https://www.drupal.org/files/issues/apachesolr-slow_queries_reindex-10.patch
projects[apachesolr][patch][2459461] = https://www.drupal.org/files/issues/apache_solr_profiling-2459461-5.patch
projects[apachesolr][patch][2476229] = https://www.drupal.org/files/issues/apachesolr-solr_clear_batch-2476229-1.patch

projects[captcha][version] = 1.0

projects[conditional_styles][version] = 2.1

projects[context][version] = 3.1
projects[context][version] = 3.6

projects[ctools][version] = 1.4

projects[date][version] = 2.6

projects[diff][version] = 3.2

projects[efq_extra_field][download][type] = git
projects[efq_extra_field][download][url] = http://git.drupal.org/project/efq_extra_field.git
projects[efq_extra_field][download][revision] = c81036076d3818afb8fd16041b00bf6dabf0b6b1
projects[efq_extra_field][patch][2399063-1] = https://www.drupal.org/files/issues/efq_extra_field-move_class_to_include-2399063-1.patch

projects[email_confirm][version] = 1.1

projects[entity][version] = 1.2
Expand Down Expand Up @@ -111,14 +122,22 @@ projects[textcaptcha][patch][2279207-1] = https://drupal.org/files/issues/textca

projects[token][version] = 1.5

projects[views][version] = 3.7
projects[transliteration][version] = 3.2

projects[views][version] = 3.11

projects[views_infinite_scroll][version] = 1.1
; Apply patch from https://www.drupal.org/node/1199794 to eliminate count query from infinite scroller for performance
projects[views_infinite_scroll][patch][1199794] = https://www.drupal.org/files/issues/infinite_scroll_no_count.patch

projects[views_bulk_operations][version] = 3.1

projects[views_data_export][version] = 3.0-beta8

projects[wysiwyg][version] = 2.2

projects[usfedgov_google_analytics][version] = 1.0-rc1

; Contrib Themes
; ==============================================================================

Expand Down Expand Up @@ -159,3 +178,6 @@ libraries[petitions-php-sdk][download][revision] = fe03d49e39e88e87cff2295172d02
libraries[spyc][download][type] = file
libraries[spyc][download][url] = https://raw.github.com/mustangostang/spyc/79f61969f63ee77e0d9460bc254a27a671b445f3/spyc.php
libraries[spyc][download][filename] = spyc.php

libraries[fed_analytics][download][type] = get
libraries[fed_analytics][download][url] = https://github.com/GSA/DAP-Gov-wide-GA-Code/archive/1785a8c79cb991ef4efd1a8ee6b7c3d66647119f.zip
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private function getPetitionDummyData() {
$data['field_petition_featured'] = $faker->randomNumber(0, 1);
$data['field_petition_hidden'] = 0;
$data['field_petition_status'] = WH_PETITION_STATUS_PUBLIC;
$data['field_petition_response_status'] = WH_PETITION_RESPONSE_STATUS_UNANSWERED;
$data['field_response_status'] = WH_PETITION_RESPONSE_STATUS_UNANSWERED;
$data['field_petition_review_timeframe'] = $review_timeframe;

return $data;
Expand Down Expand Up @@ -286,7 +286,7 @@ private function saveMongoPetition($data) {
'private_tags' => array(),
'related_petitions' => array(),
'petition_status' => $data['field_petition_status'],
'response_status' => $data['field_petition_response_status'],
'response_status' => $data['field_response_status'],
'published' => $data['field_timestamp_published'],
'reached_public' => $data['field_timestamp_reached_public'],
'reached_ready' => $data['field_timestamp_reached_ready'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* @file
* Drush script to be run one time only. Creates two-way links between response
* nodes and petition nodes after complete mongo2mysql migration is complete.
* Only to be run on sites utilizing MySQL.
*
* Instructions on when to use this file can be found in:
* - /README/PT-1532-migration-release-instructions.txt
*/

#!/usr/bin/env drush

// Select all links from petitions to responses.
$query = db_query("SELECT 'node' as entity_type, r.type as bundle, 0 as deleted, r.nid as entity_id, r.vid as revision_id, r.language as language, p.entity_id as field_petition_id_target_id
FROM node r
INNER JOIN field_data_field_response_id p ON p.field_response_id_target_id=r.nid
WHERE type='wh_response'");

// Create corresponding links from responses to petitions.
$deltas = array();
foreach ($query as $result) {
if (!isset($deltas[$result->entity_id])) {
$deltas[$result->entity_id] = 0;
}
else {
$deltas[$result->entity_id]++;
}
db_query("INSERT IGNORE INTO field_data_field_petition_id (entity_type, bundle, deleted, entity_id, revision_id, language, delta, field_petition_id_target_id) VALUES (:entity_type, :bundle, :deleted, :entity_id, :revision_id, :language, :delta, :field_petition_id_target_id)",
array(
':entity_type' => $result->entity_type,
':bundle' => $result->bundle,
':deleted' => $result->deleted,
':entity_id' => $result->entity_id,
':revision_id' => $result->revision_id,
':language' => $result->language,
':delta' => $deltas[$result->entity_id],
':field_petition_id_target_id' => $result->field_petition_id_target_id,
));
db_query("INSERT IGNORE INTO field_revision_field_petition_id (entity_type, bundle, deleted, entity_id, revision_id, language, delta, field_petition_id_target_id) VALUES (:entity_type, :bundle, :deleted, :entity_id, :revision_id, :language, :delta, :field_petition_id_target_id)",
array(
':entity_type' => $result->entity_type,
':bundle' => $result->bundle,
':deleted' => $result->deleted,
':entity_id' => $result->entity_id,
':revision_id' => $result->revision_id,
':language' => $result->language,
':delta' => $deltas[$result->entity_id],
':field_petition_id_target_id' => $result->field_petition_id_target_id,
));
}
Loading

0 comments on commit 1a4ccb0

Please sign in to comment.