require_once('../../source/class/class_core.php'); require_once('../../source/function/function_home.php'); $cachelist = array(); $discuz = C::app(); $discuz->cachelist = $cachelist; $discuz->init_cron = false; $discuz->init_setting = true; $discuz->init_user = false; $discuz->init_session = false; $discuz->init(); $google = new GoogleAPI($discuz); $google->run(); class GoogleAPI { var $core; var $version = '2.0.0'; function GoogleAPI(&$core) { $this->core = &$core; } function run() { $this->authcheck(); $method = 'on_'.getgpc('a'); if(method_exists($this, $method)) { $this->xmlheader();
// 1.0, YP 03/21/2016 - Initial release // include_once 'config.php'; // configuration and common stuff include_once 'class.GoogleApi.php'; // Google API class // Global vars $PERIOD_MIN = 30; // Start here $LOG->message("parsestats started"); $ckStart = new CheckStart($CONFIG['VAR_DIR'] . 'parsestats.lock'); if (!$ckStart->canStart()) { // Check if script already running. Doesn't allow customer to send multiple restart requests printLogAndDie("Script is already running."); } $googleAPI = new GoogleAPI($CONFIG); // GoogleAPI object $startDate = $endDate = ''; // Start and end date for report $sth = $DB->dbh->prepare("SELECT EndDate FROM FmClientStats ORDER BY EndDate DESC LIMIT 1"); $sth->execute(); if ($sth->errorInfo()[1]) { printLogAndDie("DB error: " . $sth->errorInfo()[2]); } if ($lastRecord = $sth->fetch(PDO::FETCH_ASSOC)) { $startDate = $lastRecord['EndDate']; // Start date for new report $endDate = date('Y-m-d H:i:s', strtotime($startDate . ' + ' . $PERIOD_MIN . ' minute')); } // Calculate end date for report - round down to closest 30 min. Don't check logs after this date $endDateTimeStamp = mktime(date("H"), date("i") > $PERIOD_MIN ? $PERIOD_MIN : 0, 0, date("m"), date("d"), date("Y"));
$sth1 = $DB->dbh->prepare("UPDATE FmClientSession SET Processed=? WHERE SessionId=?"); $sth1->execute(array(1, $sessionId)); if ($sth1->errorInfo()[1]) { printLogAndDie("DB error: " . $sth1->errorInfo()[2]); } return ''; } // -- markRecProcessed -- // Start here $LOG->message("report_sched started"); $ckStart = new CheckStart($CONFIG['VAR_DIR'] . 'report_sched.lock'); if (!$ckStart->canStart()) { // Check if script already running. Doesn't allow customer to send multiple restart requests printLogAndDie("Script is already running."); } $googleAPI = new GoogleAPI($CONFIG); // GoogleAPI object // Load stats for script not included in $CONFIG['FM_SCHED_SCRIPTS_2_SUM'] $qval = array(0, FM_SCHED_TYPE); $stmt = "SELECT SessionId, DATE_FORMAT(StartDate,'%Y-%m-%d %H:%i:%S') as stDate,DATE_FORMAT(EndDate,'%Y-%m-%d %H:%i:%S') as enDate, " . "TIMESTAMPDIFF(SECOND,StartDate,EndDate) as ExecTime, FmClient as SchedName " . "FROM FmClientSession " . "WHERE Processed=? and SessionType=? "; if (array_key_exists('FM_SCHED_SCRIPTS_2_SUM', $CONFIG) && count($CONFIG['FM_SCHED_SCRIPTS_2_SUM'])) { $stmt .= " AND FmClient NOT IN (?" . str_repeat(",?", count($CONFIG['FM_SCHED_SCRIPTS_2_SUM']) - 1) . ") "; $qval = array_merge($qval, $CONFIG['FM_SCHED_SCRIPTS_2_SUM']); } $stmt .= "ORDER BY SessionId"; $sth = $DB->dbh->prepare($stmt); $sth->execute($qval); if ($sth->errorInfo()[1]) { printLogAndDie("DB error: " . $sth->errorInfo()[2]); } while ($rec = $sth->fetch(PDO::FETCH_ASSOC)) {
/** * Return a map of configuration properties. This is obtained by merging properties from the config * system with properties from SiteConfig. Where the same property is defined and populated in both * places, SiteConfig takes precedence. */ public static function get_all_config() { if (!self::$_config_cache) { $conf = array(); $editable = Config::inst()->get('GoogleAPI', 'config_in_cms'); $siteConfig = SiteConfig::current_site_config(); // $googleAPIConfig = Config::inst()->get('GoogleAPI'); // $googleAPIConfig = self::config(); // Default the result properties from the config system. foreach (array('external_proxy', 'client_id', 'application_name', 'private_key_file', 'service_account', 'profile_id', 'scopes') as $prop) { $conf[$prop] = Config::inst()->get('GoogleAPI', $prop); } // For any site config properties with values, these should override the // config system, but only if editing config in the CMS is enabled. if ($editable) { foreach (array('GoogleAPIExternalProxy' => 'external_proxy', 'GoogleAPIClientID' => 'client_id', 'GoogleAPIApplicationName' => 'application_name', 'GoogleAPIServiceAccount' => 'service_account', 'GoogleAPIPrivateKeyFile' => 'private_key_file', 'GoogleAPIScopes' => 'scopes', 'GoogleAPIProfileID' => 'profile_id') as $src => $dest) { if (!empty($siteConfig->{$src})) { $conf[$dest] = $siteConfig->{$src}; } } } self::$_config_cache = $conf; } return self::$_config_cache; }