/** * Get a list of offers to be added or remove. Write the offers to the database. * @param string &$log * @return int */ public function GetOffers(&$log) { if (!$this->WS()) { return null; } $log .= "START\n"; $log .= "working dir=" . getcwd() . "\n"; $time_start = microtime_float(); $count_arr = array("suma" => 0, "dodane" => 0, "zmodyfikowane" => 0, "usuniete" => 0); $deleted_ids = $this->GetOffersPartial(false, $log, $count_arr); Errors::LogSynchroStep('WebServiceVirgo - GetOffers() - step 1'); //delete offers foreach ($deleted_ids as $idd) { $ret = Offers::DeleteOffer($idd); if ($ret == "D") { $count_arr["suma"]++; $count_arr["usuniete"]++; } echo DataBase::GetDbInstance()->LastError(); } Errors::LogSynchroStep('WebServiceVirgo - GetOffers() - step 4'); Errors::LogError2File("Offers synchronization results: added=" . $count_arr["dodane"] . ", modified=" . $count_arr["zmodyfikowane"] . ", deleted=" . $count_arr["usuniete"]); $log .= "KONIEC\n"; $time_end = microtime_float(); $time = $time_end - $time_start; if ($this->_DEBUG) { echo "<b>Execution time: {$time} seconds</b><br>"; } if ($this->_DEBUG) { echo "Queries count: " . DataBase::$QUERY_COUNT . "<br>"; } OffersHelper::clearCache(); return $count_arr["suma"]; }
/** * Verifies offers * @return int[] */ public static function VerifyOffers() { $list = array(); $xml = new XMLReader(); $domdoc = new DOMDocument(); $xml->open(WebServiceVirgo::TMP_XML_OFELIST_FILE); Errors::LogSynchroStep('Offers - VerifyOffers() - step 1'); $xml->read(); while ($xml->name) { if ($xml->name == 'Oferta') { $node = simplexml_import_dom($domdoc->importNode($xml->expand(), true)); $list[] = (int) $node["ID"]; } $xml->read(); } Errors::LogSynchroStep('Offers - VerifyOffers() - step 2'); $db = DataBase::GetDbInstance(); $query = "SELECT DISTINCT(id) FROM #S#offers o"; $result = $db->ExecuteQuery($query); $ofrs = new Offers(); //delete wrong offers $localOffs = array(); $flippedList = array_flip($list); while ($row = $db->FetchArray($result)) { if (!isset($flippedList[$row[0]])) { $ofrs->DeleteOffer($row[0]); } else { $localOffs[] = $row[0]; } } //detect missing offers $braki = array(); $flippedLocalOffs = array_flip($localOffs); foreach ($list as $id) { if (!isset($flippedLocalOffs[$id])) { $braki[] = $id; } } Errors::LogSynchroStep('Offers - VerifyOffers() - step 3'); return $braki; }