diff --git a/CHANGELOG.md b/CHANGELOG.md index 84655f7..462dde3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/README.md b/README.md index 35b5241..63b0c4e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/organic-search-analytics/data-capture-run.php b/organic-search-analytics/data-capture-run.php index 91c50da..9d7976d 100644 --- a/organic-search-analytics/data-capture-run.php +++ b/organic-search-analytics/data-capture-run.php @@ -1,18 +1,48 @@ 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 ) ) { @@ -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 "

ERROR: Invalid request. Domain: " . $_GET['domain'] . ", Date: " . $_GET['date'] . "

"; + echo "

ERROR: Invalid request. Domain: " . $params['domain'] . ", Date: " . $params['date'] . "

"; } ?> \ No newline at end of file diff --git a/organic-search-analytics/version.txt b/organic-search-analytics/version.txt index 73462a5..21b159d 100644 --- a/organic-search-analytics/version.txt +++ b/organic-search-analytics/version.txt @@ -1 +1 @@ -2.5.1 +2.5.2 \ No newline at end of file