Plugin Directory

Changeset 3170241


Ignore:
Timestamp:
10/16/2024 04:09:34 PM (18 months ago)
Author:
mlsimport
Message:

Update to version 5.8.4 from GitHub

Location:
mlsimport
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • mlsimport/tags/5.8.4/admin/class-mlsimport-admin.php

    r3134790 r3170241  
    543543    public function mlsimport_hidden_fields() {
    544544        global $post;
     545
    545546        $options = get_option( $this->plugin_name . '_admin_fields_select' );
    546         echo  'ListingKey: '.get_post_meta( $post->ID, 'ListingKey', true ).'<br>';
     547
     548        $MLSimport_item_inserted = get_post_meta( $post->ID, 'MLSimport_item_inserted', true );
     549        $MLSimport_item_updated = get_post_meta( $post->ID, 'MLSimport_item_updated', true );
     550        $listing_key = get_post_meta( $post->ID, 'ListingKey', true );
     551        $mlsImportItemStatusDelete = get_post_meta($post->ID, 'mlsImportItemStatusDelete', true);
     552
     553
     554
     555        // Check if the ListingKey exists
     556        if ( !empty( $listing_key ) ) {
     557            echo 'ListingKey: ' . $listing_key . '<br>';
     558        }
     559
     560        // Check if MLSimport_item_inserted exists
     561        if ( !empty( $MLSimport_item_inserted ) ) {
     562            echo 'Added via MLS item id: ' . $MLSimport_item_inserted . ' - ' . get_the_title( $MLSimport_item_inserted ) . '<br>';
     563        }
     564
     565        // Check if MLSimport_item_updated exists
     566        if ( !empty( $MLSimport_item_updated ) ) {
     567            echo 'Updated via MLS item id: ' . $MLSimport_item_updated . ' - ' . get_the_title( $MLSimport_item_updated ) . '<br>';
     568        }
     569
     570
     571        if(!empty($mlsImportItemStatusDelete)) {
     572            if(is_array($mlsImportItemStatusDelete)) {
     573               
     574                echo 'Do not delete if status: ' .  implode(',' ,$mlsImportItemStatusDelete) . '<br>';
     575            } else {
     576
     577                echo 'Do not delete if status: ' .  esc_html($mlsImportItemStatusDelete) . '<br>';
     578
     579            }
     580           
     581        }
     582
    547583        foreach ( $options['mls-fields-admin'] as $key => $value ) {
    548584            if ( 1 === intval($options['mls-fields-admin'][ $key ] ) ) {
     
    663699                    }
    664700
    665                     $mlsimport->admin->theme_importer->mlsimport_saas_delete_property_via_mysql( $delete_get_id, ' delete from tools ' );
     701                    $mlsimport->admin->theme_importer->mlsimportSaasDeletePropertyViaMysql( $delete_get_id, ' delete from tools ' );
    666702                }
    667703
     
    13551391            $last_date = $this->mlsimport_saas_update_last_date( $item_id );
    13561392        }
    1357 
    13581393        return $last_date;
    13591394    }
     
    13681403
    13691404        $unix_time         = current_time( 'timestamp', 0 ) - ( 2 * 60 * 60 );
    1370         $last_date_to_save = date( 'Y-m-d\TH:i', $unix_time );
     1405        print $last_date_to_save = date( 'Y-m-d\TH:i', $unix_time );
    13711406        update_post_meta( $item_id, 'mlsimport_last_date', $last_date_to_save );
    13721407
     
    13841419
    13851420        $last_date = $this->mlsimport_saas_get_last_date( $item_id );
    1386 
    1387         esc_html_e('we work with','mlsimport').' '. esc_html($last_date ). PHP_EOL;
     1421        print 'MLSitem id: '.$item_id.' - ';
     1422        esc_html_e('date to consider: ','mlsimport');
     1423        print esc_html($last_date ). '. ';
    13881424
    13891425        $mlsrequest  = $this->mlsimport_make_listing_requests( $item_id, $last_date );
     1426   
    13901427        $found_items = 0;
    13911428        if ( isset( $mlsrequest['results'] ) ) {
     
    13951432        }
    13961433
    1397         print esc_html__('we found ','mlsimport') .esc_html( $found_items ). '</br>' . PHP_EOL;
     1434        print esc_html__('We found ','mlsimport') .esc_html( $found_items ). ' listings.</br>' . PHP_EOL;
    13981435
    13991436        $attachments_to_move = array();
     
    14431480            return;
    14441481        }
    1445 
     1482 
    14461483
    14471484        $mls_data          = $this->mlsimport_saas_get_mls_reconciliation_data();
     
    14581495                $property_id = $item->iD;
    14591496                ++$counter;
     1497
     1498            //print '</br>'.$counter. ' **************************</br>';
    14601499           
    1461             if ( in_array( $listingkey, $listingKey_in_MLS ) ) {
     1500            if ( in_array( $listingkey, $listingKey_in_MLS )  ) {
    14621501                print  wp_kses_post('</br>'.$listingkey .  ' IS FOUND');
    14631502            } else {
    1464                 $delete_status= get_post_meta( $property_id, 'mlsImportItemStatusDelete', true );
    1465 
    1466                 if($delete_status=='' || $delete_status=='delete'){
     1503               
     1504                $keep = $mlsimport->admin->theme_importer->check_if_delete_when_status($property_id);
     1505
     1506                if(!$keep){
    14671507                    ++$to_delete;
    1468                     print  wp_kses_post('</br>' .$listingkey. ' ------------------------- NOT FOUND delete: '.$property_id.' <-');
    1469                 //  $mlsimport->admin->theme_importer->mlsimport_saas_delete_property_via_mysql( $property_id, $listingkey );
     1508                    print  wp_kses_post('</br>' .$listingkey. ' ------------------------- NOT FOUND delete: '.$property_id.' /'.$post_status.'<-');
     1509                    $mlsimport->admin->theme_importer->mlsimportSaasDeletePropertyViaMysql( $property_id, $listingkey );
    14701510                }else{ 
    1471                     print  wp_kses_post('</br>' .$listingkey. ' ------------------------- NOT FOUND BUT MARKED AS KEEP: '.$property_id.' / '.$delete_status.'<-');
     1511                    print  wp_kses_post('</br>' .$listingkey. ' ------------------------- NOT FOUND BUT MARKED AS KEEP: '.$property_id.' /'.$post_status.'<-');
    14721512                }
    14731513
    14741514            }
     1515
     1516            //print '</br> ************************** ';
    14751517        }
    14761518
     
    18321874        }
    18331875
     1876
    18341877        $permited_status=array('active','active under contract','coming soon','activeundercontract','comingsoon','pending');
    18351878        $permited_status_lower = array_map('strtolower', $permited_status);
    18361879
    18371880        // Filter out permitted statuses from array1 values
    1838         $standardstatus_delete_array = array_filter($standardstatus_delete_array, function ($value) use ($permited_status_lower) {
    1839             return !in_array(strtolower($value), $permited_status_lower);
    1840         });
     1881    //  $standardstatus_delete_array = array_filter($standardstatus_delete_array, function ($value) use ($permited_status_lower) {
     1882    //      return !in_array(strtolower($value), $permited_status_lower);
     1883//      });
    18411884
    18421885   
     
    19101953            'StandardStatusDelete'                 => array(
    19111954                'label'       => esc_html__( 'Delete Statuses', 'mlsimport' ),
    1912                 'description' => __( 'If you edit the Delete Statuses after importing listings, the changes will NOT apply to listings that have already been imported.', 'mlsimport' ),
     1955                'description' => __( 'Properties with these statuses will be deleted from your website after they are removed from MLS database. If you edit the field after importing, the changes will NOT apply to listings that have already been imported.', 'mlsimport' ),
    19131956                'type'        => 'select',
    19141957                'multiple'    => 'yes',
  • mlsimport/tags/5.8.4/admin/partials/mlsimport-administrative-options.php

    r3134790 r3170241  
    2626        $options = get_option( $this->plugin_name . '_administrative_options' );
    2727        $mlsimport->admin->mlsimport_saas_setting_up();
    28         // mlsimport_saas_event_mls_import_auto_function();
    29          //mlsimport_saas_reconciliation_event_function();
     28        //mlsimport_saas_event_mls_import_auto_function();
     29        //mlsimport_saas_reconciliation_event_function();
    3030    ?>
    31 
     31 
    3232<h1> Administrative Tools</h1>
    3333
  • mlsimport/tags/5.8.4/includes/ThemeImport.php

    r3144187 r3170241  
    823823        }
    824824
    825         if (!isset($property['ListingKey'])) {
     825        if (!isset($property['ListingKey']) || empty($property['ListingKey'])) {
    826826            $this->writeImportLogs('ERROR: No Listing Key ' . PHP_EOL, $tipImport);
    827827            return;
     
    834834        $propertyId         = intval($this->mlsimportSaasRetrievePropertyById($ListingKey, $listingPostType));
    835835        $status             = isset($property['StandardStatus']) ? strtolower($property['StandardStatus']) : strtolower($property['extra_meta']['MlsStatus']);
     836       
     837       
     838        $this->writeImportLogs('FIxing: on inserting ' .$status.'-->'.json_encode($mlsImportItemStatus). PHP_EOL, $tipImport);
     839
     840
    836841        $isInsert           = $this->shouldInsertProperty($propertyId, $status, $mlsImportItemStatus, $tipImport);
    837842
     
    851856                'post_author'   => $newAuthor,
    852857            ];
    853 
     858 
    854859            $propertyId = wp_insert_post($post);
    855860            if (is_wp_error($propertyId)) {
     
    857862            } else {
    858863                update_post_meta($propertyId, 'ListingKey', $ListingKey);
    859                 $keep_on_delete='delete';
    860                 if( is_array($mlsImportItemStatusDelete) && !in_array($status,$mlsImportItemStatusDelete)){
    861                     $keep_on_delete='keep';
    862                     update_post_meta($propertyId, 'mlsImportItemStatusDelete', $keep_on_delete);
    863                 }
    864 
    865 
    866    
    867            
     864                update_post_meta($propertyId, 'MLSimport_item_inserted', $itemIdArray['item_id'],);
     865                update_post_meta($propertyId, 'mlsImportItemStatusDelete', $mlsImportItemStatusDelete);
     866
     867               
    868868               
    869869                $propertyHistory[] = date('F j, Y, g:i a') . ': We Inserted the property with Default title :  ' . $submitTitle . ' and received id:' . $propertyId.'. The delete statuses are '.$keep_on_delete;
     
    874874        } elseif ($propertyId !== 0) {
    875875
    876             $keep_on_delete='delete';
    877             if(is_array($mlsImportItemStatusDelete) &&  !in_array($status,$mlsImportItemStatusDelete)){
    878                 $keep_on_delete='keep';
    879                 update_post_meta($propertyId, 'mlsImportItemStatusDelete', $keep_on_delete);
    880             }
    881 
    882             $propertyHistory = $this->updateExistingProperty($propertyId,$mlsImportItemStatusDelete, $content, $listingPostType, $newAuthor, $status, $mlsImportItemStatus, $propertyHistory, $tipImport, $ListingKey);
    883         }
     876            $keep = $this->check_if_delete_when_status($property_id);
     877
     878            if(!$keep){
     879                $log = 'Property with ID ' . $propertyId . ' and with name ' . get_the_title($propertyId) . ' has a status of <strong>' . $status . ' / '.$post_status.'</strong> and will be deleted' . PHP_EOL;
     880                $this->deleteProperty($propertyId, $ListingKey);
     881                $this->writeImportLogs($log, $tipImport);
     882            }else{ 
     883                update_post_meta($propertyId, 'mlsImportItemStatusDelete', $mlsImportItemStatusDelete);
     884                $propertyHistory = $this->updateExistingProperty($propertyId,$mlsImportItemStatusDelete, $content, $listingPostType, $newAuthor, $status, $mlsImportItemStatus, $propertyHistory, $tipImport, $ListingKey);
     885            }
     886        }
     887
     888
     889
     890
     891
    884892
    885893        if ($propertyId === 0) {
     
    910918     * @return string 'yes' or 'no' indicating if the property should be inserted.
    911919     */
    912     private function shouldInsertProperty($propertyId, $status, $mlsImportItemStatus, $tipImport) {
     920    private function shouldInsertProperty($propertyId, $status, $mlsImportItemStatus, $tipImport): string{
     921        $this->writeImportLogs(
     922            "Checking: on inserting {$propertyId}={$status} vs " .
     923            json_encode($mlsImportItemStatus) . " -- {$tipImport}" . PHP_EOL,
     924            $tipImport
     925        );
     926
     927        if ($propertyId !== 0 || !is_array($mlsImportItemStatus)) {
     928            return 'no';
     929        }
     930
     931        $activeStatuses = [
     932            'active',
     933            'active under contract',
     934            'active with contract',
     935            'activewithcontract',
     936            'status',
     937            'activeundercontract',
     938            'comingsoon',
     939            'coming soon',
     940            'pending'
     941        ];
     942        if(is_array($mlsImportItemStatus)){
     943            if (!in_array(strtolower($status), $mlsImportItemStatus, true)) {
     944                return 'no';
     945            }
     946   
     947            if ($tipImport === 'cron' && !in_array($status, $mlsImportItemStatus, true)) {
     948                return 'no';
     949            }
     950   
     951        }else{
     952            if(!in_array($status, $activeStatuses, true) ){
     953                return 'no';
     954            }
     955        }
     956   
     957        return 'yes';
     958    }
     959
     960   
     961    /**
     962     * Check for property status agains mls item delete status to see if we keep or delete the listing
     963     *
     964     *
     965     */
     966
     967     public function check_if_delete_when_status($property_id){
     968        $delete_status= get_post_meta( $property_id, 'mlsImportItemStatusDelete', true );
     969   
     970
     971        if (taxonomy_exists('property_status')) {
     972            // wpresidence
     973            $termObjList = get_the_terms($property_id, 'property_status');
     974        }else if(taxonomy_exists('property_label')){
     975            // houzez
     976            $termObjList = get_the_terms($property_id, 'property_label');
     977        } else {
     978            //real homes
     979            $termObjList = get_post_meta( $property_id, 'inspiry_property_label', true );
     980        }
     981
     982        //  property_label // houzez
     983        //  inspiry_property_label
    913984       
    914         if ($propertyId === 0) {
    915             if (in_array($status, ['active', 'active under contract', 'active with contract', 'activewithcontract', 'status', 'activeundercontract', 'comingsoon', 'coming soon', 'pending'])) {
    916                 if ($tipImport === 'cron' && !in_array($status, $mlsImportItemStatus)) {
    917                     return 'no';
    918                 }
    919                 return 'yes';
    920             }
    921             return 'no';
    922         }
    923         return 'no';
    924        
    925     }
     985        if(isset($termObjList) && is_array($termObjList)){
     986            $post_status = $termObjList[0]->name;
     987        }
     988
     989
     990        $keep=true;
     991        if(!empty($delete_status)){
     992           
     993            if(is_array($delete_status) && in_array($post_status, $delete_status)){
     994                $keep=false;
     995           
     996            }else if($post_status==$delete_status){
     997                $keep=false;
     998            }
     999
     1000        }
     1001
     1002        print  wp_kses_post('</br></br>' .$property_id. ' ------------------------- Kept: '.$property_id.' /'.$post_status.'<-');
     1003        var_dump($delete_status);
     1004        print '</br><br>';
     1005
     1006        return $keep;
     1007    }
     1008
     1009
     1010
    9261011
    9271012    /**
     
    9411026    private function updateExistingProperty($propertyId,$mlsImportItemStatusDelete, $content, $listingPostType, $newAuthor, $status, $mlsImportItemStatus, &$propertyHistory, $tipImport, $ListingKey) {
    9421027       
    943         if (is_array($mlsImportItemStatusDelete)) {
    944             $mlsImportItemStatusDelete = array_map('strtolower', $mlsImportItemStatusDelete);
    945         }
    946 
    947         if (is_array($mlsImportItemStatusDelete) &&  in_array($status, $mlsImportItemStatusDelete)) {
    948             $log = 'Property with ID ' . $propertyId . ' and with name ' . get_the_title($propertyId) . ' has a status of <strong>' . $status . '</strong> and will be deleted' . PHP_EOL;
    949             $this->deleteProperty($propertyId, $ListingKey);
    950             $this->writeImportLogs($log, $tipImport);
     1028       
     1029        $post = [
     1030            'ID' => $propertyId,
     1031            'post_content' => $content,
     1032            'post_type' => $listingPostType,
     1033            'post_author' => $newAuthor,
     1034        ];
     1035
     1036        $log = 'Property with ID ' . $propertyId . ' and with name ' . get_the_title($propertyId) . ' has a status of <strong>' . $status . '</strong> and will be Edited</br>';
     1037        $this->writeImportLogs($log, $tipImport);
     1038
     1039        $propertyId = wp_update_post($post);
     1040        if (is_wp_error($propertyId)) {
     1041            $this->writeImportLogs('ERROR: on edit ' . PHP_EOL, $tipImport);
    9511042        } else {
    952             $post = [
    953                 'ID' => $propertyId,
    954                 'post_content' => $content,
    955                 'post_type' => $listingPostType,
    956                 'post_author' => $newAuthor,
    957             ];
    958 
    959             $log = 'Property with ID ' . $propertyId . ' and with name ' . get_the_title($propertyId) . ' has a status of <strong>' . $status . '</strong> and will be Edited</br>';
    960             $this->writeImportLogs($log, $tipImport);
    961 
    962             $propertyId = wp_update_post($post);
    963             if (is_wp_error($propertyId)) {
    964                 $this->writeImportLogs('ERROR: on edit ' . PHP_EOL, $tipImport);
    965             } else {
    966                 $submitTitle = get_the_title($propertyId);
    967                 $propertyHistory[] = gmdate('F j, Y, g:i a') . ': Property with title: ' . $submitTitle . ', id:' . $propertyId . ', ListingKey:' . $ListingKey . ', Status:' . $status . ' will be edited';
    968             }
    969             clean_post_cache( $propertyId );
    970         }
    971 
     1043            $submitTitle = get_the_title($propertyId);
     1044            $propertyHistory[] = gmdate('F j, Y, g:i a') . ': Property with title: ' . $submitTitle . ', id:' . $propertyId . ', ListingKey:' . $ListingKey . ', Status:' . $status . ' will be edited';
     1045        }
     1046        clean_post_cache( $propertyId );
     1047       
    9721048        return $propertyHistory;
    9731049    }
  • mlsimport/tags/5.8.4/mlsimport.php

    r3144187 r3170241  
    44 * Plugin URI:        https://mlsimport.com/
    55 * Description:       "MLS Import - The MLSImport plugin facilitates the connection to your real estate MLS database, allowing you to download and synchronize real estate property data from the MLS.
    6  * Version:           5.8.3
     6 * Version:           5.8.4
    77 * Requires at least: 5.2
    88 * Requires PHP:      7.2
     
    2121
    2222
    23 define( 'MLSIMPORT_VERSION', '5.8.2' );
     23define( 'MLSIMPORT_VERSION', '5.8.4' );
    2424define( 'MLSIMPORT_CLUBLINK', 'mlsimport.com' );
    2525define( 'MLSIMPORT_CLUBLINKSSL', 'https' );
  • mlsimport/trunk/admin/class-mlsimport-admin.php

    r3134790 r3170241  
    543543    public function mlsimport_hidden_fields() {
    544544        global $post;
     545
    545546        $options = get_option( $this->plugin_name . '_admin_fields_select' );
    546         echo  'ListingKey: '.get_post_meta( $post->ID, 'ListingKey', true ).'<br>';
     547
     548        $MLSimport_item_inserted = get_post_meta( $post->ID, 'MLSimport_item_inserted', true );
     549        $MLSimport_item_updated = get_post_meta( $post->ID, 'MLSimport_item_updated', true );
     550        $listing_key = get_post_meta( $post->ID, 'ListingKey', true );
     551        $mlsImportItemStatusDelete = get_post_meta($post->ID, 'mlsImportItemStatusDelete', true);
     552
     553
     554
     555        // Check if the ListingKey exists
     556        if ( !empty( $listing_key ) ) {
     557            echo 'ListingKey: ' . $listing_key . '<br>';
     558        }
     559
     560        // Check if MLSimport_item_inserted exists
     561        if ( !empty( $MLSimport_item_inserted ) ) {
     562            echo 'Added via MLS item id: ' . $MLSimport_item_inserted . ' - ' . get_the_title( $MLSimport_item_inserted ) . '<br>';
     563        }
     564
     565        // Check if MLSimport_item_updated exists
     566        if ( !empty( $MLSimport_item_updated ) ) {
     567            echo 'Updated via MLS item id: ' . $MLSimport_item_updated . ' - ' . get_the_title( $MLSimport_item_updated ) . '<br>';
     568        }
     569
     570
     571        if(!empty($mlsImportItemStatusDelete)) {
     572            if(is_array($mlsImportItemStatusDelete)) {
     573               
     574                echo 'Do not delete if status: ' .  implode(',' ,$mlsImportItemStatusDelete) . '<br>';
     575            } else {
     576
     577                echo 'Do not delete if status: ' .  esc_html($mlsImportItemStatusDelete) . '<br>';
     578
     579            }
     580           
     581        }
     582
    547583        foreach ( $options['mls-fields-admin'] as $key => $value ) {
    548584            if ( 1 === intval($options['mls-fields-admin'][ $key ] ) ) {
     
    663699                    }
    664700
    665                     $mlsimport->admin->theme_importer->mlsimport_saas_delete_property_via_mysql( $delete_get_id, ' delete from tools ' );
     701                    $mlsimport->admin->theme_importer->mlsimportSaasDeletePropertyViaMysql( $delete_get_id, ' delete from tools ' );
    666702                }
    667703
     
    13551391            $last_date = $this->mlsimport_saas_update_last_date( $item_id );
    13561392        }
    1357 
    13581393        return $last_date;
    13591394    }
     
    13681403
    13691404        $unix_time         = current_time( 'timestamp', 0 ) - ( 2 * 60 * 60 );
    1370         $last_date_to_save = date( 'Y-m-d\TH:i', $unix_time );
     1405        print $last_date_to_save = date( 'Y-m-d\TH:i', $unix_time );
    13711406        update_post_meta( $item_id, 'mlsimport_last_date', $last_date_to_save );
    13721407
     
    13841419
    13851420        $last_date = $this->mlsimport_saas_get_last_date( $item_id );
    1386 
    1387         esc_html_e('we work with','mlsimport').' '. esc_html($last_date ). PHP_EOL;
     1421        print 'MLSitem id: '.$item_id.' - ';
     1422        esc_html_e('date to consider: ','mlsimport');
     1423        print esc_html($last_date ). '. ';
    13881424
    13891425        $mlsrequest  = $this->mlsimport_make_listing_requests( $item_id, $last_date );
     1426   
    13901427        $found_items = 0;
    13911428        if ( isset( $mlsrequest['results'] ) ) {
     
    13951432        }
    13961433
    1397         print esc_html__('we found ','mlsimport') .esc_html( $found_items ). '</br>' . PHP_EOL;
     1434        print esc_html__('We found ','mlsimport') .esc_html( $found_items ). ' listings.</br>' . PHP_EOL;
    13981435
    13991436        $attachments_to_move = array();
     
    14431480            return;
    14441481        }
    1445 
     1482 
    14461483
    14471484        $mls_data          = $this->mlsimport_saas_get_mls_reconciliation_data();
     
    14581495                $property_id = $item->iD;
    14591496                ++$counter;
     1497
     1498            //print '</br>'.$counter. ' **************************</br>';
    14601499           
    1461             if ( in_array( $listingkey, $listingKey_in_MLS ) ) {
     1500            if ( in_array( $listingkey, $listingKey_in_MLS )  ) {
    14621501                print  wp_kses_post('</br>'.$listingkey .  ' IS FOUND');
    14631502            } else {
    1464                 $delete_status= get_post_meta( $property_id, 'mlsImportItemStatusDelete', true );
    1465 
    1466                 if($delete_status=='' || $delete_status=='delete'){
     1503               
     1504                $keep = $mlsimport->admin->theme_importer->check_if_delete_when_status($property_id);
     1505
     1506                if(!$keep){
    14671507                    ++$to_delete;
    1468                     print  wp_kses_post('</br>' .$listingkey. ' ------------------------- NOT FOUND delete: '.$property_id.' <-');
    1469                 //  $mlsimport->admin->theme_importer->mlsimport_saas_delete_property_via_mysql( $property_id, $listingkey );
     1508                    print  wp_kses_post('</br>' .$listingkey. ' ------------------------- NOT FOUND delete: '.$property_id.' /'.$post_status.'<-');
     1509                    $mlsimport->admin->theme_importer->mlsimportSaasDeletePropertyViaMysql( $property_id, $listingkey );
    14701510                }else{ 
    1471                     print  wp_kses_post('</br>' .$listingkey. ' ------------------------- NOT FOUND BUT MARKED AS KEEP: '.$property_id.' / '.$delete_status.'<-');
     1511                    print  wp_kses_post('</br>' .$listingkey. ' ------------------------- NOT FOUND BUT MARKED AS KEEP: '.$property_id.' /'.$post_status.'<-');
    14721512                }
    14731513
    14741514            }
     1515
     1516            //print '</br> ************************** ';
    14751517        }
    14761518
     
    18321874        }
    18331875
     1876
    18341877        $permited_status=array('active','active under contract','coming soon','activeundercontract','comingsoon','pending');
    18351878        $permited_status_lower = array_map('strtolower', $permited_status);
    18361879
    18371880        // Filter out permitted statuses from array1 values
    1838         $standardstatus_delete_array = array_filter($standardstatus_delete_array, function ($value) use ($permited_status_lower) {
    1839             return !in_array(strtolower($value), $permited_status_lower);
    1840         });
     1881    //  $standardstatus_delete_array = array_filter($standardstatus_delete_array, function ($value) use ($permited_status_lower) {
     1882    //      return !in_array(strtolower($value), $permited_status_lower);
     1883//      });
    18411884
    18421885   
     
    19101953            'StandardStatusDelete'                 => array(
    19111954                'label'       => esc_html__( 'Delete Statuses', 'mlsimport' ),
    1912                 'description' => __( 'If you edit the Delete Statuses after importing listings, the changes will NOT apply to listings that have already been imported.', 'mlsimport' ),
     1955                'description' => __( 'Properties with these statuses will be deleted from your website after they are removed from MLS database. If you edit the field after importing, the changes will NOT apply to listings that have already been imported.', 'mlsimport' ),
    19131956                'type'        => 'select',
    19141957                'multiple'    => 'yes',
  • mlsimport/trunk/admin/partials/mlsimport-administrative-options.php

    r3134790 r3170241  
    2626        $options = get_option( $this->plugin_name . '_administrative_options' );
    2727        $mlsimport->admin->mlsimport_saas_setting_up();
    28         // mlsimport_saas_event_mls_import_auto_function();
    29          //mlsimport_saas_reconciliation_event_function();
     28        //mlsimport_saas_event_mls_import_auto_function();
     29        //mlsimport_saas_reconciliation_event_function();
    3030    ?>
    31 
     31 
    3232<h1> Administrative Tools</h1>
    3333
  • mlsimport/trunk/includes/ThemeImport.php

    r3144187 r3170241  
    823823        }
    824824
    825         if (!isset($property['ListingKey'])) {
     825        if (!isset($property['ListingKey']) || empty($property['ListingKey'])) {
    826826            $this->writeImportLogs('ERROR: No Listing Key ' . PHP_EOL, $tipImport);
    827827            return;
     
    834834        $propertyId         = intval($this->mlsimportSaasRetrievePropertyById($ListingKey, $listingPostType));
    835835        $status             = isset($property['StandardStatus']) ? strtolower($property['StandardStatus']) : strtolower($property['extra_meta']['MlsStatus']);
     836       
     837       
     838        $this->writeImportLogs('FIxing: on inserting ' .$status.'-->'.json_encode($mlsImportItemStatus). PHP_EOL, $tipImport);
     839
     840
    836841        $isInsert           = $this->shouldInsertProperty($propertyId, $status, $mlsImportItemStatus, $tipImport);
    837842
     
    851856                'post_author'   => $newAuthor,
    852857            ];
    853 
     858 
    854859            $propertyId = wp_insert_post($post);
    855860            if (is_wp_error($propertyId)) {
     
    857862            } else {
    858863                update_post_meta($propertyId, 'ListingKey', $ListingKey);
    859                 $keep_on_delete='delete';
    860                 if( is_array($mlsImportItemStatusDelete) && !in_array($status,$mlsImportItemStatusDelete)){
    861                     $keep_on_delete='keep';
    862                     update_post_meta($propertyId, 'mlsImportItemStatusDelete', $keep_on_delete);
    863                 }
    864 
    865 
    866    
    867            
     864                update_post_meta($propertyId, 'MLSimport_item_inserted', $itemIdArray['item_id'],);
     865                update_post_meta($propertyId, 'mlsImportItemStatusDelete', $mlsImportItemStatusDelete);
     866
     867               
    868868               
    869869                $propertyHistory[] = date('F j, Y, g:i a') . ': We Inserted the property with Default title :  ' . $submitTitle . ' and received id:' . $propertyId.'. The delete statuses are '.$keep_on_delete;
     
    874874        } elseif ($propertyId !== 0) {
    875875
    876             $keep_on_delete='delete';
    877             if(is_array($mlsImportItemStatusDelete) &&  !in_array($status,$mlsImportItemStatusDelete)){
    878                 $keep_on_delete='keep';
    879                 update_post_meta($propertyId, 'mlsImportItemStatusDelete', $keep_on_delete);
    880             }
    881 
    882             $propertyHistory = $this->updateExistingProperty($propertyId,$mlsImportItemStatusDelete, $content, $listingPostType, $newAuthor, $status, $mlsImportItemStatus, $propertyHistory, $tipImport, $ListingKey);
    883         }
     876            $keep = $this->check_if_delete_when_status($property_id);
     877
     878            if(!$keep){
     879                $log = 'Property with ID ' . $propertyId . ' and with name ' . get_the_title($propertyId) . ' has a status of <strong>' . $status . ' / '.$post_status.'</strong> and will be deleted' . PHP_EOL;
     880                $this->deleteProperty($propertyId, $ListingKey);
     881                $this->writeImportLogs($log, $tipImport);
     882            }else{ 
     883                update_post_meta($propertyId, 'mlsImportItemStatusDelete', $mlsImportItemStatusDelete);
     884                $propertyHistory = $this->updateExistingProperty($propertyId,$mlsImportItemStatusDelete, $content, $listingPostType, $newAuthor, $status, $mlsImportItemStatus, $propertyHistory, $tipImport, $ListingKey);
     885            }
     886        }
     887
     888
     889
     890
     891
    884892
    885893        if ($propertyId === 0) {
     
    910918     * @return string 'yes' or 'no' indicating if the property should be inserted.
    911919     */
    912     private function shouldInsertProperty($propertyId, $status, $mlsImportItemStatus, $tipImport) {
     920    private function shouldInsertProperty($propertyId, $status, $mlsImportItemStatus, $tipImport): string{
     921        $this->writeImportLogs(
     922            "Checking: on inserting {$propertyId}={$status} vs " .
     923            json_encode($mlsImportItemStatus) . " -- {$tipImport}" . PHP_EOL,
     924            $tipImport
     925        );
     926
     927        if ($propertyId !== 0 || !is_array($mlsImportItemStatus)) {
     928            return 'no';
     929        }
     930
     931        $activeStatuses = [
     932            'active',
     933            'active under contract',
     934            'active with contract',
     935            'activewithcontract',
     936            'status',
     937            'activeundercontract',
     938            'comingsoon',
     939            'coming soon',
     940            'pending'
     941        ];
     942        if(is_array($mlsImportItemStatus)){
     943            if (!in_array(strtolower($status), $mlsImportItemStatus, true)) {
     944                return 'no';
     945            }
     946   
     947            if ($tipImport === 'cron' && !in_array($status, $mlsImportItemStatus, true)) {
     948                return 'no';
     949            }
     950   
     951        }else{
     952            if(!in_array($status, $activeStatuses, true) ){
     953                return 'no';
     954            }
     955        }
     956   
     957        return 'yes';
     958    }
     959
     960   
     961    /**
     962     * Check for property status agains mls item delete status to see if we keep or delete the listing
     963     *
     964     *
     965     */
     966
     967     public function check_if_delete_when_status($property_id){
     968        $delete_status= get_post_meta( $property_id, 'mlsImportItemStatusDelete', true );
     969   
     970
     971        if (taxonomy_exists('property_status')) {
     972            // wpresidence
     973            $termObjList = get_the_terms($property_id, 'property_status');
     974        }else if(taxonomy_exists('property_label')){
     975            // houzez
     976            $termObjList = get_the_terms($property_id, 'property_label');
     977        } else {
     978            //real homes
     979            $termObjList = get_post_meta( $property_id, 'inspiry_property_label', true );
     980        }
     981
     982        //  property_label // houzez
     983        //  inspiry_property_label
    913984       
    914         if ($propertyId === 0) {
    915             if (in_array($status, ['active', 'active under contract', 'active with contract', 'activewithcontract', 'status', 'activeundercontract', 'comingsoon', 'coming soon', 'pending'])) {
    916                 if ($tipImport === 'cron' && !in_array($status, $mlsImportItemStatus)) {
    917                     return 'no';
    918                 }
    919                 return 'yes';
    920             }
    921             return 'no';
    922         }
    923         return 'no';
    924        
    925     }
     985        if(isset($termObjList) && is_array($termObjList)){
     986            $post_status = $termObjList[0]->name;
     987        }
     988
     989
     990        $keep=true;
     991        if(!empty($delete_status)){
     992           
     993            if(is_array($delete_status) && in_array($post_status, $delete_status)){
     994                $keep=false;
     995           
     996            }else if($post_status==$delete_status){
     997                $keep=false;
     998            }
     999
     1000        }
     1001
     1002        print  wp_kses_post('</br></br>' .$property_id. ' ------------------------- Kept: '.$property_id.' /'.$post_status.'<-');
     1003        var_dump($delete_status);
     1004        print '</br><br>';
     1005
     1006        return $keep;
     1007    }
     1008
     1009
     1010
    9261011
    9271012    /**
     
    9411026    private function updateExistingProperty($propertyId,$mlsImportItemStatusDelete, $content, $listingPostType, $newAuthor, $status, $mlsImportItemStatus, &$propertyHistory, $tipImport, $ListingKey) {
    9421027       
    943         if (is_array($mlsImportItemStatusDelete)) {
    944             $mlsImportItemStatusDelete = array_map('strtolower', $mlsImportItemStatusDelete);
    945         }
    946 
    947         if (is_array($mlsImportItemStatusDelete) &&  in_array($status, $mlsImportItemStatusDelete)) {
    948             $log = 'Property with ID ' . $propertyId . ' and with name ' . get_the_title($propertyId) . ' has a status of <strong>' . $status . '</strong> and will be deleted' . PHP_EOL;
    949             $this->deleteProperty($propertyId, $ListingKey);
    950             $this->writeImportLogs($log, $tipImport);
     1028       
     1029        $post = [
     1030            'ID' => $propertyId,
     1031            'post_content' => $content,
     1032            'post_type' => $listingPostType,
     1033            'post_author' => $newAuthor,
     1034        ];
     1035
     1036        $log = 'Property with ID ' . $propertyId . ' and with name ' . get_the_title($propertyId) . ' has a status of <strong>' . $status . '</strong> and will be Edited</br>';
     1037        $this->writeImportLogs($log, $tipImport);
     1038
     1039        $propertyId = wp_update_post($post);
     1040        if (is_wp_error($propertyId)) {
     1041            $this->writeImportLogs('ERROR: on edit ' . PHP_EOL, $tipImport);
    9511042        } else {
    952             $post = [
    953                 'ID' => $propertyId,
    954                 'post_content' => $content,
    955                 'post_type' => $listingPostType,
    956                 'post_author' => $newAuthor,
    957             ];
    958 
    959             $log = 'Property with ID ' . $propertyId . ' and with name ' . get_the_title($propertyId) . ' has a status of <strong>' . $status . '</strong> and will be Edited</br>';
    960             $this->writeImportLogs($log, $tipImport);
    961 
    962             $propertyId = wp_update_post($post);
    963             if (is_wp_error($propertyId)) {
    964                 $this->writeImportLogs('ERROR: on edit ' . PHP_EOL, $tipImport);
    965             } else {
    966                 $submitTitle = get_the_title($propertyId);
    967                 $propertyHistory[] = gmdate('F j, Y, g:i a') . ': Property with title: ' . $submitTitle . ', id:' . $propertyId . ', ListingKey:' . $ListingKey . ', Status:' . $status . ' will be edited';
    968             }
    969             clean_post_cache( $propertyId );
    970         }
    971 
     1043            $submitTitle = get_the_title($propertyId);
     1044            $propertyHistory[] = gmdate('F j, Y, g:i a') . ': Property with title: ' . $submitTitle . ', id:' . $propertyId . ', ListingKey:' . $ListingKey . ', Status:' . $status . ' will be edited';
     1045        }
     1046        clean_post_cache( $propertyId );
     1047       
    9721048        return $propertyHistory;
    9731049    }
  • mlsimport/trunk/mlsimport.php

    r3144187 r3170241  
    44 * Plugin URI:        https://mlsimport.com/
    55 * Description:       "MLS Import - The MLSImport plugin facilitates the connection to your real estate MLS database, allowing you to download and synchronize real estate property data from the MLS.
    6  * Version:           5.8.3
     6 * Version:           5.8.4
    77 * Requires at least: 5.2
    88 * Requires PHP:      7.2
     
    2121
    2222
    23 define( 'MLSIMPORT_VERSION', '5.8.2' );
     23define( 'MLSIMPORT_VERSION', '5.8.4' );
    2424define( 'MLSIMPORT_CLUBLINK', 'mlsimport.com' );
    2525define( 'MLSIMPORT_CLUBLINKSSL', 'https' );
Note: See TracChangeset for help on using the changeset viewer.