Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get "Workspace to pull" on test_rdr to work again #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions PmiRdrModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,12 @@ function decodeSnapshotsFromStorage($snapshotSetting) {
$storedSnapshots .= $this->getSystemSetting($thisIndex);
}

return json_decode($storedSnapshots);
return json_decode($storedSnapshots, true);
}

## RDR Cron method to pull data in
public function rdr_pull($debugApi = false,$singleRecord = false) {
// $this->log("Ran pull cron");
public function rdr_pull($debugApi = false, $singleRecord = false) {


if(is_array($debugApi)) {
## When run from the cron, an array is passed in here
Expand Down Expand Up @@ -610,12 +610,18 @@ public function rdr_pull($debugApi = false,$singleRecord = false) {

## Start looping through the data returned from the API (this is the "record" level)
foreach($decodedResults as $dataKey => $dataDetails) {
## This could be because an error message was received or the API data isn't formatted properly
## Or if not yet at $maxRecordId
if(!is_array($dataDetails) || $dataKey < $maxRecordId) {
continue;

if ($singleRecord) {
if ($dataKey != $singleRecord) {
continue;
}
} else {
## This could be because an error message was received or the API data isn't formatted properly
## Or if not yet at $maxRecordId
if (!is_array($dataDetails) || $dataKey < $maxRecordId) {
continue;
}
}

## "flat" means that the top level array keys don't contain the record IDs, so need to look it up from the data
$recordId = $dataKey;
if($dataFormats[$urlKey] == "flat") {
Expand All @@ -625,7 +631,7 @@ public function rdr_pull($debugApi = false,$singleRecord = false) {
## Don't try to import if the record already exists
## TODO See if we can find a way to update records without making it
## TODO run so slowly that it can never finish in App Engine (60 second timeout)
if(array_key_exists($recordId,$recordList)) {
if(array_key_exists($recordId,$recordList) && !$singleRecord) {
continue;
}

Expand All @@ -651,13 +657,10 @@ public function rdr_pull($debugApi = false,$singleRecord = false) {
$rowData[$redcapField] = $this->getApiValue($dataDetails,$apiField,$metadata[$redcapField]);
}
}

if($testingOnly[$urlKey] == "1") {
if(!$debugApi) {
echo "<pre>".htmlspecialchars($recordId." => ".var_export($rowData,true))."</pre>";echo "<br />";
}
if($debugApi) {
echo "<pre>".htmlspecialchars($recordId." => ".var_export($rowData,true))."</pre>";echo "<br />";
}
else {
if ($testingOnly[$urlKey] != "1") {
Comment on lines -655 to +663
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kcmcg I am changing this around so we can use test_rdr without having to put the module in test mode, because we shouldn't have to stop the functionality to see a a debug on the test page.

self::checkShutdown();

## Attempt to save the data
Expand Down