Ejegg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/312441

Change subject: Remove obsolete and broken wmf_unsubscribe module
......................................................................

Remove obsolete and broken wmf_unsubscribe module

This is now handled by the FundraisingEmailUnsubscribe mediawiki
extension. And the manual unsubscribe page is silly - it's way
simpler to just go to the contact and set the opt out field.

Bug: T145419
Change-Id: Ic05ea768d2fb32457ce0f8c21e2a8b959edcaf04
---
D sites/all/modules/wmf_unsubscribe/import_unsubs.drush.inc
D sites/all/modules/wmf_unsubscribe/resources/unsubscribe.css
D sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-confirm.en.html
D sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-confirm.es.html
D sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-fail.en.html
D sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-fail.es.html
D sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-success.en.html
D sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-success.es.html
D sites/all/modules/wmf_unsubscribe/templates/unsubscribe-confirm.html
D sites/all/modules/wmf_unsubscribe/templates/unsubscribe-fail.html
D sites/all/modules/wmf_unsubscribe/templates/unsubscribe-success.html
D sites/all/modules/wmf_unsubscribe/unsub_make.drush.inc
D sites/all/modules/wmf_unsubscribe/wmf_unsubscribe.info
D sites/all/modules/wmf_unsubscribe/wmf_unsubscribe.module
M sites/default/enabled_modules
15 files changed, 0 insertions(+), 645 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/41/312441/1

diff --git a/sites/all/modules/wmf_unsubscribe/import_unsubs.drush.inc 
b/sites/all/modules/wmf_unsubscribe/import_unsubs.drush.inc
deleted file mode 100644
index c27b369..0000000
--- a/sites/all/modules/wmf_unsubscribe/import_unsubs.drush.inc
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-/**
- * @file import_unsubs.drush.inc
- *
- * Import unsubscribed email addresses into CiviCRM from a CSV
- *
- * @author Peter Gehres <pgeh...@wikimedia.org>
- */
-
-/**
- * Implementation of hook_drush_command()
- */
-function import_unsubs_drush_command() {
-       $items = array();
-
-       $items['import-unsubs'] = array(
-               'description' =>
-               'Import unsubscribed email addresses into CiviCRM from a CSV 
via a queue',
-               'examples' => array( 'drush import-unsubs filename.csv' ),
-//    'aliases' => array( 'ic' ),
-               'required-arguments' => true,
-               'arguments' => array(
-                       'file' => 'Name of CSV file to process'
-               )
-       );
-
-       return $items;
-}
-
-/**
- * Implementation of hook_drush_help()
- */
-function import_unsubs_drush_help( $section ) {
-       switch ( $section ) {
-               case 'drush:import-unsubs':
-                       return dt( "Import unsubscribed email addresses into 
CiviCRM from a CSV via a queue" );
-       }
-}
-
-/**
- *
- */
-function drush_import_unsubs() {
-       try{
-               $args = drush_get_arguments();
-               $filename = $args[1];
-
-               if( ( $file = fopen( $filename, 'r' )) === FALSE ){
-                       watchdog('wmf_unsubscribe', 'Import unsubs: Could not 
open file for reading: ' . $filename, array(), WATCHDOG_ERROR);
-                       return;
-               }
-
-               $headers = _load_headers( fgetcsv( $file, 0, ',', '"', '\\') );
-
-               while( ( $row = fgetcsv( $file, 0, ',', '"', '\\')) !== FALSE) {
-                       $form_state = array(
-                               'values' => array(
-                                       'email' => _get_value( "email", $row, 
$headers ),
-                               ),
-                       );
-
-                       wmf_unsubscribe_manual_form_submit( null, $form_state );
-               }
-
-       }
-       catch ( Exception $e ){
-               watchdog('wmf_unsubscribe', 'Import unsubs: Exception thrown 
during csv processing: ' . print_r( $e, true ), array(), WATCHDOG_ERROR);
-       }
-}
diff --git a/sites/all/modules/wmf_unsubscribe/resources/unsubscribe.css 
b/sites/all/modules/wmf_unsubscribe/resources/unsubscribe.css
deleted file mode 100755
index f222533..0000000
--- a/sites/all/modules/wmf_unsubscribe/resources/unsubscribe.css
+++ /dev/null
@@ -1,47 +0,0 @@
-#header-region,
-#wrapper,
-#wrapper #container,
-#wrapper #container #center,
-#wrapper #container #center #squeeze,
-.left-corner,
-.right-corner{
-    background: none !important;
-    background-image: none !important;
-    background-color: transparent !important;
-}
-
-#block-system-0,
-#header,
-#sidebar-left,
-#sidebar-right,
-.breadcrumb,
-.messages.error,
-.messages.status,
-h2{
-    display: none !important;
-}
-
-body{
-    background-color: #f3f3f3 !important;
-}
-
-#logo{
-    position: absolute;
-    top: 13px;
-    left: 15px;
-    width: 135px;
-    height: 135px;
-    background-image: 
url(//upload.wikimedia.org/wikipedia/foundation/9/9a/Wikimediafoundation-logo.png);
-}
-
-h2{
-    margin: 0 0 0 150px !important;
-}
-
-#unsub-body{
-    margin: 50px 0 0 175px !important;
-}
-
-.visible{
-    display: block !important;
-}
\ No newline at end of file
diff --git 
a/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-confirm.en.html 
b/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-confirm.en.html
deleted file mode 100644
index e918657..0000000
--- 
a/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-confirm.en.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<h2 class="visible">Wikimedia Foundation unsubscribe</h2>
-<div id="logo"></div>
-<div id="unsub-body">
-    <p id="unsub-text">Are you sure you want to unsubscribe <b>{{ 
contact.email }}</b>?</p>
-    <p id="unsub-warning">This will opt you out of e-mails from the Wikimedia 
Foundation sent to you as a donor. You may still receive e-mails to this e-mail 
address if it is associated with an account on one of our projects. If you have 
any questions, please contact <a 
href="mailto:donati...@wikimedia.org";>donati...@wikimedia.org</a>.</p>
-    <br />
-    <form id="unsub" method="post">
-        <input type="hidden" name="h" value="{{ hash }}">
-        <input type="hidden" name="c" value="{{ contribution_id }}">
-        <input type="submit" value="Unsubscribe">
-    </form>
-</div>
\ No newline at end of file
diff --git 
a/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-confirm.es.html 
b/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-confirm.es.html
deleted file mode 100644
index 5541945..0000000
--- 
a/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-confirm.es.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<h2 class="visible">Cancelar la subscripción a la Fundación Wikimedia</h2>
-<div id="logo"></div>
-<div id="unsub-body">
-    <p id="unsub-text">¿Está seguro de que desea cancelar la suscripción <b> 
{{ contact.email }} </b>?</p>
-    <p id="unsub-warning">Esto va a cancelar su suscripción de los e-mails que 
la Fundación Wikimedia le envia como donante. Todavía puede recibir mensajes en 
ese correo electrónico si esta dirección de correo electrónico está asociada 
con una cuenta en uno de nuestros proyectos. Si tienes alguna pregunta, póngase 
en contacto con <a 
href="mailto:donati...@wikimedia.org";>donati...@wikimedia.org</a>.</p>
-    <br />
-    <form id="unsub" method="post">
-        <input type="hidden" name="h" value="{{ hash }}">
-        <input type="hidden" name="c" value="{{ contribution_id }}">
-        <input type="submit" value="Cancelar la suscripción">
-    </form>
-</div>
\ No newline at end of file
diff --git 
a/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-fail.en.html 
b/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-fail.en.html
deleted file mode 100644
index afc74c0..0000000
--- a/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-fail.en.html
+++ /dev/null
@@ -1,5 +0,0 @@
-<h2 class="visible">Wikimedia Foundation unsubscribe</h2>
-<div id="logo"></div>
-<div id="unsub-body">
-    <p id="unsub-text">There was an error processing your request, please 
contact <a 
href="mailto:donati...@wikimedia.org";>donati...@wikimedia.org</a>.</p>
-</div>
\ No newline at end of file
diff --git 
a/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-fail.es.html 
b/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-fail.es.html
deleted file mode 100644
index 2a95a43..0000000
--- a/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-fail.es.html
+++ /dev/null
@@ -1,5 +0,0 @@
-<h2 class="visible">Cancelar la subscripción a la Fundación Wikimedia</h2>
-<div id="logo"></div>
-<div id="unsub-body">
-    <p id="unsub-text">Hubo un error al procesar su solicitud, póngase en 
contacto con <a 
href="mailto:donati...@wikimedia.org";>donati...@wikimedia.org</a>.</donati...@wikimedia.org></p>
-</div>
\ No newline at end of file
diff --git 
a/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-success.en.html 
b/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-success.en.html
deleted file mode 100644
index 0614297..0000000
--- 
a/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-success.en.html
+++ /dev/null
@@ -1,6 +0,0 @@
-<h2 class="visible">Wikimedia Foundation unsubscribe</h2>
-<div id="logo"></div>
-<div id="unsub-body">
-    <p id="unsub-text">You have successfully been removed from our mailing 
list</p>
-    <p id="unsub-warning">Please allow up to four (4) days for the changes to 
take effect. We apologize for any e-mails you receive during this time. If you 
have any questions, please contact <a 
href="mailto:donati...@wikimedia.org";>donati...@wikimedia.org</a></p>
-</div>
\ No newline at end of file
diff --git 
a/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-success.es.html 
b/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-success.es.html
deleted file mode 100644
index 14bcec5..0000000
--- 
a/sites/all/modules/wmf_unsubscribe/templates/i18n/unsubscribe-success.es.html
+++ /dev/null
@@ -1,6 +0,0 @@
-<h2 class="visible">Cancelar la subscripción a la Fundación Wikimedia</h2>
-<div id="logo"></div>
-<div id="unsub-body">
-    <p id="unsub-text">Has sido eliminado correctamente de nuestra lista de 
correo</p>
-    <p id="unsub-warning">Puede tardar hasta cuatro 4 días que los cambios 
surtan efecto. Nos disculpamos por los correos electrónicos que pueda recibir 
durante este tiempo. Si tiene alguna duda, póngase en contacto con <a 
href="mailto:donati...@wikimedia.org";>donati...@wikimedia.org</a></donati...@wikimedia.org></p>
-</div>
\ No newline at end of file
diff --git 
a/sites/all/modules/wmf_unsubscribe/templates/unsubscribe-confirm.html 
b/sites/all/modules/wmf_unsubscribe/templates/unsubscribe-confirm.html
deleted file mode 100755
index 4a160c4..0000000
--- a/sites/all/modules/wmf_unsubscribe/templates/unsubscribe-confirm.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<h2 class="visible">%donate_interface-email-unsub-title%</h2>
-<div id="logo"></div>
-<div id="unsub-body">
-    <p id="unsub-text">%donate_interface-email-unsub-confirm|{{ contact.email 
}}%</p>
-    <p id="unsub-warning">%donate_interface-email-unsub-warning%</p>
-    <br />
-    <form id="unsub" method="post">
-        <input type="hidden" name="h" value="{{ hash }}">
-        <input type="hidden" name="c" value="{{ contribution_id }}">
-        <input type="submit" value="%donate_interface-email-unsub-button%">
-    </form>
-</div>
\ No newline at end of file
diff --git a/sites/all/modules/wmf_unsubscribe/templates/unsubscribe-fail.html 
b/sites/all/modules/wmf_unsubscribe/templates/unsubscribe-fail.html
deleted file mode 100755
index c175505..0000000
--- a/sites/all/modules/wmf_unsubscribe/templates/unsubscribe-fail.html
+++ /dev/null
@@ -1,5 +0,0 @@
-<h2 class="visible">%donate_interface-email-unsub-title%</h2>
-<div id="logo"></div>
-<div id="unsub-body">
-    <p id="unsub-text">%donate_interface-email-unsub-fail%</p>
-</div>
\ No newline at end of file
diff --git 
a/sites/all/modules/wmf_unsubscribe/templates/unsubscribe-success.html 
b/sites/all/modules/wmf_unsubscribe/templates/unsubscribe-success.html
deleted file mode 100755
index 77c13f2..0000000
--- a/sites/all/modules/wmf_unsubscribe/templates/unsubscribe-success.html
+++ /dev/null
@@ -1,6 +0,0 @@
-<h2 class="visible">%donate_interface-email-unsub-title%</h2>
-<div id="logo"></div>
-<div id="unsub-body">
-    <p id="unsub-text">%donate_interface-email-unsub-success%</p>
-    <p id="unsub-warning">%donate_interface-email-unsub-delay%</p>
-</div>
\ No newline at end of file
diff --git a/sites/all/modules/wmf_unsubscribe/unsub_make.drush.inc 
b/sites/all/modules/wmf_unsubscribe/unsub_make.drush.inc
deleted file mode 100755
index 6b62f0d..0000000
--- a/sites/all/modules/wmf_unsubscribe/unsub_make.drush.inc
+++ /dev/null
@@ -1,123 +0,0 @@
-<?php
-/**
- * @file unsub_make.drush.inc
- *
- * Generates translated versions of the unsubscription pages from the i18n 
files.
- *
- * @author Peter Gehres <pgeh...@wikimedia.org>
- * @TODO print some useful info to STDOUT
- */
-
-use wmf_communication\MediaWikiMessages;
-use wmf_communication\Translation;
-
-/**
- * Implementation of hook_drush_command()
- */
-function unsub_make_drush_command() {
-    $items = array();
-
-    $items['unsub-make'] = array(
-        'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
-        'description' => 'Generates translated versions of the unsubscription 
pages from the i18n files',
-        'examples' => array(
-            'drush unsub-make' => '# Make translations',
-            'drush unsub-make --partial' => '# Make translations, including 
partially translated languages'
-        ),
-        'options' => array(
-            'partial' => 'allow translations where not all of the messages 
have translations'
-        ),
-    );
-
-    return $items;
-}
-
-/**
- * Implementation of hook_drush_help()
- *
- * @param $section
- * @return mixed
- */
-function unsub_make_drush_help( $section ) {
-    switch ( $section ) {
-        case 'drush:unsub-make':
-            return dt( "Generates translated versions of the unsubscription 
pages from the i18n files.\n\n" .
-            "This is NOT meant to be run in production.  It should be run 
locally and the results committed " .
-            "and code reviewed.");
-    }
-}
-
-/**
- * Generates translated versions of the unsubscribe pages from the
- * DonationInterface i18n files.
- */
-function drush_unsub_make() {
-    $partial = drush_get_option( 'partial', false );
-
-    $base_path = __DIR__ . '/';
-    $template_path = $base_path . 'templates/'; // TODO: ensure that this path 
exists
-    $output_path = $base_path . 'templates/i18n/'; // TODO: ensure that this 
path exists
-
-    $pages = array(
-        'unsubscribe-confirm',
-        'unsubscribe-fail',
-        'unsubscribe-success'
-    );
-    $messages = array(
-        'donate_interface-email-unsub-title',
-        'donate_interface-email-unsub-success',
-        'donate_interface-email-unsub-delay',
-        'donate_interface-email-unsub-confirm',
-        'donate_interface-email-unsub-warning',
-        'donate_interface-email-unsub-fail',
-        'donate_interface-email-unsub-button'
-    );
-
-    $DImsgs = MediaWikiMessages::getInstance();
-    $languages = $DImsgs->languageList();
-
-    foreach( $languages as $lang ){
-        if( $lang === "qqq" ){
-            continue;
-        }
-        echo "$lang -> ";
-        $msgCount = 0;
-        foreach( $messages as $m ){
-            if( $DImsgs->msgExists( $m, $lang ) ){
-                $msgCount++;
-            }
-        }
-        if( $msgCount == count( $messages ) || ( $msgCount > 0 && $partial ) ){
-            echo " fully translated\n";
-            foreach( $pages as $p ){
-                echo "\t writing $p ... ";
-                $page_str = file_get_contents( $template_path . "$p.html" );
-                $replaced = Translation::replace_messages( $page_str, $lang );
-
-                // the following is required to fix errors in the submission of
-                // messages for translation
-                $replaced = str_replace( "<donati...@wikimedia.org>", "<a 
href=\"mailto:donati...@wikimedia.org\";>donati...@wikimedia.org</a>", $replaced 
);
-
-                $outfile = fopen( $output_path . "$p.$lang.html", 'w' );
-                fwrite( $outfile, $replaced );
-                fclose( $outfile );
-                echo "done\n";
-            }
-        }
-        else{
-            echo " partial translation ... skipping\n";
-        }
-    }
-    $errors = drush_get_error_log();
-    if ( !empty( $errors ) ){
-           echo "\n***ERRORS***";
-           foreach( $errors as $error => $msgarray ){
-                   echo "\n$error: ";
-                   foreach( $msgarray as $count => $message ){
-                           echo "\n    $message";
-                   }
-           }
-           echo "\n\n";
-           exit( drush_get_error() );
-    }
-}
diff --git a/sites/all/modules/wmf_unsubscribe/wmf_unsubscribe.info 
b/sites/all/modules/wmf_unsubscribe/wmf_unsubscribe.info
deleted file mode 100755
index da7f97b..0000000
--- a/sites/all/modules/wmf_unsubscribe/wmf_unsubscribe.info
+++ /dev/null
@@ -1,6 +0,0 @@
-name = WMF Unsubscribe
-description = Unsubscription module for the Wikimedia Foundation
-core = 7.x
-package = Wikimedia
-dependencies[] = wmf_common
-dependencies[] = wmf_communication
diff --git a/sites/all/modules/wmf_unsubscribe/wmf_unsubscribe.module 
b/sites/all/modules/wmf_unsubscribe/wmf_unsubscribe.module
deleted file mode 100755
index 0745f1b..0000000
--- a/sites/all/modules/wmf_unsubscribe/wmf_unsubscribe.module
+++ /dev/null
@@ -1,330 +0,0 @@
-<?php
-
-use wmf_communication\Templating;
-
-/**
- * Implements hook_menu
- */
-function wmf_unsubscribe_menu() {
-    $items = array();
-
-    // this link should be left in place so that old links are
-    // still valid for some time, remove in 2013
-    $items['thank_you/unsubscribe'] = array(
-        'title' => 'Wikimedia Foundation Unsubscribe',
-        'access arguments' => array('unsubscribe'),
-        'page callback' => 'unsubscribe_page',
-        'type' => MENU_CALLBACK
-    );
-
-  /* Old code that should be removed but I dont want to excise it in case it 
breaks something
-    $items['wmf_unsubscribe/preview'] = array(
-        'title' => 'WMF Unsubscribe',
-        'access arguments' => array('unsubscribe'),
-        'page callback' => 'wmf_unsubscribe_preview',
-    );
-  */
-
-    $items['wmf_unsubscribe/manual'] = array(
-        'title' => 'WMF Manual Unsubscribe',
-        'access arguments' => array('manual unsubscribe'),
-        'page callback' => 'wmf_unsubscribe_manual',
-    );
-
-    return $items;
-}
-
-/**
- * Implements hook_permission
- */
-function wmf_unsubscribe_permission() {
-    return array(
-        'administer wmf modules' => array(
-            'title' => t('Administer WMF modules'),
-        ),
-        'unsubscribe' => array(
-            'title' => t('Unsubscribe self'),
-        ),
-        'manual unsubscribe' => array(
-            'title' => t('Unsubscribe donors'),
-        ),
-    );
-}
-
-/**
- * Renders the unsubscription process, checking to ensure that the request is 
valid.
- *
- * @return string the rendered output
- */
-function unsubscribe_page(){
-    require_once drupal_get_path( 'module', 'wmf_common' ) . 
'/civicrm_api_check.php';
-
-    drupal_add_css( drupal_get_path('module', 'wmf_unsubscribe') . 
'/resources/unsubscribe.css' );
-
-    $matches = array();
-    $contribution_id = "-1";
-    if( array_key_exists('c', $_REQUEST ) ){
-        $contribution_id = ( preg_match( '([a-zA-Z0-9]+)', $_REQUEST['c'], 
$matches ) == 1 ) ? $matches[0] : "";
-    }
-    $hash_get = "-1";
-    if( array_key_exists( 'h', $_REQUEST ) ){
-        $hash_get = ( preg_match( '([a-zA-Z0-9]+)', $_REQUEST['h'], $matches ) 
== 1 ) ? $matches[0] : "";
-    }
-    // set language to null, we will override this later based on 
preferred_language later
-    // if there is no language in the querystring
-    $language = NULL;
-    if( array_key_exists( 'uselang', $_REQUEST ) ){
-        $language = ( preg_match( '([a-zA-Z-]+)', $_REQUEST['uselang'], 
$matches ) == 1 ) ? $matches[0] : "en";
-    }
-
-    civicrm_initialize(TRUE);
-
-    $contribution = civicrm_api("Contribution","get", array (
-        'version' =>'3',
-        'contribution_id' => $contribution_id
-    ));
-
-    $params = array();
-
-    if( !WMFCiviAPICheck::check_api_result( $contribution, TRUE ) ){
-        watchdog('wmf_unsubscribe', 'Contribution API failed on unsubscribe 
request: ' . $contribution_id . '<pre>' . check_plain(print_r($contribution, 
TRUE)) . '</pre>', array(), WATCHDOG_ERROR);
-    }
-    if( !WMFCiviAPICheck::check_api_contribution( $contribution, 
$contribution_id, TRUE ) ){
-        // do not spam the logs with "contribution not found" DoS
-        return render_page( "unsubscribe-fail", $params, $language );
-
-    }
-    $contribution = WMFCiviAPICheck::check_api_simplify( $contribution, 
$contribution_id );
-
-    $contact = civicrm_api("Contact","get", array (
-        'version' =>'3',
-        'id' => $contribution[ 'contact_id' ],
-    ));
-
-    if( !WMFCiviAPICheck::check_api_result( $contact, TRUE ) ){
-        watchdog('wmf_unsubscribe', 'Contact API failed on unsubscribe 
request: ' . $contribution[ 'contact_id' ] . '<pre>' . 
check_plain(print_r($contact, TRUE)) . '</pre>', array(), WATCHDOG_ERROR);
-    }
-    if( !WMFCiviAPICheck::check_api_contact( $contact, $contribution[ 
'contact_id' ], TRUE ) ){
-        // do not spam the logs with "contact not found" DoS
-        return render_page( "unsubscribe-fail", $params, $language );
-    }
-    $contact = WMFCiviAPICheck::check_api_simplify( $contact, $contribution[ 
'contact_id' ] );
-
-    // check to see if the language was not set in the querystring
-    if( $language == NULL ){
-        // check to see if the contact record has a preferred language
-        if( array_key_exists( 'preferred_language', $contact ) ){
-            $locale = $contact['preferred_language'];
-            $language = substr($locale, 0, 2);
-        }
-        // if not, default back to english
-        else{
-            $language = "en";
-        }
-    }
-
-    // check to make sure that the hash for this unsubscribe attempt is valid
-    if( get_unsubscribe_hash( $contribution ) != $hash_get ){
-        // do not spam the logs with "invalid hash" messages
-        return render_page( "unsubscribe-fail", $params, $language );
-    }
-
-    $params["contribution_id"] = $contribution['id'];
-    $params["hash"] = $hash_get;
-    $params["contact"] = $contact;
-
-    // check to see if the user submitted the form
-    if( variable_get( 'thank_you_onestep_unsubscribe', 'false' ) == "true" || 
( isset( $_POST ) && !empty( $_POST ) ) ) {
-        // process the unsubscription
-        $contact = civicrm_api("Contact","update", array (
-            'version' =>'3',
-            'id' => $contribution[ 'contact_id' ],
-            'is_opt_out' => 1,
-        ));
-
-        if( WMFCiviAPICheck::check_api_contact( $contact ) ){
-            watchdog('wmf_unsubscribe', "Unsubscribe success for contact: %id, 
%display_name <%email>", array( "%id" => $params['contact']['id'], 
"%display_name" => $params['contact']['display_name'], "%email" => 
$params['contact']['email'] ), WATCHDOG_INFO);
-            return render_page( "unsubscribe-success", $params, $language );
-        } else {
-            watchdog('wmf_unsubscribe', "Unsubscribe FAILURE for contact (1): 
%id <%email>", array( "%id" => $params['contact']['id'], "%email" => 
$params['contact']['email'] ), WATCHDOG_INFO);
-            return render_page( "unsubscribe-fail", $params, $language );
-        }
-    } else {
-        // display the opt-out form
-        return render_page( "unsubscribe-confirm", $params, $language );
-    }
-}
-
-/**
- * Renders the specified page in the specified language, falling back
- * to English if a version of the page does not exist in the specified
- * language.
- *
- * @param string $page the name of the page to render
- * @param array $params any parameters needed to render the page
- * @param string $language the langauge in which to render the page
- * @return string the rendered page
- */
-function render_page( $page, $params=array(), $language='en' ){
-
-    $twig = Templating::twig_from_directory( __DIR__ . '/templates/i18n/' );
-
-    try{
-        $template = $twig->loadTemplate( "$page.$language.html" );
-    } catch ( Twig_Error_Loader $e ) {
-        try{
-            $template = $twig->loadTemplate( "$page.en.html" );
-        } catch ( Exception $e ){
-            // TODO: notify fr-tech that we have a problem
-            return "There was an error processing your request.  Please 
contact giv...@wikimedia.org.\n" . $e->getRawMessage();
-        }
-    }
-    return $template->render( $params );
-}
-
-/**
- * Returns a hash used to confirm that the user had a valid unsubscription
- * link and thus prevent brute force unsubscriptions
- *
- * @param $contribution array A CiviCRM Contribution API result
- */
-function get_unsubscribe_hash( $contribution ){
-    if( array_key_exists( 'id', $contribution ) &&
-        array_key_exists( 'contact_id', $contribution ) &&
-        array_key_exists( 'trxn_id', $contribution ) ){
-
-        return sha1( $contribution[ 'id' ] . $contribution[ 'contact_id' ] .
-            $contribution[ 'trxn_id' ] );
-    }
-
-    return FALSE;
-}
-
-/**
- * Displays a preview of the unsubscription page for a given language
- *
- * @return string html representing the rendered page
- */
-function wmf_unsubscribe_preview(){
-    drupal_add_css( drupal_get_path('module', 'wmf_unsubscribe') . 
'/resources/unsubscribe.css' );
-
-    $contribution_id = NULL;
-    $page = "unsubscribe-fail";
-    $language = "en";
-
-    if( array_key_exists('c', $_REQUEST ) ){
-        $contribution_id = ( preg_match( '([a-zA-Z0-9]+)', $_REQUEST['c'], 
$matches ) == 1 ) ? $matches[0] : NULL;
-    }
-    if( array_key_exists('page', $_REQUEST ) ){
-        $page = ( preg_match( '([a-zA-Z0-9-]+)', $_REQUEST['page'], $matches ) 
== 1 ) ? $matches[0] : "";
-    }
-    if( array_key_exists('uselang', $_REQUEST ) ){
-        $language = ( preg_match( '([a-zA-Z0-9-]+)', $_REQUEST['uselang'], 
$matches ) == 1 ) ? $matches[0] : "en";
-    }
-
-    return render_page( $page, array(), $language );
-}
-
-/* --- Manual Unsubscribe Functions --- */
-/**
- * Main form for manual unsubscribe -- wmf_unsubscribe/manual
- * @return Page content
- */
-function wmf_unsubscribe_manual() {
-  return drupal_get_form('wmf_unsubscribe_manual_form');
-}
-
-/**
- * Creates the form that wmf_unsubscribe_manual() uses. Allows unsubscribe of 
a contact manually. Callback
- * for drupal_get_form().
- */
-function wmf_unsubscribe_manual_form() {
-  $form = array();
-  $form['email'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Email Address'),
-    '#size' => 50,
-    '#maxlength' => 128,
-    '#description' => t('Email address of the contact to unsubscribe.'),
-  );
-  $form['submit'] = array('#type' => 'submit', '#value' => t('Unsubscribe'));
-  return $form;
-}
-
-/**
- * Processing callback for wmf_unsubscribe_manual_form. Will unsubscribe a 
contact manually.
- * @param $form
- * @param $form_state
- * @return bool
- */
-function wmf_unsubscribe_manual_form_submit($form, &$form_state) {
-  civicrm_initialize();
-  $email = $form_state['values']['email'];
-
-  // Search for the email contact
-  $emails = civicrm_api(
-    'Email', 'get',
-    array(
-      'version' => '3',
-      'email'   => $email,
-    )
-  );
-
-  $emailEncoded = json_encode($email);
-  if ($emails[ 'is_error' ] == TRUE) {
-    form_set_error("API search failed for email address: $emailEncoded " . 
json_encode($emails));
-  }
-
-  $tc = $emails[ 'count' ];
-  if ($tc === 0) {
-    drupal_set_message("No contacts in Civi for email $email");
-    return TRUE;
-  }
-
-  // We have a pile of contacts, whoo. Attempt injection into queue.
-  $count = 0;
-  try {
-    foreach ($emails[ 'values' ] as $id => $emailEntry) {
-      // Get the contribution ID
-      $contactId = $emailEntry['contact_id'];
-      $contributions = civicrm_api(
-        'Contribution', 'get',
-        array(
-          'version' => '3',
-          'contact_id' => $contactId,
-        )
-      );
-
-      // Check if the query failed
-      if (( $contributions[ 'is_error' ] == TRUE ) || ( $contributions[ 
'count' ] < 1 )) {
-        drupal_set_message("API contribution search failed for contact ID: 
$contactId " . json_encode($contributions));
-        continue;
-      }
-
-      // Retrieve the contribution id from the first array element
-      $ctid = array_keys($contributions['values']);
-      $ctid = $ctid[0];
-
-      // Contruct the STOMP message
-      $time = time();
-      $headers = array( 'correlation-id' => "manual-removal-{$time}-{$count}");
-      $body = array(
-        'process' => 'wmf-manual',
-        'contribution-id' => $ctid,
-        'email' => $email,
-      );
-
-      // Queue the message
-      if (!queue2civicrm_stomp()->enqueue( json_encode($body), $headers, 
"/queue/unsubscribe" )) {
-        drupal_set_message("Failed to queue unsubscribe message for 
contribution ID $ctid");
-        continue;
-      }
-
-      $count += 1;
-    }
-  } catch ( WmfException $ex ) {
-    drupal_set_message("API unsubscribe failed with " . $ex-getMessage());
-  }
-
-  drupal_set_message("Unsubscribed $email. ($count successful of $tc)");
-}
diff --git a/sites/default/enabled_modules b/sites/default/enabled_modules
index 6a8b308..533b1ba 100644
--- a/sites/default/enabled_modules
+++ b/sites/default/enabled_modules
@@ -33,5 +33,4 @@
 wmf_logging
 wmf_refund_qc
 wmf_reports
-wmf_unsubscribe
 wmf_unsubscribe_qc

-- 
To view, visit https://gerrit.wikimedia.org/r/312441
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic05ea768d2fb32457ce0f8c21e2a8b959edcaf04
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to