Plugin Directory

Changeset 3376210


Ignore:
Timestamp:
10/10/2025 11:53:46 AM (5 months ago)
Author:
crowdaa
Message:

Added version 2.2.0, which include some important bug fixes

Location:
crowdaa-sync
Files:
6 edited
44 copied

Legend:

Unmodified
Added
Removed
  • crowdaa-sync/tags/2.2.0/CHANGELOG

    r3274443 r3376210  
    77
    88## [Unreleased]
     9
     10## [2.2.0] - 2025-10-10
     11
     12### Changed
     13
     14- Fixed issue where categories would be synced twice for no reason
     15- Fixed crash on WP>API sync where the API ID was not properly recorded, which may have caused articles to be duplicated
     16- Fixed post metadata that were not being updated on API>WP sync
     17- Removed articles deletion when previous articles are now in a blacklisted category
     18- Now filtering blacklisted/whitelisted categories for articles for the API>WP sync
     19- Commented code that were removing synced categories ID during opqueue building, which may have cause categories to be duplicated
    920
    1021## [2.1.1] - 2025-04-16
  • crowdaa-sync/tags/2.2.0/README.txt

    r3274443 r3376210  
    66Requires PHP: 7.3
    77Tested up to: 5.9
    8 Stable tag: 2.1.1
     8Stable tag: 2.2.0
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • crowdaa-sync/tags/2.2.0/admin/class-crowdaa-sync-add-info-api.php

    r3229463 r3376210  
    146146      'name'        => $term->name,
    147147      'slug'        => $term->slug,
    148       'parent'      => $term->parent,
     148      'parent'      => $term->parent . '',
    149149    ];
    150150
     
    158158    $data['isEvent'] = (get_term_meta($term->term_id, 'crowdaa_is_event', true) === 'yes');
    159159    if (isset($term->rootParentId)) {
    160       $data['rootParentId'] = $term->rootParentId;
     160      $data['rootParentId'] = $term->rootParentId . '';
    161161    }
    162162
     
    509509      $item->term_hash = $item->sync_data['term_hash'];
    510510      if ($sync_categories_mode === 'whitelist' && !in_array($item->wp_id, $sync_categories_list)) {
    511         $sync_db->delete_entry(['id' => $item->id]);
     511        // Do not do : $sync_db->delete_entry(['id' => $item->id]);
    512512      } else if ($sync_categories_mode === 'blacklist' && in_array($item->wp_id, $sync_categories_list)) {
    513         $sync_db->delete_entry(['id' => $item->id]);
     513        // Do not do : $sync_db->delete_entry(['id' => $item->id]);
    514514      } else {
    515515        $synced_by_wp_id[$item->wp_id] = $item;
     
    10731073  }
    10741074
    1075 
    1076   private function remove_already_synced_post($post_id)
    1077   {
    1078     $sync_api = new Crowdaa_Sync_API();
    1079     $api_post_id = get_post_meta($post_id, 'api_post_id', true);
    1080 
    1081     if ($api_post_id) {
    1082       try {
    1083         $sync_api->delete_post_api($api_post_id);
    1084       } catch (\Throwable $e) {
    1085         /* Do nothing */
    1086       }
    1087     }
    1088 
    1089     delete_post_meta($post_id, 'crowdaa_need_sync');
    1090     delete_post_meta($post_id, 'crowdaa_version');
    1091     delete_post_meta($post_id, 'crowdaa_last_api_update');
    1092     delete_post_meta($post_id, 'crowdaa_last_wp_update');
    1093     delete_post_meta($post_id, 'api_post_id');
    1094   }
     1075  // private function remove_already_synced_post($post_id)
     1076  // {
     1077  //   $sync_api = new Crowdaa_Sync_API();
     1078  //   $api_post_id = get_post_meta($post_id, 'api_post_id', true);
     1079
     1080  //   if ($api_post_id) {
     1081  //     try {
     1082  //       $sync_api->delete_post_api($api_post_id);
     1083  //     } catch (\Throwable $e) {
     1084  //       /* Do nothing */
     1085  //     }
     1086  //   }
     1087
     1088  //   delete_post_meta($post_id, 'crowdaa_need_sync');
     1089  //   delete_post_meta($post_id, 'crowdaa_version');
     1090  //   delete_post_meta($post_id, 'crowdaa_last_api_update');
     1091  //   delete_post_meta($post_id, 'crowdaa_last_wp_update');
     1092  //   delete_post_meta($post_id, 'api_post_id');
     1093  // }
    10951094
    10961095  public function sync_badges_api(
     
    13281327        $api_post_id = get_post_meta($post['post_id'], 'api_post_id');
    13291328        if ($api_post_id) {
    1330           Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API');
    1331           $this->remove_already_synced_post($post['post_id']);
     1329          Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API (code disabled)');
     1330          // $this->remove_already_synced_post($post['post_id']);
    13321331        }
    13331332
     
    13371336        $api_post_id = get_post_meta($post['post_id'], 'api_post_id');
    13381337        if ($api_post_id) {
    1339           Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API');
    1340           $this->remove_already_synced_post($post['post_id']);
     1338          Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API (code disabled)');
     1339          // $this->remove_already_synced_post($post['post_id']);
    13411340        }
    13421341
     
    13501349          $api_post_id = get_post_meta($post['post_id'], 'api_post_id');
    13511350          if ($api_post_id) {
    1352             Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API');
    1353             $this->remove_already_synced_post($post['post_id']);
     1351            Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API (code disabled)');
     1352            // $this->remove_already_synced_post($post['post_id']);
    13541353          }
    13551354
     
    13661365        }
    13671366        if (!$api_term_ids) {
    1368           throw new Crowdaa_Sync_Post_Error('Could not find synced category for term ' . $term->term_id . '. This should not happen, aborting sync.');
     1367          throw new Crowdaa_Sync_Post_Error('Could not find synced category for terms (' . implode(', ', $allowed_term_ids) . '). This should not happen, aborting sync.');
    13691368
    13701369          continue;
     
    13841383        // Update post
    13851384        if (in_array($post, $only_wp, true)) {
    1386           $sync_api->create_post_api($api_term_ids, $post['post_id'], $feed_display);
     1385          $post['api_id'] = $sync_api->create_post_api($api_term_ids, $post['post_id'], $feed_display);
    13871386        } else {
    13881387          $sync_api->update_draft_post_api($api_term_ids, $post['post_id'], $post['api_id'], $feed_display);
  • crowdaa-sync/tags/2.2.0/admin/class-crowdaa-sync-add-info-wp.php

    r3274443 r3376210  
    217217    $errors = [];
    218218    $api_data_class = new Crowdaa_Sync_API();
     219    $cat_sync_db    = Crowdaa_Sync_Syncdb::instance('categories');
    219220    $posts_sync_to_wp = array_merge($api_to_wp, $only_api);
     221
     222    $sync_categories_mode = get_option('crowdaa_sync_categories_mode', 'blacklist');
     223    $sync_categories_list = get_option('crowdaa_sync_categories_list', '');
     224    if ($sync_categories_list === '') {
     225      $sync_categories_list = [];
     226    } else {
     227      $sync_categories_list = explode(',', $sync_categories_list);
     228    }
    220229
    221230    foreach ($posts_sync_to_wp as $postArrayId => $api_post) {
     
    234243
    235244      try {
     245        $is_only_api = in_array($api_post, $only_api, true);
     246        if (isset($api_whole_post->categories) && count($api_whole_post->categories) > 0) {
     247          $api_ids = [];
     248          foreach ($api_whole_post->categories as $category) {
     249            $api_ids[] = $category->_id;
     250          }
     251          $terms = $cat_sync_db->get_entries_with_api_ids($api_ids, 'wp_id');
     252          $terms = Crowdaa_Sync_Utils::object_array_extract_field('wp_id', $terms);
     253        } else {
     254          $term = $cat_sync_db->get_entry_with_api_id($api_whole_post->category->_id, 'wp_id');
     255          $terms = [(int) $term->wp_id];
     256        }
     257
     258        $whitelisted = ($sync_categories_mode !== 'whitelist');
     259        $blacklisted = false;
     260        $allowed_term_ids = [];
     261        foreach ($terms as $termId) {
     262          if (in_array($termId, $sync_categories_list)) {
     263            if ($sync_categories_mode === 'blacklist') {
     264              $blacklisted = $termId;
     265              break;
     266            } else {
     267              $whitelisted = $termId;
     268              $allowed_term_ids[] = $termId;
     269            }
     270          } else if (
     271            $sync_categories_mode !== 'whitelist' &&
     272            !$blacklisted
     273          ) {
     274            $allowed_term_ids[] = $termId;
     275          }
     276        }
     277
     278        if (!$whitelisted) {
     279          Crowdaa_Sync_Logs::log('Could not find a whitelisted category for this article, skipping');
     280          if (!$is_only_api) {
     281            Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from WP (code disabled)');
     282            // $this->remove_already_synced_post($post['post_id']);
     283          }
     284
     285          continue;
     286        } else if ($blacklisted) {
     287          Crowdaa_Sync_Logs::log('Blacklisted category', $blacklisted, 'skipping');
     288          if (!$is_only_api) {
     289            Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from WP (code disabled)');
     290            // $this->remove_already_synced_post($post['post_id']);
     291          }
     292
     293          continue;
     294        }
     295
     296        $can_sync = apply_filters('crowdaa_sync_can_sync_api_post', true, $api_whole_post, $is_only_api ? null : $api_post['post_id']);
     297        if (!$can_sync) {
     298          Crowdaa_Sync_Logs::log('Post sync denied by "crowdaa_sync_can_sync_api_post" filter');
     299          if (!$is_only_api) {
     300            Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from WP (code disabled)');
     301            // $this->remove_already_synced_post($api_whole_post);
     302          }
     303
     304          continue;
     305        }
     306
    236307        if (in_array($api_post, $only_api, true)) {
    237           $sync_errors = $this->create_wp_post_from_api($api_whole_post);
     308          $sync_errors = $this->create_wp_post_from_api($allowed_term_ids, $api_whole_post);
    238309        } else {
    239           $sync_errors = $this->update_wp_post_from_api($api_whole_post, $api_post['post_id']);
     310          $sync_errors = $this->update_wp_post_from_api($allowed_term_ids, $api_whole_post, $api_post['post_id']);
    240311        }
    241312        $errors += $sync_errors;
     
    259330  }
    260331
    261   private function create_wp_post_from_api($api_data)
    262   {
    263     $cat_sync_db    = Crowdaa_Sync_Syncdb::instance('categories');
    264 
    265     if (isset($api_data->categories) && count($api_data->categories) > 0) {
    266       $api_ids = [];
    267       foreach ($api_data->categories as $category) {
    268         $api_ids[] = $category->_id;
    269       }
    270       $terms = $cat_sync_db->get_entries_with_api_ids($api_ids, 'wp_id');
    271       $terms = Crowdaa_Sync_Utils::object_array_extract_field('wp_id', $terms);
    272     } else {
    273       $term = $cat_sync_db->get_entry_with_api_id($api_data->category->_id, 'wp_id');
    274       $terms = [(int) $term->wp_id];
    275     }
    276 
     332  private function create_wp_post_from_api($terms, $api_data)
     333  {
    277334    $publicationTime = self::api_date_to_unix($api_data->publicationDate);
    278335    $post_data = [
     
    346403  }
    347404
    348   private function update_wp_post_from_api($api_data, $wp_post_id)
    349   {
    350     $cat_sync_db    = Crowdaa_Sync_Syncdb::instance('categories');
    351 
    352     if (isset($api_data->categories) && count($api_data->categories) > 0) {
    353       $api_ids = [];
    354       foreach ($api_data->categories as $category) {
    355         $api_ids[] = $category->_id;
    356       }
    357       $terms = $cat_sync_db->get_entries_with_api_ids($api_ids, 'wp_id');
    358       $terms = Crowdaa_Sync_Utils::object_array_extract_field('wp_id', $terms);
    359     } else {
    360       $term = $cat_sync_db->get_entry_with_api_id($api_data->category->_id, 'wp_id');
    361       $terms = [(int) $term->wp_id];
    362     }
    363 
     405  private function update_wp_post_from_api($terms, $api_data, $wp_post_id)
     406  {
    364407    $publicationTime = self::api_date_to_unix($api_data->publicationDate);
    365408    $data = [
  • crowdaa-sync/tags/2.2.0/admin/class-crowdaa-sync-api.php

    r3274443 r3376210  
    596596        }
    597597
    598         update_post_meta($wp_post_id, 'api_post_id', $json->articleId);
    599598        if ($send_notification) {
    600599          update_post_meta($wp_post_id, 'crowdaa_notification_sent', 'yes');
     
    603602        Crowdaa_Sync_Logs::log('Created API post', $json->articleId);
    604603      }
     604
     605      update_post_meta($wp_post_id, 'api_post_id', $json->articleId);
    605606
    606607      return $json->articleId;
  • crowdaa-sync/tags/2.2.0/crowdaa-sync.php

    r3274443 r3376210  
    1414 * Plugin URI:       
    1515 * Description:       Plugin for synchronizing WordPress site and Crowdaa CMS
    16  * Version:           2.1.1
     16 * Version:           2.2.0
    1717 * Requires at least: 5.5
    1818 * Requires PHP:      7.2
     
    3434 * Uses SemVer - https://semver.org
    3535 */
    36 define('CROWDAA_SYNC_VERSION', '2.1.1');
     36define('CROWDAA_SYNC_VERSION', '2.2.0');
    3737define('CROWDAA_SYNC_PLUGIN_DIR', __DIR__);
    3838define('CROWDAA_SYNC_PLUGIN_NAME', 'crowdaa-sync');
  • crowdaa-sync/trunk/CHANGELOG

    r3274443 r3376210  
    77
    88## [Unreleased]
     9
     10## [2.2.0] - 2025-10-10
     11
     12### Changed
     13
     14- Fixed issue where categories would be synced twice for no reason
     15- Fixed crash on WP>API sync where the API ID was not properly recorded, which may have caused articles to be duplicated
     16- Fixed post metadata that were not being updated on API>WP sync
     17- Removed articles deletion when previous articles are now in a blacklisted category
     18- Now filtering blacklisted/whitelisted categories for articles for the API>WP sync
     19- Commented code that were removing synced categories ID during opqueue building, which may have cause categories to be duplicated
    920
    1021## [2.1.1] - 2025-04-16
  • crowdaa-sync/trunk/README.txt

    r3274443 r3376210  
    66Requires PHP: 7.3
    77Tested up to: 5.9
    8 Stable tag: 2.1.1
     8Stable tag: 2.2.0
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • crowdaa-sync/trunk/admin/class-crowdaa-sync-add-info-api.php

    r3229463 r3376210  
    146146      'name'        => $term->name,
    147147      'slug'        => $term->slug,
    148       'parent'      => $term->parent,
     148      'parent'      => $term->parent . '',
    149149    ];
    150150
     
    158158    $data['isEvent'] = (get_term_meta($term->term_id, 'crowdaa_is_event', true) === 'yes');
    159159    if (isset($term->rootParentId)) {
    160       $data['rootParentId'] = $term->rootParentId;
     160      $data['rootParentId'] = $term->rootParentId . '';
    161161    }
    162162
     
    509509      $item->term_hash = $item->sync_data['term_hash'];
    510510      if ($sync_categories_mode === 'whitelist' && !in_array($item->wp_id, $sync_categories_list)) {
    511         $sync_db->delete_entry(['id' => $item->id]);
     511        // Do not do : $sync_db->delete_entry(['id' => $item->id]);
    512512      } else if ($sync_categories_mode === 'blacklist' && in_array($item->wp_id, $sync_categories_list)) {
    513         $sync_db->delete_entry(['id' => $item->id]);
     513        // Do not do : $sync_db->delete_entry(['id' => $item->id]);
    514514      } else {
    515515        $synced_by_wp_id[$item->wp_id] = $item;
     
    10731073  }
    10741074
    1075 
    1076   private function remove_already_synced_post($post_id)
    1077   {
    1078     $sync_api = new Crowdaa_Sync_API();
    1079     $api_post_id = get_post_meta($post_id, 'api_post_id', true);
    1080 
    1081     if ($api_post_id) {
    1082       try {
    1083         $sync_api->delete_post_api($api_post_id);
    1084       } catch (\Throwable $e) {
    1085         /* Do nothing */
    1086       }
    1087     }
    1088 
    1089     delete_post_meta($post_id, 'crowdaa_need_sync');
    1090     delete_post_meta($post_id, 'crowdaa_version');
    1091     delete_post_meta($post_id, 'crowdaa_last_api_update');
    1092     delete_post_meta($post_id, 'crowdaa_last_wp_update');
    1093     delete_post_meta($post_id, 'api_post_id');
    1094   }
     1075  // private function remove_already_synced_post($post_id)
     1076  // {
     1077  //   $sync_api = new Crowdaa_Sync_API();
     1078  //   $api_post_id = get_post_meta($post_id, 'api_post_id', true);
     1079
     1080  //   if ($api_post_id) {
     1081  //     try {
     1082  //       $sync_api->delete_post_api($api_post_id);
     1083  //     } catch (\Throwable $e) {
     1084  //       /* Do nothing */
     1085  //     }
     1086  //   }
     1087
     1088  //   delete_post_meta($post_id, 'crowdaa_need_sync');
     1089  //   delete_post_meta($post_id, 'crowdaa_version');
     1090  //   delete_post_meta($post_id, 'crowdaa_last_api_update');
     1091  //   delete_post_meta($post_id, 'crowdaa_last_wp_update');
     1092  //   delete_post_meta($post_id, 'api_post_id');
     1093  // }
    10951094
    10961095  public function sync_badges_api(
     
    13281327        $api_post_id = get_post_meta($post['post_id'], 'api_post_id');
    13291328        if ($api_post_id) {
    1330           Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API');
    1331           $this->remove_already_synced_post($post['post_id']);
     1329          Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API (code disabled)');
     1330          // $this->remove_already_synced_post($post['post_id']);
    13321331        }
    13331332
     
    13371336        $api_post_id = get_post_meta($post['post_id'], 'api_post_id');
    13381337        if ($api_post_id) {
    1339           Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API');
    1340           $this->remove_already_synced_post($post['post_id']);
     1338          Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API (code disabled)');
     1339          // $this->remove_already_synced_post($post['post_id']);
    13411340        }
    13421341
     
    13501349          $api_post_id = get_post_meta($post['post_id'], 'api_post_id');
    13511350          if ($api_post_id) {
    1352             Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API');
    1353             $this->remove_already_synced_post($post['post_id']);
     1351            Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API (code disabled)');
     1352            // $this->remove_already_synced_post($post['post_id']);
    13541353          }
    13551354
     
    13661365        }
    13671366        if (!$api_term_ids) {
    1368           throw new Crowdaa_Sync_Post_Error('Could not find synced category for term ' . $term->term_id . '. This should not happen, aborting sync.');
     1367          throw new Crowdaa_Sync_Post_Error('Could not find synced category for terms (' . implode(', ', $allowed_term_ids) . '). This should not happen, aborting sync.');
    13691368
    13701369          continue;
     
    13841383        // Update post
    13851384        if (in_array($post, $only_wp, true)) {
    1386           $sync_api->create_post_api($api_term_ids, $post['post_id'], $feed_display);
     1385          $post['api_id'] = $sync_api->create_post_api($api_term_ids, $post['post_id'], $feed_display);
    13871386        } else {
    13881387          $sync_api->update_draft_post_api($api_term_ids, $post['post_id'], $post['api_id'], $feed_display);
  • crowdaa-sync/trunk/admin/class-crowdaa-sync-add-info-wp.php

    r3274443 r3376210  
    217217    $errors = [];
    218218    $api_data_class = new Crowdaa_Sync_API();
     219    $cat_sync_db    = Crowdaa_Sync_Syncdb::instance('categories');
    219220    $posts_sync_to_wp = array_merge($api_to_wp, $only_api);
     221
     222    $sync_categories_mode = get_option('crowdaa_sync_categories_mode', 'blacklist');
     223    $sync_categories_list = get_option('crowdaa_sync_categories_list', '');
     224    if ($sync_categories_list === '') {
     225      $sync_categories_list = [];
     226    } else {
     227      $sync_categories_list = explode(',', $sync_categories_list);
     228    }
    220229
    221230    foreach ($posts_sync_to_wp as $postArrayId => $api_post) {
     
    234243
    235244      try {
     245        $is_only_api = in_array($api_post, $only_api, true);
     246        if (isset($api_whole_post->categories) && count($api_whole_post->categories) > 0) {
     247          $api_ids = [];
     248          foreach ($api_whole_post->categories as $category) {
     249            $api_ids[] = $category->_id;
     250          }
     251          $terms = $cat_sync_db->get_entries_with_api_ids($api_ids, 'wp_id');
     252          $terms = Crowdaa_Sync_Utils::object_array_extract_field('wp_id', $terms);
     253        } else {
     254          $term = $cat_sync_db->get_entry_with_api_id($api_whole_post->category->_id, 'wp_id');
     255          $terms = [(int) $term->wp_id];
     256        }
     257
     258        $whitelisted = ($sync_categories_mode !== 'whitelist');
     259        $blacklisted = false;
     260        $allowed_term_ids = [];
     261        foreach ($terms as $termId) {
     262          if (in_array($termId, $sync_categories_list)) {
     263            if ($sync_categories_mode === 'blacklist') {
     264              $blacklisted = $termId;
     265              break;
     266            } else {
     267              $whitelisted = $termId;
     268              $allowed_term_ids[] = $termId;
     269            }
     270          } else if (
     271            $sync_categories_mode !== 'whitelist' &&
     272            !$blacklisted
     273          ) {
     274            $allowed_term_ids[] = $termId;
     275          }
     276        }
     277
     278        if (!$whitelisted) {
     279          Crowdaa_Sync_Logs::log('Could not find a whitelisted category for this article, skipping');
     280          if (!$is_only_api) {
     281            Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from WP (code disabled)');
     282            // $this->remove_already_synced_post($post['post_id']);
     283          }
     284
     285          continue;
     286        } else if ($blacklisted) {
     287          Crowdaa_Sync_Logs::log('Blacklisted category', $blacklisted, 'skipping');
     288          if (!$is_only_api) {
     289            Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from WP (code disabled)');
     290            // $this->remove_already_synced_post($post['post_id']);
     291          }
     292
     293          continue;
     294        }
     295
     296        $can_sync = apply_filters('crowdaa_sync_can_sync_api_post', true, $api_whole_post, $is_only_api ? null : $api_post['post_id']);
     297        if (!$can_sync) {
     298          Crowdaa_Sync_Logs::log('Post sync denied by "crowdaa_sync_can_sync_api_post" filter');
     299          if (!$is_only_api) {
     300            Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from WP (code disabled)');
     301            // $this->remove_already_synced_post($api_whole_post);
     302          }
     303
     304          continue;
     305        }
     306
    236307        if (in_array($api_post, $only_api, true)) {
    237           $sync_errors = $this->create_wp_post_from_api($api_whole_post);
     308          $sync_errors = $this->create_wp_post_from_api($allowed_term_ids, $api_whole_post);
    238309        } else {
    239           $sync_errors = $this->update_wp_post_from_api($api_whole_post, $api_post['post_id']);
     310          $sync_errors = $this->update_wp_post_from_api($allowed_term_ids, $api_whole_post, $api_post['post_id']);
    240311        }
    241312        $errors += $sync_errors;
     
    259330  }
    260331
    261   private function create_wp_post_from_api($api_data)
    262   {
    263     $cat_sync_db    = Crowdaa_Sync_Syncdb::instance('categories');
    264 
    265     if (isset($api_data->categories) && count($api_data->categories) > 0) {
    266       $api_ids = [];
    267       foreach ($api_data->categories as $category) {
    268         $api_ids[] = $category->_id;
    269       }
    270       $terms = $cat_sync_db->get_entries_with_api_ids($api_ids, 'wp_id');
    271       $terms = Crowdaa_Sync_Utils::object_array_extract_field('wp_id', $terms);
    272     } else {
    273       $term = $cat_sync_db->get_entry_with_api_id($api_data->category->_id, 'wp_id');
    274       $terms = [(int) $term->wp_id];
    275     }
    276 
     332  private function create_wp_post_from_api($terms, $api_data)
     333  {
    277334    $publicationTime = self::api_date_to_unix($api_data->publicationDate);
    278335    $post_data = [
     
    346403  }
    347404
    348   private function update_wp_post_from_api($api_data, $wp_post_id)
    349   {
    350     $cat_sync_db    = Crowdaa_Sync_Syncdb::instance('categories');
    351 
    352     if (isset($api_data->categories) && count($api_data->categories) > 0) {
    353       $api_ids = [];
    354       foreach ($api_data->categories as $category) {
    355         $api_ids[] = $category->_id;
    356       }
    357       $terms = $cat_sync_db->get_entries_with_api_ids($api_ids, 'wp_id');
    358       $terms = Crowdaa_Sync_Utils::object_array_extract_field('wp_id', $terms);
    359     } else {
    360       $term = $cat_sync_db->get_entry_with_api_id($api_data->category->_id, 'wp_id');
    361       $terms = [(int) $term->wp_id];
    362     }
    363 
     405  private function update_wp_post_from_api($terms, $api_data, $wp_post_id)
     406  {
    364407    $publicationTime = self::api_date_to_unix($api_data->publicationDate);
    365408    $data = [
  • crowdaa-sync/trunk/admin/class-crowdaa-sync-api.php

    r3274443 r3376210  
    596596        }
    597597
    598         update_post_meta($wp_post_id, 'api_post_id', $json->articleId);
    599598        if ($send_notification) {
    600599          update_post_meta($wp_post_id, 'crowdaa_notification_sent', 'yes');
     
    603602        Crowdaa_Sync_Logs::log('Created API post', $json->articleId);
    604603      }
     604
     605      update_post_meta($wp_post_id, 'api_post_id', $json->articleId);
    605606
    606607      return $json->articleId;
  • crowdaa-sync/trunk/crowdaa-sync.php

    r3274443 r3376210  
    1414 * Plugin URI:       
    1515 * Description:       Plugin for synchronizing WordPress site and Crowdaa CMS
    16  * Version:           2.1.1
     16 * Version:           2.2.0
    1717 * Requires at least: 5.5
    1818 * Requires PHP:      7.2
     
    3434 * Uses SemVer - https://semver.org
    3535 */
    36 define('CROWDAA_SYNC_VERSION', '2.1.1');
     36define('CROWDAA_SYNC_VERSION', '2.2.0');
    3737define('CROWDAA_SYNC_PLUGIN_DIR', __DIR__);
    3838define('CROWDAA_SYNC_PLUGIN_NAME', 'crowdaa-sync');
Note: See TracChangeset for help on using the changeset viewer.