Skip to content
This repository was archived by the owner on Oct 29, 2020. It is now read-only.

Commit 24b941d

Browse files
committed
Revert "Reportback"
1 parent 542b97b commit 24b941d

File tree

7 files changed

+42
-81
lines changed

7 files changed

+42
-81
lines changed

lib/modules/dosomething/dosomething_api/resources/reportback_item_resource.inc

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,6 @@ function _reportback_item_resource_definition() {
7575
'source' => array('param' => 'page'),
7676
'default value' => 1,
7777
),
78-
array(
79-
'name' => 'load_user',
80-
'description' => 'Flag to indicate whether to make call to northstar to retrieve full user data.',
81-
'optional' => TRUE,
82-
'type' => 'boolean',
83-
'source' => array('param' => 'load_user'),
84-
'default value' => FALSE,
85-
),
8678
),
8779
'access callback' => '_reportback_item_resource_access',
8880
'access arguments' => array('index'),
@@ -116,14 +108,13 @@ function _reportback_item_resource_access($op) {
116108
}
117109

118110

119-
function _reportback_item_resource_index($campaigns, $status, $count, $random, $page, $load_user) {
111+
function _reportback_item_resource_index($campaigns, $status, $count, $random, $page) {
120112
$parameters = array(
121113
'campaigns' => $campaigns,
122114
'status' => $status,
123115
'count' => $count,
124116
'random' => $random,
125117
'page' => $page,
126-
'load_user' => $load_user,
127118
);
128119

129120
$reportbackItems = new ReportbackItemTransformer;

lib/modules/dosomething/dosomething_api/resources/reportback_resource.inc

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,6 @@ function _reportback_resource_definition() {
7575
'source' => array('param' => 'page'),
7676
'default value' => 1,
7777
),
78-
array(
79-
'name' => 'load_user',
80-
'description' => 'Flag to indicate whether to make call to northstar to retrieve full user data.',
81-
'optional' => TRUE,
82-
'type' => 'boolean',
83-
'source' => array('param' => 'load_user'),
84-
'default value' => FALSE,
85-
),
8678
),
8779
'access callback' => '_reportback_resource_access',
8880
'access arguments' => array('index'),
@@ -116,14 +108,13 @@ function _reportback_resource_access($op) {
116108
}
117109

118110

119-
function _reportback_resource_index($campaigns, $status, $count, $random, $page, $load_user) {
111+
function _reportback_resource_index($campaigns, $status, $count, $random, $page) {
120112
$parameters = array(
121113
'campaigns' => $campaigns,
122114
'status' => $status,
123115
'count' => $count,
124116
'random' => $random,
125117
'page' => $page,
126-
'load_user' => $load_user,
127118
);
128119

129120
$reportbacks = new ReportbackTransformer;

lib/modules/dosomething/dosomething_northstar/dosomething_northstar.module

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,31 +128,20 @@ function dosomething_northstar_update_user($form_state) {
128128
}
129129

130130
/**
131-
* Get user data from northstar.
132-
*
133-
* @param int $id Drupal user id.
134-
* @return object
131+
*Get user data from northstar.
135132
*/
136133
function dosomething_northstar_get_northstar_user($id) {
137-
$northstar_user_info = cache_get('northstar_user_info_' . $id, 'cache_northstar_user_info');
138-
$northstar_user_info = $northstar_user_info->data;
139-
140-
if (empty($northstar_user_info)) {
134+
if (!empty($northstar_user_info)) {
135+
$northstar_user_info = cache_get('northstar_user_info_' . $id, 'cache_northstar_user_info');
136+
} else {
141137
$client = _dosomething_northstar_build_http_client();
142138

143139
$northstar_user_info = drupal_http_request($client['base_url'] . '/users/drupal_id/' . $id, array(
144-
'headers' => $client['headers'],
145-
'method' => 'GET',
146-
));
147-
148-
$northstar_user_info = $northstar_user_info->data;
149-
150-
if (!empty($northstar_user_info->error)) {
151-
$error = sprintf("Error fetching Northstar user data, uid=%d: '%s'", $id, $northstar_user_info->error);
152-
watchdog_exception('northstar', new Exception($error));
153-
} else {
154-
cache_set('northstar_user_info_' . $id, $northstar_user_info, 'cache_northstar_user_info', REQUEST_TIME + 60*60*24);
155-
}
140+
'headers' => $client['headers'],
141+
'method' => 'GET',
142+
));
143+
144+
cache_set('northstar_user_info_' . $id, $northstar_user_info, 'cache_northstar_user_info', REQUEST_TIME + 60*60*24);
156145
}
157146

158147
return $northstar_user_info;

lib/modules/dosomething/dosomething_reportback/includes/Reportback.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ public static function find(array $filters = []) {
123123

124124
foreach($results as $item) {
125125
// @TODO: remove need for passing variable for constructor check.
126-
$load_user = dosomething_helpers_isset($filters['load_user'], NULL, FALSE);
127-
$reportback = new static(['ignore' => true]);
128-
$reportback->build($item, $load_user);
126+
$reportback = new static(['ignore' => TRUE]);
127+
$reportback->build($item);
129128

130129
$reportbacks[] = $reportback;
131130
}
@@ -138,9 +137,8 @@ public static function find(array $filters = []) {
138137
* Build out the instantiated Reportback class object with supplied data.
139138
*
140139
* @param object $data
141-
* @param bool $full Boolean to decide whether to fetch full user data.
142140
*/
143-
private function build($data, $full = false) {
141+
private function build($data) {
144142
global $user;
145143

146144
$this->id = $data->rbid;
@@ -160,20 +158,18 @@ private function build($data, $full = false) {
160158
],
161159
];
162160

163-
if ($full) {
164-
$northstar_user = dosomething_northstar_get_northstar_user($data->uid);
165-
$northstar_user = json_decode($northstar_user, true);
166-
$northstar_user = (object) $northstar_user['data'][0];
167-
168-
$this->user = [
169-
'drupal_id' => $data->uid,
170-
'id' => $northstar_user->_id,
171-
'first_name' => $northstar_user->first_name,
172-
'last_name' => $northstar_user->last_name,
173-
'photo' => $northstar_user->photo,
174-
'country' => $northstar_user->country,
175-
];
176-
}
161+
$northstar_user = dosomething_northstar_get_northstar_user($data->uid);
162+
$northstar_user = json_decode($northstar_user->data, true);
163+
$northstar_user = (object) $northstar_user['data'][0];
164+
165+
$this->user = [
166+
'drupal_id' => $data->uid,
167+
'id' => $northstar_user->_id,
168+
'first_name' => $northstar_user->first_name,
169+
'last_name' => $northstar_user->last_name,
170+
'photo' => $northstar_user->photo,
171+
'country' => $northstar_user->country,
172+
];
177173
}
178174

179175

lib/modules/dosomething/dosomething_reportback/includes/ReportbackItem.php

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,10 @@ public static function find(array $filters = []) {
7676
}
7777

7878
foreach($results as $item) {
79-
$load_user = dosomething_helpers_isset($filters['load_user'], NULL, FALSE);
80-
$reportbackItem = new static(['ignore' => true]);
81-
$reportbackItem->build($item, $load_user);
79+
$reportbackItem = new static;
80+
$reportbackItem->build($item);
8281

83-
$reportbacks[] = $reportback;
82+
$reportbackItems[] = $reportbackItem;
8483
}
8584

8685
return $reportbackItems;
@@ -91,9 +90,8 @@ public static function find(array $filters = []) {
9190
* Build out the instantiated Reportback Item class object with supplied data.
9291
*
9392
* @param object $data
94-
* @param bool $full Boolean to decide whether to fetch full user data.
9593
*/
96-
private function build($data, $full = false) {
94+
private function build($data) {
9795
$this->id = $data->fid;
9896
$this->status = $data->status;
9997
$this->caption = !empty($data->caption) ? $data->caption : t('DoSomething? Just did!');
@@ -118,20 +116,18 @@ private function build($data, $full = false) {
118116
],
119117
];
120118

121-
if ($full) {
122-
$northstar_user = dosomething_northstar_get_northstar_user($data->uid);
123-
$northstar_user = json_decode($northstar_user->data, true);
124-
$northstar_user = (object) $northstar_user['data'][0];
125-
126-
$this->user = [
127-
'drupal_id' => $data->uid,
128-
'id' => $northstar_user->_id,
129-
'first_name' => $northstar_user->first_name,
130-
'last_name' => $northstar_user->last_name,
131-
'photo' => $northstar_user->photo,
132-
'country' => $northstar_user->country,
133-
];
134-
}
119+
$northstar_user = dosomething_northstar_get_northstar_user($data->uid);
120+
$northstar_user = json_decode($northstar_user->data, true);
121+
$northstar_user = (object) $northstar_user['data'][0];
122+
123+
$this->user = [
124+
'drupal_id' => $data->uid,
125+
'id' => $northstar_user->_id,
126+
'first_name' => $northstar_user->first_name,
127+
'last_name' => $northstar_user->last_name,
128+
'photo' => $northstar_user->photo,
129+
'country' => $northstar_user->country,
130+
];
135131
}
136132

137133

lib/modules/dosomething/dosomething_reportback/includes/ReportbackItemTransformer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public function index($parameters) {
2020
// Not ideal that this is NULL instead of FALSE but due to how logic happens in original query function. It should be updated!
2121
// Logic currently checks for isset() instead of just boolean, so won't change until endpoints switched.
2222
$filters['random'] = $parameters['random'] === 'true' ? TRUE : NULL;
23-
$filters['load_user'] = $parameters['load_user'] === 'true' ? TRUE : NULL;
2423

2524
try {
2625
$reportbackItems = ReportbackItem::find($filters);

lib/modules/dosomething/dosomething_reportback/includes/ReportbackTransformer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public function index($parameters) {
4343
// Not ideal that this is NULL instead of FALSE but due to how logic happens in original query function. It should be updated!
4444
// Logic currently checks for isset() instead of just boolean, so won't change until endpoints switched.
4545
$filters['random'] = $parameters['random'] === 'true' ? TRUE : NULL;
46-
$filters['load_user'] = $parameters['load_user'] === 'true' ? TRUE : NULL;
4746

4847
try {
4948
$reportbacks = Reportback::find($filters);

0 commit comments

Comments
 (0)