Current File : /home/n742ef5/royalanteam.com/mls_bkp/mls_extra.php |
<?php
ini_set('memory_limit', '1024M');
set_time_limit(0);
ini_set('max_execution_time', 7200);
ini_set('display_errors', 1);
ini_set("log_errors", 1);
ini_set('default_charset', 'UTF-8');
error_reporting(E_ALL);
header('Content-Type: text/html; charset=utf-8');
date_default_timezone_set('America/Toronto');
//ini_set("error_log", "/home3/sitwoweb/public_html/royalanteam/mls/mls_resi_new.txt");
//echo "dfdf";exit;
$plus_v = urlencode("+");
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] . $mtime[0];
$t_start = $mtime;
$to = 'msuman1610@gmail.com';
$subject = 'Property Sold';
require_once("config/mls_config.php");
require_once("lib/phrets.php");
require_once("config/properties_config.php");
require_once("/home/n742ef5/royalanteam.com/wp-load.php");
global $wpdb;
echo $website_uri = site_url();
//exit;
$message = "";
$message = '<html><head><title>RoyalTeam Extra Import</title></head><body>';
$timestamp_field = 'Timestamp_sql';
$file_name = "mls_sold.php";
$curr_resource = "Property";
$mls_key_field = "Ml_num";
$curr_mls_id = 1;
date_default_timezone_set('America/Toronto');
$curr_date = date('Y-m-d H:i:s');
$cron_tablename = 'properties_cron_log';
$tmp_tablename = 'property_queue';
foreach($all_classes as $classkey=> $classdata ) {
$className = $classdata['ClassName'];
$pro_table = $classdata['TableName'];
echo $classNameText = $classdata['classNameText'];
$inserted_prop = 0;
$updated_prop = 0;
$properties_inserted_in_db = 0;
$sql_query = "SELECT id,Ml_num, property_insert_time,property_last_updated FROM `rets_property_data_resi` where Status='A' order by property_last_updated desc LIMIT 5000,3000";
$sql_query = "SELECT id,Ml_num FROM `rets_property_data_resi` where Status='A' and processed = 1 order by property_last_updated desc LIMIT 5000,10000";
$sql_query = "SELECT id,Ml_num FROM `rets_property_data_resi` where Status='A' and processed = 1 and Municipality IN ('Markham', 'Toronto', 'Ajax', 'Pickering', 'Oshawa', 'Mississauga', 'Brampton','King') ORDER BY id ASC LIMIT 3000,2000";
$sql_query = "SELECT id,Ml_num, property_last_updated FROM `rets_property_data_resi` where Status='A' and processed = 1 and Municipality IN ('Markham', 'Toronto', 'Ajax', 'Pickering', 'Oshawa', 'Mississauga', 'Brampton','King') and Ml_num in(Select meta_value from $wpdb->postmeta where meta_key='fave_mls_field_key_value' ) ORDER BY property_last_updated DESC LIMIT 3000,500";
//Scarborough
$all_post = $wpdb->get_results( $sql_query );
$cc = 0 ;
if ($all_post && !empty($all_post) ) {
foreach($all_post as $curr_post){
$cc++;
$listing_key = $curr_post->Ml_num;
echo "<br>".$cc." '".$curr_post->Ml_num."',";
//continue;
$listingId = $listing_key ;
$qn_query = "select post_id from $wpdb->postmeta where meta_key='fave_mls_field_key_value' and meta_value = '".$listing_key."' ";
$pre_post = $wpdb->get_results( $qn_query );
if ($pre_post && !empty($pre_post) ) {
$post_id = $pre_post[0]->post_id;
//$post_id = $each_posts['ID'];
echo "<br>Post Id :".$post_id;
//continue;
$media = get_attached_media('', $post_id);
if (isset($media) && count($media) > 0) {
foreach ($media as $photo) {
echo "<br>".$main_image_path = $photo->post_content_filtered;
error_log("Image " . $main_image_path . "<br>");
@unlink($main_image_path);
$thumbnail_image_src = wp_get_attachment_image_src($photo->ID, 'thumbnail');
$thumbnail_relative_url = str_replace($website_uri.'/', $main_directory, $thumbnail_image_src['0']);
@unlink($thumbnail_relative_url);
$image_post_id = $photo->ID;
$wp_delete_query = "DELETE FROM $wpdb->postmeta where post_id=$image_post_id";
$wpdb->query($wp_delete_query);
$wp_delete_query = "DELETE FROM $wpdb->posts where ID =$image_post_id";
$wpdb->query($wp_delete_query);
}
}
$wp_delete_query = "DELETE FROM $wpdb->postmeta where post_id=$post_id and meta_key in('_iwp_gallery','fave_property_images')";
$wpdb->query($wp_delete_query);
$remove_query_meta = "DELETE FROM $wpdb->postmeta where post_id = $post_id ";
$result_remove = $wpdb->query($remove_query_meta);
$del_term = "DELETE FROM $wpdb->term_relationships where object_id = $post_id ";
$wpdb->query($del_term);
$remove_main = "DELETE FROM $wpdb->posts where ID = $post_id ";
$result_remove = $wpdb->query($remove_main);
}
}
}
}
$message .= "</body></html>";
$end_time = date('Y-m-d H:i:s');
$headers = 'From: Royalanteam <noreply@'.$_SERVER['HTTP_HOST'].'>' . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
//mail('msuman1610@gmail.com','MLS Download '.$end_time,$message,$headers);
?>