function patch_album($get_sysid) { global $rets, $useradmin; while ($row_get_sysid = mysql_fetch_assoc($get_sysid)) { echo '<br/><br/>checking:<span style="color:#00ff00;">' . $row_get_sysid['sysid'] . '</span><br/>'; $album_id = check_and_insert($row_get_sysid['sysid']); if (!empty($album_id)) { $photo_id_array = get_photo_id($row_get_sysid['sysid']); echo "<br/>"; var_dump($photo_id_array); echo "<br/>"; $response = $rets->GetPhoto('Property', $row_get_sysid['sysid'] . ':*', 'images'); $photo_array = $response['photo_array']; echo "<br/>服务器图片数量:" . count($photo_array) . ' & 本地图片数量:' . count($photo_id_array) . "<br/>"; if (count($photo_array) > count($photo_id_array)) { echo "<br/>We got more photos from the remote server<br/>"; for ($i = 0; $i < count($photo_array); $i++) { $selectSQL = "SELECT * FROM photo_profile WHERE photo_path='" . $photo_array[$i] . "'"; if ($photo_item = mysql_fetch_assoc(mysql_query_or_die($selectSQL, $useradmin))) { echo "<br/>photo_path found in database, nothing to be inserted.<br/>"; } else { $selectSQL = "SELECT photo_profile.photo_id FROM listings LEFT JOIN album_profile ON listings.album_id = album_profile.album_id" . " LEFT JOIN photo_profile ON album_profile.photo_id = photo_profile.photo_id" . " WHERE photo_path='http://80a5e3a6041af90156b0-bf53eb49f254872ee431fd1273bc084d.r45.cf2.rackcdn.com/_.jpg'" . " AND listings.album_id={$album_id}"; //echo $selectSQL; $get_photo = mysql_query_or_die($selectSQL, $useradmin); if ($row_get_photo = mysql_fetch_assoc($get_photo)) { echo "<br/>Broken image found. Updating record.<br/>"; $photo_id = $row_get_photo['photo_id']; $photo_path = $photo_array[$i]; $update_SQL = sprintf("UPDATE photo_profile SET photo_path=%s WHERE photo_id=%s", GetSQLValueString($photo_path, "text"), GetSQLValueString($photo_id, "int")); $result = mysql_query_or_die($update_SQL, $useradmin); } else { echo "<br/>photo_path not found in database, inserting new record<br/>"; $insertPhotoSQL = sprintf("INSERT INTO photo_profile(photo_path)VALUES(%s)", GetSQLValueString($photo_array[$i], "text")); $result = mysql_query_or_die($insertPhotoSQL, $useradmin); $photo_id = mysql_insert_id($useradmin); $insertAlbumSQL = sprintf("INSERT INTO album_profile(album_id, photo_id, cover)VALUES(%s,%s,%s)", GetSQLValueString($album_id, "int"), GetSQLValueString($photo_id, "int"), GetSQLValueString($i == 0 ? 'Y' : 'N', "text")); $result = mysql_query_or_die($insertAlbumSQL, $useradmin); } } unset($selectSQL); } $updateSQL = sprintf("UPDATE listings SET num_of_photos=%s, album_patched=%s WHERE sysid=%s", GetSQLValueString(count($photo_array), "int"), GetSQLValueString('Y', "text"), GetSQLValueString($row_get_sysid['sysid'], "int")); $result = mysql_query_or_die($updateSQL, $useradmin); } elseif (count($photo_id_array) == count($photo_array)) { for ($i = 0; $i < count($photo_array); $i++) { //first we have to check if local database image is broken $selectSQL = "SELECT photo_profile.photo_id FROM listings LEFT JOIN album_profile ON listings.album_id = album_profile.album_id" . " LEFT JOIN photo_profile ON album_profile.photo_id = photo_profile.photo_id" . " WHERE photo_path='http://80a5e3a6041af90156b0-bf53eb49f254872ee431fd1273bc084d.r45.cf2.rackcdn.com/_.jpg'" . " AND listings.album_id={$album_id}"; //echo $selectSQL; $get_photo = mysql_query_or_die($selectSQL, $useradmin); if ($row_get_photo = mysql_fetch_assoc($get_photo)) { echo "<br/><span style=\"color:red\">There is a broken image in album {$album_id}. Updating record.</span><br/>"; $photo_id = $row_get_photo['photo_id']; $photo_path = $photo_array[$i]; $update_SQL = sprintf("UPDATE photo_profile SET photo_path=%s WHERE photo_id=%s", GetSQLValueString($photo_path, "text"), GetSQLValueString($photo_id, "int")); $result = mysql_query_or_die($update_SQL, $useradmin); } } $updateSQL = sprintf("UPDATE listings SET album_patched=%s WHERE sysid=%s", GetSQLValueString('Y', "text"), GetSQLValueString($row_get_sysid['sysid'], "int")); $result = mysql_query_or_die($updateSQL, $useradmin); } else { echo "<br/><span style=\"color:green;\">取得的图片[" . count($photo_array) . "]没有本地图片[" . count($photo_id_array) . "]多</span><br/>"; $selectSQL = "SELECT photo_profile.photo_id FROM listings LEFT JOIN album_profile ON listings.album_id = album_profile.album_id" . " LEFT JOIN photo_profile ON album_profile.photo_id = photo_profile.photo_id" . " WHERE photo_path='http://80a5e3a6041af90156b0-bf53eb49f254872ee431fd1273bc084d.r45.cf2.rackcdn.com/_.jpg'" . " AND listings.album_id={$album_id}"; //echo $selectSQL; $get_photo = mysql_query_or_die($selectSQL, $useradmin); if ($row_get_photo = mysql_fetch_assoc($get_photo)) { echo "<br/>Broken image found. Updating record.<br/>"; $photo_id = $row_get_photo['photo_id']; $deleteSQL = "DELETE FROM album_profile WHERE photo_id={$photo_id}"; $result = mysql_query_or_die($deleteSQL, $useradmin); $photo_id_array = get_photo_id($row_get_sysid['sysid']); $updateSQL = sprintf("UPDATE listings SET num_of_photos=%s, album_patched=%s WHERE sysid=%s", GetSQLValueString(count($photo_id_array), "int"), GetSQLValueString(count($photo_array) == 0 ? 'Y' : 'Y', "text"), GetSQLValueString($row_get_sysid['sysid'], "int")); $result = mysql_query_or_die($updateSQL, $useradmin); } } } } }
$current_GMT_time_string = date("Y-m-d H:i:s", $current_GMT_time); $current_YVR_time = getTimeByCity($current_GMT_time, 'YVR'); $current_YVR_time_string = date("Y-m-d H:i:s", $current_YVR_time); $before1hr_time_string = date("Y-m-d H:i:s", $current_YVR_time - 3600); $selectSQL = "SELECT SQL_CALC_FOUND_ROWS DISTINCT sysid FROM listings WHERE (ISNULL(listings.album_id) OR num_of_photos<=1) AND status='A' AND property_type!='Land Only' ORDER BY RAND() LIMIT 0, 10"; $get_sysid = mysql_query_or_die($selectSQL, $useradmin); $row = mysql_fetch_row(mysql_query("SELECT FOUND_ROWS()", $useradmin)); //login and receive server response. if (is_array($row) && $row[0] > 0) { echo '<br/>' . $row[0] . 'records needs to be album_patched.<br/>'; $response = $rets->Login(); while ($row_get_sysid = mysql_fetch_assoc($get_sysid)) { echo '<br/><br/>checking:<span style="color:#00ff00;">' . $row_get_sysid['sysid'] . '</span><br/>'; $album_id = check_and_insert($row_get_sysid['sysid']); if (!empty($album_id)) { $photo_id_array = get_photo_id($row_get_sysid['sysid']); var_dump($photo_id_array); $response = $rets->GetPhoto('Property', $row_get_sysid['sysid'] . ':*', 'images'); $photo_array = $response['photo_array']; if (count($photo_array) > count($photo_id_array)) { for ($i = 0; $i < count($photo_array); $i++) { $selectSQL = "SELECT * FROM photo_profile WHERE photo_path='" . $photo_array[$i] . "'"; if ($photo_item = mysql_fetch_assoc(mysql_query_or_die($selectSQL, $useradmin))) { echo "<br/>photo_path found in database, nothing to be inserted.<br/>"; } else { echo "<br/>photo_path not found in database, inserting new record<br/>"; $insertPhotoSQL = sprintf("INSERT INTO photo_profile(photo_path)VALUES(%s)", GetSQLValueString($photo_array[$i], "text")); $result = mysql_query_or_die($insertPhotoSQL, $useradmin); $photo_id = mysql_insert_id($useradmin); $insertAlbumSQL = sprintf("INSERT INTO album_profile(album_id, photo_id, cover)VALUES(%s,%s,%s)", GetSQLValueString($album_id, "int"), GetSQLValueString($photo_id, "int"), GetSQLValueString($i == 0 ? 'Y' : 'N', "text")); $result = mysql_query_or_die($insertAlbumSQL, $useradmin);