function write_updated_zone($vtimezone, $tzid) { global $new_zones, $modified_zones; if (empty($vtimezone)) { dbg_error_log('tz/updatecheck', 'Skipping zone "%s" - no data from server', $tzid); return; } $tzrow = fetch_db_zone($tzid); if (isset($tzrow) && $vtimezone == $tzrow->vtimezone) { dbg_error_log('tz/updatecheck', 'Skipping zone "%s" - no change', $tzid); return; } $vtz = new vCalendar($vtimezone); $last_modified = $vtz->GetPValue('LAST-MODIFIED'); if (empty($last_modified)) { $last_modified = gmdate('Ymd\\THis\\Z'); // Then it was probably that way when we last updated the data, too :-( if (!empty($tzrow)) { $old_vtz = new vCalendar($tzrow->vtimezone); $old_vtz->ClearProperties('LAST-MODIFIED'); // We need to add & remove this property so the Render is equivalent. $vtz->AddProperty('LAST-MODIFIED', $last_modified); $vtz->ClearProperties('LAST-MODIFIED'); if ($vtz->Render() == $old_vtz->Render()) { dbg_error_log('tz/updatecheck', 'Skipping zone "%s" - no change', $tzid); return; } } $vtz->AddProperty('LAST-MODIFIED', $last_modified); } dbg_error_log('tz/updatecheck', 'Writing %s zone for "%s"', empty($tzrow) ? "new" : "updated", $tzid); printf("Writing %s zone for '%s'\n", empty($tzrow) ? "new" : "updated", $tzid); $params = array(':tzid' => $tzid, ':olson_name' => $tzid, ':vtimezone' => $vtz->Render(), ':last_modified' => $last_modified, ':etag' => md5($vtz->Render())); if (empty($tzrow)) { $new_zones++; $sql = 'INSERT INTO timezones(tzid,active,olson_name,last_modified,etag,vtimezone) '; $sql .= 'VALUES(:tzid,TRUE,:olson_name,:last_modified,:etag,:vtimezone)'; } else { $modified_zones++; $sql = 'UPDATE timezones SET active=TRUE, olson_name=:olson_name, last_modified=:last_modified, '; $sql .= 'etag=:etag, vtimezone=:vtimezone WHERE tzid=:tzid'; } $qry = new AwlQuery($sql, $params); $qry->Exec('tz/update', __LINE__, __FILE__); }