Skip to content

Commit

Permalink
Merge pull request #48 from PromInc/CRON
Browse files Browse the repository at this point in the history
CRON
  • Loading branch information
PromInc authored Apr 21, 2017
2 parents 909500d + c0fe0b9 commit 078f15e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.5.2 - 2017-04-20
### Added
- CRON functionality

## 2.5.1 - 2017-04-08
### Bug Fixes
- Bing data was not being captured. Run the upgrade script to correct the database structure for this to capture.
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Organic Search Analytics Importer
## CRON Features (April 20th, 2017)
### New Features (2.5.2) - current master branch
- Ability to run the import via CRON by calling data-capture-run.php

## Version 2.5.1 Now Available!!! (April 9th, 2017)
### New Features (2.5.1)
- Bug fix that prevented Bing data from capturing after 2.5.0
Expand Down
62 changes: 46 additions & 16 deletions organic-search-analytics/data-capture-run.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,48 @@
<?php
require_once realpath(dirname(__FILE__).'/inc/code/globalIncludes.php'); /* Load classes */

if( isset($_GET) && isset($_GET['type']) && isset($_GET['domain']) && isset($_GET['date']) && preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/",$_GET['date']) ) {
$params = false;

if( isset( $_GET ) && is_array( $_GET ) && count( $_GET ) > 0 ) {
$params = $_GET;
} elseif( isset( $argv ) && is_array( $argv ) && count( $argv ) >= 4 ) {
$params = array();
$params['type'] = $argv[1];
$params['domain'] = $argv[2];
$params['date'] = $argv[3];
if( isset( $argv[4] ) ) {
$params['mode'] = $argv[4];
}
if( isset( $argv[5] ) ) {
$params['row_limit'] = $argv[5];
}
if( isset( $argv[6] ) ) {
$params['dimensions'] = $argv[6];
}
if( isset( $argv[7] ) ) {
$params['filters'] = $argv[7];
}
if( isset( $argv[8] ) ) {
$params['aggregation_type'] = $argv[8];
}
if( isset( $argv[8] ) ) {
$params['search_type'] = $argv[8];
}
}


if( isset($params) && isset($params['type']) && isset($params['domain']) && isset($params['date']) && preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/",$params['date']) ) {
/* Set the max allowed execution time for the page to allow for longer procesing times. */
ini_set('max_execution_time', 600); //300 seconds = 5 minutes

/* Set overrides from URL paramters */
$overrideSettings = array();
if( isset( $_GET['mode'] ) ) { $overrideSettings['mode'] = $_GET['mode']; }
if( isset( $_GET['row_limit'] ) ) { $overrideSettings['row_limit'] = $_GET['row_limit']; }
if( isset( $_GET['dimensions'] ) ) { $overrideSettings['dimensions'] = explode( ',', $_GET['dimensions'] ); }
if( isset( $_GET['search_type'] ) ) { $overrideSettings['search_type'] = explode( ',', $_GET['search_type'] ); }
if( isset( $_GET['filters'] ) ) {
$filters = explode( '|', $_GET['filters'] );
if( isset( $params['mode'] ) ) { $overrideSettings['mode'] = $params['mode']; }
if( isset( $params['row_limit'] ) ) { $overrideSettings['row_limit'] = $params['row_limit']; }
if( isset( $params['dimensions'] ) ) { $overrideSettings['dimensions'] = explode( ',', $params['dimensions'] ); }
if( isset( $params['search_type'] ) ) { $overrideSettings['search_type'] = explode( ',', $params['search_type'] ); }
if( isset( $params['filters'] ) ) {
$filters = explode( '|', $params['filters'] );
foreach( $filters as $filter ) {
$filterArgs = explode( ',', $filter );
if( count( $filterArgs > 1 ) ) {
Expand All @@ -22,36 +52,36 @@
}
}
}
if( isset( $_GET['aggregation_type'] ) ) { $overrideSettings['aggregation_type'] = $_GET['aggregation_type']; }
if( isset( $params['aggregation_type'] ) ) { $overrideSettings['aggregation_type'] = $params['aggregation_type']; }

switch( $_GET['type'] ) {
switch( $params['type'] ) {
case 'googleSearchAnalytics':
$recordsImported = $dataCapture->downloadGoogleSearchAnalytics( $_GET['domain'],$_GET['date'], $overrideSettings );
if( !isset( $_GET['mode'] ) || $_GET['mode'] != 'return' ) {
$recordsImported = $dataCapture->downloadGoogleSearchAnalytics( $params['domain'],$params['date'], $overrideSettings );
if( !isset( $params['mode'] ) || $params['mode'] != 'return' ) {
switch( $recordsImported ) {
case -1:
echo "There was an error in authorizing your API connection.";
break;
default:
echo number_format( $recordsImported ) . " records succesfully imported to the database for " . $_GET['domain'] . " for date: " . $_GET['date'] . ".";
echo number_format( $recordsImported ) . " records succesfully imported to the database for " . $params['domain'] . " for date: " . $params['date'] . ".";
}
}
break;
case 'bingSearchKeywords':
$recordsImported = $dataCapture->downloadBingSearchKeywords($_GET['domain'],$_GET['date'], $overrideSettings);
if( !isset( $_GET['mode'] ) || $_GET['mode'] != 'return' ) {
$recordsImported = $dataCapture->downloadBingSearchKeywords($params['domain'],$params['date'], $overrideSettings);
if( !isset( $params['mode'] ) || $params['mode'] != 'return' ) {
switch( $recordsImported ) {
case -1:
echo "There was an error in authorizing your API connection.";
break;
default:
echo number_format( $recordsImported ) . " records succesfully imported to the database for " . $_GET['domain'] . ".";
echo number_format( $recordsImported ) . " records succesfully imported to the database for " . $params['domain'] . ".";
}
}
break;
}

} else {
echo "<p>ERROR: Invalid request. Domain: " . $_GET['domain'] . ", Date: " . $_GET['date'] . "</p>";
echo "<p>ERROR: Invalid request. Domain: " . $params['domain'] . ", Date: " . $params['date'] . "</p>";
}
?>
2 changes: 1 addition & 1 deletion organic-search-analytics/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.1
2.5.2

0 comments on commit 078f15e

Please sign in to comment.