Plugin Directory

Changeset 2825896


Ignore:
Timestamp:
11/29/2022 12:21:57 PM (3 years ago)
Author:
crowdaa
Message:

Added tag 1.7.0.

Location:
crowdaa-sync
Files:
6 edited
74 copied

Legend:

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

    r2818151 r2825896  
    66
    77## [Unreleased]
     8
     9## [1.7.0] - 2022-11-29
     10
     11### Added
     12
     13- Support for multi-categories synchronization
     14
     15### Changed
     16
     17- Fixed issues/typos in medias synchronizations
     18- Fixed a typo when creating a checksum of a category
    819
    920## [1.6.3] - 2022-11-15
  • crowdaa-sync/tags/1.7.0/README.txt

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

    r2805875 r2825896  
    147147
    148148    if (Crowdaa_Sync_Utils::have_plugin('custom-category-image')) {
    149       if ($category->picture) {
     149      if (isset($category->picture) && $category->picture) {
    150150        if (is_object($category->picture[0]) && isset($category->picture[0]->pictureUrl)) {
    151151          $data['picture'] = $category->picture[0]->_id;
     
    11971197    }
    11981198
    1199     $args = array(
    1200       'hide_empty' => false,
    1201       'taxonomy'   => 'category',
    1202       'childless'  => true,
    1203     );
    1204     $all_child_terms = get_terms($args);
    1205     $child_terms = [];
    1206     foreach ($all_child_terms as $child_term) {
    1207       $child_terms[] = $child_term->term_id;
    1208     }
    1209 
    12101199    $feed_categories = get_option('crowdaa_sync_feed_categories', 'all');
    12111200    if ($feed_categories !== 'all') {
     
    12281217      $child_term = false;
    12291218      $post_terms = get_the_terms($post['post_id'], 'category');
    1230       $post_term = null;
    12311219      if(empty($post_terms)) {
    12321220        Crowdaa_Sync_Logs::log('No categories for this post, skipping...');
     
    12361224      $whitelisted = ($sync_categories_mode !== 'whitelist');
    12371225      $blacklisted = false;
     1226      $allowed_term_ids = [];
    12381227      foreach ($post_terms as $term) {
    12391228        if (in_array($term->term_id, $sync_categories_list)) {
    12401229          if ($sync_categories_mode === 'blacklist') {
    12411230            $blacklisted = $term->term_id;
     1231            break;
    12421232          } else {
    12431233            $whitelisted = $term->term_id;
    1244             if (!$post_term) {
    1245               $post_term  = [
    1246                 'id'    => $term->term_id,
    1247                 'child' => in_array($term->term_id, $child_terms),
    1248               ];
    1249             } else if (!$post_term['child'] && in_array($term->term_id, $child_terms)) {
    1250               $post_term  = [
    1251                 'id'    => $term->term_id,
    1252                 'child' => true,
    1253               ];
    1254             }
     1234            $allowed_term_ids[] = $term->term_id;
    12551235          }
    12561236        } else if (
     
    12581238          !$blacklisted
    12591239        ) {
    1260           if (!$post_term) {
    1261             $post_term  = [
    1262               'id'    => $term->term_id,
    1263               'child' => in_array($term->term_id, $child_terms),
    1264             ];
    1265           } else if (!$post_term['child'] && in_array($term->term_id, $child_terms)) {
    1266             $post_term  = [
    1267               'id'    => $term->term_id,
    1268               'child' => true,
    1269             ];
    1270           }
     1240          $allowed_term_ids[] = $term->term_id;
    12711241        }
    12721242      }
     
    13051275        }
    13061276
    1307         // Get category API ID
    1308         $api_term_id = $cat_wp_to_api_id[$post_term['id']];
    1309         if (!$api_term_id) {
     1277        // Get categories API IDs
     1278        $api_term_ids = [];
     1279        foreach ($allowed_term_ids as $ids) {
     1280          $api_term_id = @$cat_wp_to_api_id[$ids];
     1281          if ($api_term_id) {
     1282            $api_term_ids[] = $api_term_id;
     1283          }
     1284        }
     1285        if (!$api_term_ids) {
    13101286          throw new Crowdaa_Sync_Post_Error('Could not find synced category for term '.$post_term['id'].'. This should not happen, aborting sync.');
    13111287
     
    13261302        // Update post
    13271303        if(in_array($post, $only_wp, true)) {
    1328           $sync_api->create_post_api($api_term_id, $post['post_id'], $feed_display);
     1304          $sync_api->create_post_api($api_term_ids, $post['post_id'], $feed_display);
    13291305        } else {
    1330           $sync_api->update_draft_post_api($api_term_id, $post['post_id'], $post['api_id'], $feed_display);
     1306          $sync_api->update_draft_post_api($api_term_ids, $post['post_id'], $post['api_id'], $feed_display);
    13311307        }
    13321308      } catch (Crowdaa_Sync_Post_Skip_Error $e) {
  • crowdaa-sync/tags/1.7.0/admin/class-crowdaa-sync-add-info-wp.php

    r2776976 r2825896  
    248248    $cat_sync_db    = new Crowdaa_Sync_Syncdb('categories');
    249249
    250     $term = $cat_sync_db->get_entry_with_api_id($api_data->category->_id, 'wp_id');
    251     $term = (int) $term->wp_id;
     250    if (isset($api_data->categories)) {
     251      $api_ids = [];
     252      foreach ($api_data->categories as $category) {
     253        $api_ids[] = $category->_id;
     254      }
     255      $terms = $cat_sync_db->get_entries_with_api_ids($api_ids, 'wp_id');
     256      $terms = Crowdaa_Sync_Utils::object_array_extract_field('wp_id', $terms);
     257    } else {
     258      $term = $cat_sync_db->get_entry_with_api_id($api_data->category->_id, 'wp_id');
     259      $terms = [(int) $term->wp_id];
     260    }
    252261
    253262    // $publicationTime = self::api_date_to_unix($api_data->publicationDate);
     
    274283    update_post_meta($wp_post_id, 'display_option_fullscreen', ($fullscreen ? 'yes' : 'no'));
    275284
    276     wp_set_post_terms($wp_post_id, [$term], 'category');
     285    wp_set_post_terms($wp_post_id, $terms, 'category');
    277286
    278287    $sync_errors = $this->post_sync_api_medias($api_data, $wp_post_id);
     
    307316    $cat_sync_db    = new Crowdaa_Sync_Syncdb('categories');
    308317
    309     $term = $cat_sync_db->get_entry_with_api_id($api_data->category->_id, 'wp_id');
    310     $term = (int) $term->wp_id;
     318    if (isset($api_data->categories)) {
     319      $api_ids = [];
     320      foreach ($api_data->categories as $category) {
     321        $api_ids[] = $category->_id;
     322      }
     323      $terms = $cat_sync_db->get_entries_with_api_ids($api_ids, 'wp_id');
     324      $terms = Crowdaa_Sync_Utils::object_array_extract_field('wp_id', $terms);
     325    } else {
     326      $term = $cat_sync_db->get_entry_with_api_id($api_data->category->_id, 'wp_id');
     327      $terms = [(int) $term->wp_id];
     328    }
    311329
    312330    // $publicationTime = self::api_date_to_unix($api_data->publicationDate);
     
    322340    // }
    323341
    324     wp_set_post_terms($wp_post_id, [$term], 'category');
     342    wp_set_post_terms($wp_post_id, $terms, 'category');
    325343    wp_update_post($data);
    326344    update_post_meta($wp_post_id, 'api_post_id', $api_data->_id);
  • crowdaa-sync/tags/1.7.0/admin/class-crowdaa-sync-api.php

    r2762188 r2825896  
    201201      'actions'        => [],
    202202      'authorName'     => $post_author,
    203       'categoryId'     => $category_id,
    204203      'feedPicture'    => $api_feedpicture_id,
    205204      'md'             => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME),
     
    215214      ],
    216215    ];
     216    if (is_array($category_id)) {
     217      $data['categoriesId'] = $category_id;
     218    } else {
     219      $data['categoryId'] = $category_id;
     220    }
    217221    $data = apply_filters('crowdaa_sync_api_update_article_payload', $data, $wp_post_id);
    218222
     
    314318    }
    315319
    316     if(!$article_data['categoryId']) {
     320    if(!$article_data['categoryId'] && !$article_data['categoriesId']) {
    317321      throw new Crowdaa_Sync_Post_Skip_Error(__('Unable to create article without Category', CROWDAA_SYNC_PLUGIN_NAME));
    318322    }
     
    375379    }
    376380
    377     if(!$article_data['categoryId']) {
     381    if(!$article_data['categoryId'] && !$article_data['categoriesId']) {
    378382      throw new Crowdaa_Sync_Post_Skip_Error(__('Unable to update article without Category', CROWDAA_SYNC_PLUGIN_NAME));
    379383    }
     
    465469      'actions'        => [],
    466470      'authorName'     => $post_author,
    467       'categoryId'     => $category_id,
    468471      'feedPicture'    => $api_feedpicture_id,
    469472      'md'             => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME),
     
    479482      ],
    480483    ];
     484    if (is_array($category_id)) {
     485      $data['categoriesId'] = $category_id;
     486    } else {
     487      $data['categoryId'] = $category_id;
     488    }
    481489    $data = apply_filters('crowdaa_sync_api_create_article_payload', $data, $wp_post_id);
    482490
     
    591599    } else if ($gallery_ids === ''.$default_image['attachment_id'] && $thumbnail_id !== null) {
    592600      $gallery_ids = ''.$thumbnail_id;
    593       $api_media_map[$api_feedpicture_id] = [
    594         'attachment_id' => $attachment_id,
     601      $api_media_map[$api_feedpicture_id['api_id']] = [
     602        'attachment_id' => $thumbnail_id,
    595603        'image' => true,
    596604      ];
     
    615623          update_post_meta($wp_post_id, 'api_media_map', serialize($api_media_map));
    616624        } else if ($thumbnail_id && $attachment_id == $thumbnail_id) {
    617           $api_media_map[$api_feedpicture_id] = [
     625          $api_media_map[$api_feedpicture_id['api_id']] = [
    618626            'attachment_id' => $attachment_id,
    619627            'image' => true,
  • crowdaa-sync/tags/1.7.0/crowdaa-sync.php

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

    r2818151 r2825896  
    66
    77## [Unreleased]
     8
     9## [1.7.0] - 2022-11-29
     10
     11### Added
     12
     13- Support for multi-categories synchronization
     14
     15### Changed
     16
     17- Fixed issues/typos in medias synchronizations
     18- Fixed a typo when creating a checksum of a category
    819
    920## [1.6.3] - 2022-11-15
  • crowdaa-sync/trunk/README.txt

    r2818151 r2825896  
    66Requires PHP: 7.3
    77Tested up to: 5.9
    8 Stable tag: 1.6.3
     8Stable tag: 1.7.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

    r2805875 r2825896  
    147147
    148148    if (Crowdaa_Sync_Utils::have_plugin('custom-category-image')) {
    149       if ($category->picture) {
     149      if (isset($category->picture) && $category->picture) {
    150150        if (is_object($category->picture[0]) && isset($category->picture[0]->pictureUrl)) {
    151151          $data['picture'] = $category->picture[0]->_id;
     
    11971197    }
    11981198
    1199     $args = array(
    1200       'hide_empty' => false,
    1201       'taxonomy'   => 'category',
    1202       'childless'  => true,
    1203     );
    1204     $all_child_terms = get_terms($args);
    1205     $child_terms = [];
    1206     foreach ($all_child_terms as $child_term) {
    1207       $child_terms[] = $child_term->term_id;
    1208     }
    1209 
    12101199    $feed_categories = get_option('crowdaa_sync_feed_categories', 'all');
    12111200    if ($feed_categories !== 'all') {
     
    12281217      $child_term = false;
    12291218      $post_terms = get_the_terms($post['post_id'], 'category');
    1230       $post_term = null;
    12311219      if(empty($post_terms)) {
    12321220        Crowdaa_Sync_Logs::log('No categories for this post, skipping...');
     
    12361224      $whitelisted = ($sync_categories_mode !== 'whitelist');
    12371225      $blacklisted = false;
     1226      $allowed_term_ids = [];
    12381227      foreach ($post_terms as $term) {
    12391228        if (in_array($term->term_id, $sync_categories_list)) {
    12401229          if ($sync_categories_mode === 'blacklist') {
    12411230            $blacklisted = $term->term_id;
     1231            break;
    12421232          } else {
    12431233            $whitelisted = $term->term_id;
    1244             if (!$post_term) {
    1245               $post_term  = [
    1246                 'id'    => $term->term_id,
    1247                 'child' => in_array($term->term_id, $child_terms),
    1248               ];
    1249             } else if (!$post_term['child'] && in_array($term->term_id, $child_terms)) {
    1250               $post_term  = [
    1251                 'id'    => $term->term_id,
    1252                 'child' => true,
    1253               ];
    1254             }
     1234            $allowed_term_ids[] = $term->term_id;
    12551235          }
    12561236        } else if (
     
    12581238          !$blacklisted
    12591239        ) {
    1260           if (!$post_term) {
    1261             $post_term  = [
    1262               'id'    => $term->term_id,
    1263               'child' => in_array($term->term_id, $child_terms),
    1264             ];
    1265           } else if (!$post_term['child'] && in_array($term->term_id, $child_terms)) {
    1266             $post_term  = [
    1267               'id'    => $term->term_id,
    1268               'child' => true,
    1269             ];
    1270           }
     1240          $allowed_term_ids[] = $term->term_id;
    12711241        }
    12721242      }
     
    13051275        }
    13061276
    1307         // Get category API ID
    1308         $api_term_id = $cat_wp_to_api_id[$post_term['id']];
    1309         if (!$api_term_id) {
     1277        // Get categories API IDs
     1278        $api_term_ids = [];
     1279        foreach ($allowed_term_ids as $ids) {
     1280          $api_term_id = @$cat_wp_to_api_id[$ids];
     1281          if ($api_term_id) {
     1282            $api_term_ids[] = $api_term_id;
     1283          }
     1284        }
     1285        if (!$api_term_ids) {
    13101286          throw new Crowdaa_Sync_Post_Error('Could not find synced category for term '.$post_term['id'].'. This should not happen, aborting sync.');
    13111287
     
    13261302        // Update post
    13271303        if(in_array($post, $only_wp, true)) {
    1328           $sync_api->create_post_api($api_term_id, $post['post_id'], $feed_display);
     1304          $sync_api->create_post_api($api_term_ids, $post['post_id'], $feed_display);
    13291305        } else {
    1330           $sync_api->update_draft_post_api($api_term_id, $post['post_id'], $post['api_id'], $feed_display);
     1306          $sync_api->update_draft_post_api($api_term_ids, $post['post_id'], $post['api_id'], $feed_display);
    13311307        }
    13321308      } catch (Crowdaa_Sync_Post_Skip_Error $e) {
  • crowdaa-sync/trunk/admin/class-crowdaa-sync-add-info-wp.php

    r2776976 r2825896  
    248248    $cat_sync_db    = new Crowdaa_Sync_Syncdb('categories');
    249249
    250     $term = $cat_sync_db->get_entry_with_api_id($api_data->category->_id, 'wp_id');
    251     $term = (int) $term->wp_id;
     250    if (isset($api_data->categories)) {
     251      $api_ids = [];
     252      foreach ($api_data->categories as $category) {
     253        $api_ids[] = $category->_id;
     254      }
     255      $terms = $cat_sync_db->get_entries_with_api_ids($api_ids, 'wp_id');
     256      $terms = Crowdaa_Sync_Utils::object_array_extract_field('wp_id', $terms);
     257    } else {
     258      $term = $cat_sync_db->get_entry_with_api_id($api_data->category->_id, 'wp_id');
     259      $terms = [(int) $term->wp_id];
     260    }
    252261
    253262    // $publicationTime = self::api_date_to_unix($api_data->publicationDate);
     
    274283    update_post_meta($wp_post_id, 'display_option_fullscreen', ($fullscreen ? 'yes' : 'no'));
    275284
    276     wp_set_post_terms($wp_post_id, [$term], 'category');
     285    wp_set_post_terms($wp_post_id, $terms, 'category');
    277286
    278287    $sync_errors = $this->post_sync_api_medias($api_data, $wp_post_id);
     
    307316    $cat_sync_db    = new Crowdaa_Sync_Syncdb('categories');
    308317
    309     $term = $cat_sync_db->get_entry_with_api_id($api_data->category->_id, 'wp_id');
    310     $term = (int) $term->wp_id;
     318    if (isset($api_data->categories)) {
     319      $api_ids = [];
     320      foreach ($api_data->categories as $category) {
     321        $api_ids[] = $category->_id;
     322      }
     323      $terms = $cat_sync_db->get_entries_with_api_ids($api_ids, 'wp_id');
     324      $terms = Crowdaa_Sync_Utils::object_array_extract_field('wp_id', $terms);
     325    } else {
     326      $term = $cat_sync_db->get_entry_with_api_id($api_data->category->_id, 'wp_id');
     327      $terms = [(int) $term->wp_id];
     328    }
    311329
    312330    // $publicationTime = self::api_date_to_unix($api_data->publicationDate);
     
    322340    // }
    323341
    324     wp_set_post_terms($wp_post_id, [$term], 'category');
     342    wp_set_post_terms($wp_post_id, $terms, 'category');
    325343    wp_update_post($data);
    326344    update_post_meta($wp_post_id, 'api_post_id', $api_data->_id);
  • crowdaa-sync/trunk/admin/class-crowdaa-sync-api.php

    r2762188 r2825896  
    201201      'actions'        => [],
    202202      'authorName'     => $post_author,
    203       'categoryId'     => $category_id,
    204203      'feedPicture'    => $api_feedpicture_id,
    205204      'md'             => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME),
     
    215214      ],
    216215    ];
     216    if (is_array($category_id)) {
     217      $data['categoriesId'] = $category_id;
     218    } else {
     219      $data['categoryId'] = $category_id;
     220    }
    217221    $data = apply_filters('crowdaa_sync_api_update_article_payload', $data, $wp_post_id);
    218222
     
    314318    }
    315319
    316     if(!$article_data['categoryId']) {
     320    if(!$article_data['categoryId'] && !$article_data['categoriesId']) {
    317321      throw new Crowdaa_Sync_Post_Skip_Error(__('Unable to create article without Category', CROWDAA_SYNC_PLUGIN_NAME));
    318322    }
     
    375379    }
    376380
    377     if(!$article_data['categoryId']) {
     381    if(!$article_data['categoryId'] && !$article_data['categoriesId']) {
    378382      throw new Crowdaa_Sync_Post_Skip_Error(__('Unable to update article without Category', CROWDAA_SYNC_PLUGIN_NAME));
    379383    }
     
    465469      'actions'        => [],
    466470      'authorName'     => $post_author,
    467       'categoryId'     => $category_id,
    468471      'feedPicture'    => $api_feedpicture_id,
    469472      'md'             => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME),
     
    479482      ],
    480483    ];
     484    if (is_array($category_id)) {
     485      $data['categoriesId'] = $category_id;
     486    } else {
     487      $data['categoryId'] = $category_id;
     488    }
    481489    $data = apply_filters('crowdaa_sync_api_create_article_payload', $data, $wp_post_id);
    482490
     
    591599    } else if ($gallery_ids === ''.$default_image['attachment_id'] && $thumbnail_id !== null) {
    592600      $gallery_ids = ''.$thumbnail_id;
    593       $api_media_map[$api_feedpicture_id] = [
    594         'attachment_id' => $attachment_id,
     601      $api_media_map[$api_feedpicture_id['api_id']] = [
     602        'attachment_id' => $thumbnail_id,
    595603        'image' => true,
    596604      ];
     
    615623          update_post_meta($wp_post_id, 'api_media_map', serialize($api_media_map));
    616624        } else if ($thumbnail_id && $attachment_id == $thumbnail_id) {
    617           $api_media_map[$api_feedpicture_id] = [
     625          $api_media_map[$api_feedpicture_id['api_id']] = [
    618626            'attachment_id' => $attachment_id,
    619627            'image' => true,
  • crowdaa-sync/trunk/crowdaa-sync.php

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