Changeset 3376210
- Timestamp:
- 10/10/2025 11:53:46 AM (5 months ago)
- Location:
- crowdaa-sync
- Files:
-
- 6 edited
- 44 copied
-
tags/2.2.0 (copied) (copied from crowdaa-sync/trunk)
-
tags/2.2.0/CHANGELOG (copied) (copied from crowdaa-sync/trunk/CHANGELOG) (1 diff)
-
tags/2.2.0/README.txt (copied) (copied from crowdaa-sync/trunk/README.txt) (1 diff)
-
tags/2.2.0/admin/class-crowdaa-sync-add-info-api.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-add-info-api.php) (9 diffs)
-
tags/2.2.0/admin/class-crowdaa-sync-add-info-wp.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-add-info-wp.php) (4 diffs)
-
tags/2.2.0/admin/class-crowdaa-sync-admin-display.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-admin-display.php)
-
tags/2.2.0/admin/class-crowdaa-sync-admin.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-admin.php)
-
tags/2.2.0/admin/class-crowdaa-sync-api.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-api.php) (2 diffs)
-
tags/2.2.0/admin/class-crowdaa-sync-ext-hooks.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-ext-hooks.php)
-
tags/2.2.0/admin/class-crowdaa-sync-meta-box.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-meta-box.php)
-
tags/2.2.0/admin/class-crowdaa-sync-rest-api.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-rest-api.php)
-
tags/2.2.0/admin/class-crowdaa-sync-wp-hooks.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-wp-hooks.php)
-
tags/2.2.0/admin/css/crowdaa-sync-admin.css (copied) (copied from crowdaa-sync/trunk/admin/css/crowdaa-sync-admin.css)
-
tags/2.2.0/admin/js/crowdaa-sync-admin.js (copied) (copied from crowdaa-sync/trunk/admin/js/crowdaa-sync-admin.js)
-
tags/2.2.0/admin/partials/crowdaa-sync-admin-display.php (copied) (copied from crowdaa-sync/trunk/admin/partials/crowdaa-sync-admin-display.php)
-
tags/2.2.0/crowdaa-sync.php (copied) (copied from crowdaa-sync/trunk/crowdaa-sync.php) (2 diffs)
-
tags/2.2.0/includes/class-crowdaa-sync-activator.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-activator.php)
-
tags/2.2.0/includes/class-crowdaa-sync-deactivator.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-deactivator.php)
-
tags/2.2.0/includes/class-crowdaa-sync-exception.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-exception.php)
-
tags/2.2.0/includes/class-crowdaa-sync-i18n.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-i18n.php)
-
tags/2.2.0/includes/class-crowdaa-sync-loader.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-loader.php)
-
tags/2.2.0/includes/class-crowdaa-sync-lock.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-lock.php)
-
tags/2.2.0/includes/class-crowdaa-sync-logs.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-logs.php)
-
tags/2.2.0/includes/class-crowdaa-sync-permissions.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-permissions.php)
-
tags/2.2.0/includes/class-crowdaa-sync-syncdb.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-syncdb.php)
-
tags/2.2.0/includes/class-crowdaa-sync-timer.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-timer.php)
-
tags/2.2.0/includes/class-crowdaa-sync-utils.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-utils.php)
-
tags/2.2.0/includes/class-crowdaa-sync-versions.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-versions.php)
-
tags/2.2.0/includes/class-crowdaa-sync.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync.php)
-
tags/2.2.0/languages/crowdaa-sync-fr_FR.mo (copied) (copied from crowdaa-sync/trunk/languages/crowdaa-sync-fr_FR.mo)
-
tags/2.2.0/languages/crowdaa-sync-fr_FR.po (copied) (copied from crowdaa-sync/trunk/languages/crowdaa-sync-fr_FR.po)
-
tags/2.2.0/vendor/autoload.php (copied) (copied from crowdaa-sync/trunk/vendor/autoload.php)
-
tags/2.2.0/vendor/composer/ClassLoader.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/ClassLoader.php)
-
tags/2.2.0/vendor/composer/InstalledVersions.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/InstalledVersions.php)
-
tags/2.2.0/vendor/composer/LICENSE (copied) (copied from crowdaa-sync/trunk/vendor/composer/LICENSE)
-
tags/2.2.0/vendor/composer/autoload_classmap.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/autoload_classmap.php)
-
tags/2.2.0/vendor/composer/autoload_files.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/autoload_files.php)
-
tags/2.2.0/vendor/composer/autoload_namespaces.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/autoload_namespaces.php)
-
tags/2.2.0/vendor/composer/autoload_psr4.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/autoload_psr4.php)
-
tags/2.2.0/vendor/composer/autoload_real.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/autoload_real.php)
-
tags/2.2.0/vendor/composer/autoload_static.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/autoload_static.php)
-
tags/2.2.0/vendor/composer/installed.json (copied) (copied from crowdaa-sync/trunk/vendor/composer/installed.json)
-
tags/2.2.0/vendor/composer/installed.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/installed.php)
-
tags/2.2.0/vendor/composer/platform_check.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/platform_check.php)
-
trunk/CHANGELOG (modified) (1 diff)
-
trunk/README.txt (modified) (1 diff)
-
trunk/admin/class-crowdaa-sync-add-info-api.php (modified) (9 diffs)
-
trunk/admin/class-crowdaa-sync-add-info-wp.php (modified) (4 diffs)
-
trunk/admin/class-crowdaa-sync-api.php (modified) (2 diffs)
-
trunk/crowdaa-sync.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
crowdaa-sync/tags/2.2.0/CHANGELOG
r3274443 r3376210 7 7 8 8 ## [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 9 20 10 21 ## [2.1.1] - 2025-04-16 -
crowdaa-sync/tags/2.2.0/README.txt
r3274443 r3376210 6 6 Requires PHP: 7.3 7 7 Tested up to: 5.9 8 Stable tag: 2. 1.18 Stable tag: 2.2.0 9 9 License: GPLv2 or later 10 10 License 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 146 146 'name' => $term->name, 147 147 'slug' => $term->slug, 148 'parent' => $term->parent ,148 'parent' => $term->parent . '', 149 149 ]; 150 150 … … 158 158 $data['isEvent'] = (get_term_meta($term->term_id, 'crowdaa_is_event', true) === 'yes'); 159 159 if (isset($term->rootParentId)) { 160 $data['rootParentId'] = $term->rootParentId ;160 $data['rootParentId'] = $term->rootParentId . ''; 161 161 } 162 162 … … 509 509 $item->term_hash = $item->sync_data['term_hash']; 510 510 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]); 512 512 } 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]); 514 514 } else { 515 515 $synced_by_wp_id[$item->wp_id] = $item; … … 1073 1073 } 1074 1074 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 // } 1095 1094 1096 1095 public function sync_badges_api( … … 1328 1327 $api_post_id = get_post_meta($post['post_id'], 'api_post_id'); 1329 1328 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']); 1332 1331 } 1333 1332 … … 1337 1336 $api_post_id = get_post_meta($post['post_id'], 'api_post_id'); 1338 1337 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']); 1341 1340 } 1342 1341 … … 1350 1349 $api_post_id = get_post_meta($post['post_id'], 'api_post_id'); 1351 1350 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']); 1354 1353 } 1355 1354 … … 1366 1365 } 1367 1366 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.'); 1369 1368 1370 1369 continue; … … 1384 1383 // Update post 1385 1384 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); 1387 1386 } else { 1388 1387 $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 217 217 $errors = []; 218 218 $api_data_class = new Crowdaa_Sync_API(); 219 $cat_sync_db = Crowdaa_Sync_Syncdb::instance('categories'); 219 220 $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 } 220 229 221 230 foreach ($posts_sync_to_wp as $postArrayId => $api_post) { … … 234 243 235 244 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 236 307 if (in_array($api_post, $only_api, true)) { 237 $sync_errors = $this->create_wp_post_from_api($a pi_whole_post);308 $sync_errors = $this->create_wp_post_from_api($allowed_term_ids, $api_whole_post); 238 309 } else { 239 $sync_errors = $this->update_wp_post_from_api($a pi_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']); 240 311 } 241 312 $errors += $sync_errors; … … 259 330 } 260 331 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 { 277 334 $publicationTime = self::api_date_to_unix($api_data->publicationDate); 278 335 $post_data = [ … … 346 403 } 347 404 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 { 364 407 $publicationTime = self::api_date_to_unix($api_data->publicationDate); 365 408 $data = [ -
crowdaa-sync/tags/2.2.0/admin/class-crowdaa-sync-api.php
r3274443 r3376210 596 596 } 597 597 598 update_post_meta($wp_post_id, 'api_post_id', $json->articleId);599 598 if ($send_notification) { 600 599 update_post_meta($wp_post_id, 'crowdaa_notification_sent', 'yes'); … … 603 602 Crowdaa_Sync_Logs::log('Created API post', $json->articleId); 604 603 } 604 605 update_post_meta($wp_post_id, 'api_post_id', $json->articleId); 605 606 606 607 return $json->articleId; -
crowdaa-sync/tags/2.2.0/crowdaa-sync.php
r3274443 r3376210 14 14 * Plugin URI: 15 15 * Description: Plugin for synchronizing WordPress site and Crowdaa CMS 16 * Version: 2. 1.116 * Version: 2.2.0 17 17 * Requires at least: 5.5 18 18 * Requires PHP: 7.2 … … 34 34 * Uses SemVer - https://semver.org 35 35 */ 36 define('CROWDAA_SYNC_VERSION', '2. 1.1');36 define('CROWDAA_SYNC_VERSION', '2.2.0'); 37 37 define('CROWDAA_SYNC_PLUGIN_DIR', __DIR__); 38 38 define('CROWDAA_SYNC_PLUGIN_NAME', 'crowdaa-sync'); -
crowdaa-sync/trunk/CHANGELOG
r3274443 r3376210 7 7 8 8 ## [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 9 20 10 21 ## [2.1.1] - 2025-04-16 -
crowdaa-sync/trunk/README.txt
r3274443 r3376210 6 6 Requires PHP: 7.3 7 7 Tested up to: 5.9 8 Stable tag: 2. 1.18 Stable tag: 2.2.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
crowdaa-sync/trunk/admin/class-crowdaa-sync-add-info-api.php
r3229463 r3376210 146 146 'name' => $term->name, 147 147 'slug' => $term->slug, 148 'parent' => $term->parent ,148 'parent' => $term->parent . '', 149 149 ]; 150 150 … … 158 158 $data['isEvent'] = (get_term_meta($term->term_id, 'crowdaa_is_event', true) === 'yes'); 159 159 if (isset($term->rootParentId)) { 160 $data['rootParentId'] = $term->rootParentId ;160 $data['rootParentId'] = $term->rootParentId . ''; 161 161 } 162 162 … … 509 509 $item->term_hash = $item->sync_data['term_hash']; 510 510 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]); 512 512 } 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]); 514 514 } else { 515 515 $synced_by_wp_id[$item->wp_id] = $item; … … 1073 1073 } 1074 1074 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 // } 1095 1094 1096 1095 public function sync_badges_api( … … 1328 1327 $api_post_id = get_post_meta($post['post_id'], 'api_post_id'); 1329 1328 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']); 1332 1331 } 1333 1332 … … 1337 1336 $api_post_id = get_post_meta($post['post_id'], 'api_post_id'); 1338 1337 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']); 1341 1340 } 1342 1341 … … 1350 1349 $api_post_id = get_post_meta($post['post_id'], 'api_post_id'); 1351 1350 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']); 1354 1353 } 1355 1354 … … 1366 1365 } 1367 1366 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.'); 1369 1368 1370 1369 continue; … … 1384 1383 // Update post 1385 1384 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); 1387 1386 } else { 1388 1387 $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 217 217 $errors = []; 218 218 $api_data_class = new Crowdaa_Sync_API(); 219 $cat_sync_db = Crowdaa_Sync_Syncdb::instance('categories'); 219 220 $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 } 220 229 221 230 foreach ($posts_sync_to_wp as $postArrayId => $api_post) { … … 234 243 235 244 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 236 307 if (in_array($api_post, $only_api, true)) { 237 $sync_errors = $this->create_wp_post_from_api($a pi_whole_post);308 $sync_errors = $this->create_wp_post_from_api($allowed_term_ids, $api_whole_post); 238 309 } else { 239 $sync_errors = $this->update_wp_post_from_api($a pi_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']); 240 311 } 241 312 $errors += $sync_errors; … … 259 330 } 260 331 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 { 277 334 $publicationTime = self::api_date_to_unix($api_data->publicationDate); 278 335 $post_data = [ … … 346 403 } 347 404 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 { 364 407 $publicationTime = self::api_date_to_unix($api_data->publicationDate); 365 408 $data = [ -
crowdaa-sync/trunk/admin/class-crowdaa-sync-api.php
r3274443 r3376210 596 596 } 597 597 598 update_post_meta($wp_post_id, 'api_post_id', $json->articleId);599 598 if ($send_notification) { 600 599 update_post_meta($wp_post_id, 'crowdaa_notification_sent', 'yes'); … … 603 602 Crowdaa_Sync_Logs::log('Created API post', $json->articleId); 604 603 } 604 605 update_post_meta($wp_post_id, 'api_post_id', $json->articleId); 605 606 606 607 return $json->articleId; -
crowdaa-sync/trunk/crowdaa-sync.php
r3274443 r3376210 14 14 * Plugin URI: 15 15 * Description: Plugin for synchronizing WordPress site and Crowdaa CMS 16 * Version: 2. 1.116 * Version: 2.2.0 17 17 * Requires at least: 5.5 18 18 * Requires PHP: 7.2 … … 34 34 * Uses SemVer - https://semver.org 35 35 */ 36 define('CROWDAA_SYNC_VERSION', '2. 1.1');36 define('CROWDAA_SYNC_VERSION', '2.2.0'); 37 37 define('CROWDAA_SYNC_PLUGIN_DIR', __DIR__); 38 38 define('CROWDAA_SYNC_PLUGIN_NAME', 'crowdaa-sync');
Note: See TracChangeset
for help on using the changeset viewer.