function CheckForNewDeals($ST) { //Read deal update times list($QR, $RS, $T) = QuerySet('SELECT DealSourceID AS SID, DealSourceName AS DN, DealSourceFileName AS FN, DealSourceResetTime AS RT FROM 4100_Deal_Sources WHERE DealSourceStatus & 1 = 1;'); //list ($QR, $RS, $T) = QuerySet('SELECT DealSourceID AS ID, DealSourceFileName AS FN FROM 4100_Deal_Sources WHERE DealSourceStatus & 1 = 1 AND UNIX_TIMESTAMP(DealsLastUpdated) <= '.mktime(date('H')-6,date('i'),date('s'),date('n'),date('j'),date('Y')).';'); if ($QR < 0) { return SysLogIt('Query returned an error', StatusError, ActionSelect); } if ($QR > 0) { while ($DR = mysql_fetch_array($RS)) { if (time() - $ST > 720) { return SysLogIt('Deal parsing exceeded 12 minutes; stopping until next cycle.', StatusInfo, ActionNotSpecified, -1); } try { $AClass = $DR['FN']; $TheClass = new $AClass(); //Retrieve districts list($QR, $SRS, $T) = QuerySet('SELECT RemoteID AS SRID, CountryID AS CID, URL, LanguageID AS LID, TimeZone AS TZ, Latitude AS LAT, Longitude AS LNG FROM 4110_Deal_Source_URLs WHERE Latitude <> 0 AND Longitude <> 0 AND DealSourceID = ' . $DR['SID'] . ' AND (NextUpdate < ' . date('YmdHis') . ' OR NextUpdate = 0) AND Status = 1 ' . Limits . ';'); if ($QR < 0) { return SysLogIt('Error while searching for ' . $DR['DN'] . ' divisions.', StatusError, ActionSelect); } if ($QR > 0) { SysLogIt('Retrieving ' . $DR['DN'] . ' deals.'); while ($SDR = mysql_fetch_array($SRS)) { if (time() - $ST > 720) { return SysLogIt('Script exceeded 12 minutes; stopping until next cycle.', StatusInfo, ActionNotSpecified, -1); } $Next = 0; SysLogIt('Processing ' . $DR['DN'] . ' division with ID of ' . $SDR['SRID'] . ' (' . $SDR['URL'] . ')', StatusInfo, ActionNotSpecified, 1); list($S, $DArr) = $TheClass->GetDivisionData($SDR['SRID'], $SDR['URL'], $SDR['LID'], $SDR['TZ']); if ($S) { if ($DArr !== false) { foreach ($DArr as $D) { CleanAll($D); if (!array_key_exists('GW', $D)) { ProcessDeal($D, $DR['SID'], $DR['DN'], $SDR['SRID'], $SDR['LID'], $SDR['CID'], $SDR['LAT'], $SDR['LNG']); if ($Next == 0 || $D['EDate'] < $Next) { $Next = $D['EDate']; } } if (array_key_exists('Deals', $D)) { foreach ($D['Deals'] as $DItem) { $DURL = is_array($DItem) ? $DItem[0] : $DItem; $WebD = is_array($DItem) ? $DItem[1] : false; SysLogIt('Processing ' . $DR['DN'] . ' sub-deal (' . $DURL . ').', StatusInfo, ActionNotSpecified, 1); list($S, $SDArr) = $TheClass->GetDivisionData($SDR['SRID'], $DURL, $SDR['LID'], $SDR['TZ'], true, $WebD); if ($S) { if ($SDArr !== false) { foreach ($SDArr as $SD) { CleanAll($SD); ProcessDeal($SD, $DR['SID'], $DR['DN'], $SDR['SRID'], $SDR['LID'], $SDR['CID'], $SDR['LAT'], $SDR['LNG']); if ($Next == 0 || $SD['EDate'] < $Next) { $Next = $SD['EDate']; } } } } } } } SetNextUpdate($DR['SID'], $SDR['SRID'], $DR['RT'], $SDR['TZ'], $Next); } else { SysLogIt('No active deal for division with ID of ' . $SDR['SRID'] . '.'); //Exceptions if ($DR['SID'] == 9 && date('H') < 10) { $Next = mktime(date('H') + 3, date('i'), date('s'), date('n'), date('j'), date('Y')); } SetNextUpdate($DR['SID'], $SDR['SRID'], $DR['RT'], $SDR['TZ'], $Next); } } else { SetNextUpdate($DR['SID'], $SDR['SRID'], 0, 0, 0); } } SysLogIt('Finished retrieving ' . $DR['DN'] . ' deals.', StatusInfo, ActionNotSpecified, -1); } } catch (Exception $Exp) { SysLogIt('Error getting deals for source with ID of ' . $DR['SID'] . '.', StatusError); } } } return true; }
} include_once dirname(__FILE__) . '/ressources/class.templates.inc'; include_once dirname(__FILE__) . '/ressources/class.ccurl.inc'; include_once dirname(__FILE__) . '/ressources/class.ini.inc'; include_once dirname(__FILE__) . '/ressources/class.mysql.inc'; include_once dirname(__FILE__) . '/framework/class.unix.inc'; include_once dirname(__FILE__) . '/ressources/class.squid.inc'; include_once dirname(__FILE__) . '/ressources/class.os.system.inc'; include_once dirname(__FILE__) . "/framework/frame.class.inc"; include_once dirname(__FILE__) . '/ressources/class.computers.inc'; if (system_is_overloaded()) { die; } $GLOBALS["Q"] = new mysql_squid_builder(); if ($argv[1] == "--cleanall") { CleanAll(); exit; } if ($argv[1] == "--year") { table_year(); exit; } tables_months(); function CleanAll() { $q = new mysql_squid_builder(); $LIST_TABLES_MONTH = $q->LIST_TABLES_MONTH(); while (list($tablename, $none) = each($LIST_TABLES_MONTH)) { echo "Empty {$tablename}\n"; $q->QUERY_SQL("DROP TABLE `{$tablename}`"); }