Changeset 2980105
- Timestamp:
- 10/17/2023 12:47:59 PM (2 years ago)
- Location:
- ringier-bus/trunk
- Files:
-
- 6 edited
-
CHANGELOG.md (modified) (1 diff)
-
README.md (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
ringier-bus.php (modified) (3 diffs)
-
src/Core/Bus/ArticleEvent.php (modified) (3 diffs)
-
src/Core/Bus/BusHelper.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ringier-bus/trunk/CHANGELOG.md
r2976439 r2980105 1 1 # Changelog Details 2 3 ### 2.3.0 (Oct 9, 2023) ### 4 5 * [UPDATE]: Transitioned from relying on the rest_after_insert_post hook to the more universally available transition_post_status hook. 6 7 *Reason*: We identified that some blogs were disabling the Gutenberg editor and as a result, not utilizing the new WordPress REST API. This meant that the rest_after_insert_post hook wasn't being triggered for those instances. To ensure consistent and robust post update handling across all blogs, regardless of their editor choice, we've shifted to the transition_post_status hook. 8 9 *Impact*: This change ensures that our logic remains consistent even in environments where Gutenberg is disabled or the REST API isn't being leveraged. 10 11 * [UPDATE]: Improved JSON handling and compression for Slack logging 12 * Ensured safe JSON encoding with error checks 13 * Utilized gzcompress for payload compression when available to prevent truncation in Slack notifications channel 2 14 3 15 ### 2.2.0 (Oct 9, 2023) ### -
ringier-bus/trunk/README.md
r2976439 r2980105 6 6 **Tags:** ringier, bus, api, cde 7 7 **Requires at least:** 6.0 8 **Tested up to:** 6.3. 19 **Stable tag:** 2. 2.08 **Tested up to:** 6.3.2 9 **Stable tag:** 2.3.0 10 10 **Requires PHP:** 8.0.2 11 11 **License:** GPLv2 or later -
ringier-bus/trunk/readme.txt
r2976439 r2980105 3 3 Tags: ringier, bus, api, cde 4 4 Requires at least: 6.0 5 Tested up to: 6.3. 16 Stable tag: 2. 2.05 Tested up to: 6.3.2 6 Stable tag: 2.3.0 7 7 Requires PHP: 8.0.2 8 8 License: GPLv2 or later … … 74 74 == Changelog == 75 75 76 ### 2.3.0 (Oct 9, 2023) ### 77 * [UPDATE]: Transitioned from relying on the rest_after_insert_post hook to the more universally available transition_post_status hook. 78 79 *Reason*: 80 We identified that some blogs were disabling the Gutenberg editor and as a result, not utilizing the new WordPress REST API. This meant that the rest_after_insert_post hook wasn't being triggered for those instances. To ensure consistent and robust post update handling across all blogs, regardless of their editor choice, we've shifted to the transition_post_status hook. 81 82 * [UPDATE]: Improved JSON handling and compression for Slack logging (see Changelog.md) 83 76 84 ### 2.2.0 (Oct 9, 2023) ### 77 85 * [NEW] Introduction of the possibility to add a custom Top level primary category - can ENABLE/DISABLED when needed | See Changelog.md -
ringier-bus/trunk/ringier-bus.php
r2976439 r2980105 11 11 * Plugin URI: https://github.com/RingierIMU/mkt-plugin-wordpress-bus 12 12 * Description: A plugin to push events to Ringier CDE via the BUS API whenever an article is created, updated or deleted 13 * Version: 2. 2.013 * Version: 2.3.0 14 14 * Requires at least: 6.0 15 15 * Author: Ringier SA, Wasseem Khayrattee … … 50 50 */ 51 51 define('RINGIER_BUS_DS', DIRECTORY_SEPARATOR); 52 define('RINGIER_BUS_PLUGIN_VERSION', '2. 2.0');52 define('RINGIER_BUS_PLUGIN_VERSION', '2.3.0'); 53 53 define('RINGIER_BUS_PLUGIN_MINIMUM_WP_VERSION', '6.0'); 54 54 define('RINGIER_BUS_PLUGIN_DIR_URL', plugin_dir_url(__FILE__)); //has trailing slash at end … … 58 58 define('RINGIER_BUS_PLUGIN_CACHE_DIR', WP_CONTENT_DIR . RINGIER_BUS_DS . 'cache' . RINGIER_BUS_DS); 59 59 define('RINGIER_BUS_PLUGIN_ERROR_LOG_FILE', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'ringier_bus_plugin_error_log'); 60 61 /** 62 * define a cache nonce for asset files loaded by this plugin 63 * on the admin facing UI (Gutenberg) 64 * The name was chosen since we were already using this within our legacy Ringier repos. 65 */ 66 if (!defined('_S_VERSION')) { 67 define('_S_VERSION', '2.3.0.001'); 68 } 60 69 61 70 /** -
ringier-bus/trunk/src/Core/Bus/ArticleEvent.php
r2976439 r2980105 98 98 * @throws \Exception 99 99 */ 100 public function sendToBus(int $post_ID, \WP_Post $post) 100 public function sendToBus(int $post_ID, \WP_Post $post): void 101 101 { 102 102 /* … … 126 126 $requestBody 127 127 ); 128 $bodyArray = json_decode((string) $response->getBody(), true); 128 $raw_response = (string) $response->getBody(); 129 $bodyArray = json_decode($raw_response, true); 130 131 // To compress string so it is not truncated on Slack 132 if (json_last_error() !== JSON_ERROR_NONE) { 133 Utils::l('JSON encoding error: ' . json_last_error_msg()); 134 135 return; 136 } 137 $raw_response = json_encode($raw_response); 138 139 if (extension_loaded('zlib')) { 140 $raw_response = gzcompress($raw_response); 141 } 142 143 $message2 = <<<EOF 144 The payload seems to have been successfully delivered. 145 And the FULL json compressed with gzcompress() (to prevent truncation) was: 146 147 EOF; 148 Utils::l($message2 . base64_encode($raw_response)); //push to SLACK 149 129 150 // ringier_errorlogthis($bodyArray); 130 151 } catch (\Exception $exception) { … … 599 620 { 600 621 $options = get_option(Enum::SETTINGS_PAGE_OPTION_NAME); 601 $field_status_alt_category = $options[Enum::FIELD_STATUS_ALTERNATE_PRIMARY_CATEGORY]; 602 if (strcmp($field_status_alt_category, 'on') == 0) { 603 return true; 622 // Check if the key exists before accessing its value. 623 if (isset($options[Enum::FIELD_STATUS_ALTERNATE_PRIMARY_CATEGORY])) { 624 $field_status_alt_category = $options[Enum::FIELD_STATUS_ALTERNATE_PRIMARY_CATEGORY]; 625 if (strcmp($field_status_alt_category, 'on') == 0) { 626 return true; 627 } 604 628 } 605 629 -
ringier-bus/trunk/src/Core/Bus/BusHelper.php
r2976439 r2980105 61 61 //Register Bus Events ONLY IF it is enabled 62 62 if ($fieldsObject->is_bus_enabled === true) { 63 add_action('transition_post_status', [self::class, 'cater_for_custom_post'], 10, 3); 64 add_action('rest_after_insert_post', [self::class, 'triggerArticleEvent'], 10, 1); 63 // add_action('transition_post_status', [self::class, 'cater_for_custom_post'], 10, 3); 64 // add_action('rest_after_insert_post', [self::class, 'triggerArticleEvent'], 10, 1); 65 add_action('transition_post_status', [self::class, 'trigger_bus_event_on_post_change'], 10, 3); 65 66 add_action('future_to_publish', [self::class, 'cater_for_manually_scheduled_post'], 10, 1); 66 67 add_action('publish_to_trash', [self::class, 'triggerArticleDeletedEvent'], 10, 3); … … 133 134 134 135 /** 136 * In essence, this method is a merge of cater_for_custom_post() and triggerArticleEvent() 137 * because the rest_after_insert_post hook does not get triggered in all WordPress contexts, 138 * such as when updating a post using the Classic Editor (IMO disabled Gutenberg) 139 * or programmatically without the REST API. 140 * 141 * Thus we ensure that the desired actions are consistently executed regardless 142 * of the editing method or environment. 143 * 144 * @param string $new_status 145 * @param string $old_status 146 * @param WP_Post $post 147 * 148 * @throws MissingExtensionException 149 */ 150 public static function trigger_bus_event_on_post_change(string $new_status, string $old_status, WP_Post $post): void 151 { 152 // Check if it's a page or normal post and return 153 if ($post->post_type === 'page' || empty($post->post_type)) { 154 return; 155 } 156 157 // Bail if we're working on a draft or trashed item 158 if ($new_status == 'auto-draft' || $new_status == 'draft' || $new_status == 'inherit' || $new_status == 'trash') { 159 return; 160 } 161 162 if ($new_status === 'publish') { 163 $post_ID = $post->ID; 164 $post_ID = Utils::getParentPostId($post_ID); 165 166 /* 167 * This conditioning helps us get context if the post is in mode NEW or EDIT 168 * There is no other way around this as of this date of coding (Apr 2021) 169 * Hope in the future WordPress exposes a better way for us to get this context 170 */ 171 $articleTriggerMode = Utils::isPostNew($post_ID) ? Enum::EVENT_ARTICLE_CREATED : Enum::EVENT_ARTICLE_EDITED; 172 173 /* 174 * we will now schedule the event after 1min instead of instantly executing it, because: 175 * not all meta data of the article are updated correctly when: 176 * - article is first created, 177 * - when article meta are changed 178 */ 179 self::scheduleSendToBus($articleTriggerMode, $post_ID, 0, 1); 180 181 //push to SLACK 182 $blogKey = $_ENV[Enum::ENV_BUS_APP_KEY]; 183 self::pushToSLACK($blogKey, $articleTriggerMode, $post_ID); 184 } 185 } 186 187 /** 188 * (No more used in favor of trigger_bus_event_on_post_change()) 189 * 135 190 * To cater for custom post_type only 136 191 * Triggered by hook: transition_post_status … … 163 218 164 219 /** 220 * (No more used in favor of trigger_bus_event_on_post_change()) 221 * 165 222 * Triggered by Hook: rest_after_insert_post 166 223 *
Note: See TracChangeset
for help on using the changeset viewer.