Plugin Directory

Changeset 2976439


Ignore:
Timestamp:
10/09/2023 02:20:17 PM (2 years ago)
Author:
ringier
Message:

New release for v2.2.0 (see CHANGELOG.md)

Location:
ringier-bus/trunk
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • ringier-bus/trunk/CHANGELOG.md

    r2939921 r2976439  
    11# Changelog Details
     2
     3### 2.2.0 (Oct 9, 2023) ###
     4
     5* [NEW] Introduction of the possibility to add a custom Top level primary category - can ENABLE/DISABLED when needed
     6  * Addition of two new fields on the Settings page for the below
     7  * use-case: when you have several wordpress instance on the same root domain
     8  * by default, it will use the full domain as the primary category when enabled, with the flexibility for you to change it on the *settings page*
     9
     10* [UPDATE] Refactored the logic for saving custom fields (on gutenberg) to work as soon as the plugin is active, irrespective if the BUS sync is OFF
     11* [FIX] There was a bug that could prevent the primary category of an article from being fetched from the fallback method if the one from Yoast fails
    212
    313### 2.1.0 (Jul 18, 2023) ###
  • ringier-bus/trunk/README.md

    r2939921 r2976439  
    66**Tags:** ringier, bus, api, cde   
    77**Requires at least:** 6.0 
    8 **Tested up to:** 6.2.2 
    9 **Stable tag:** 2.1.0 
     8**Tested up to:** 6.3.1 
     9**Stable tag:** 2.2.0 
    1010**Requires PHP:** 8.0.2 
    1111**License:** GPLv2 or later 
     
    3333Event names: ArticleCreated, ArticleUpdated and ArticleDeleted.
    3434
    35 The events are scheduled to be sent to the Bus with a 2-minute delay. This is to allow WordPress to process the changes and update custom fields in the database, which is done asynchronously. You can view scheduled events by making use of the plugin "Advanced Cron Manager".
     35The **events are scheduled** to be sent to the Bus **within a 1-minute delay**. This is to allow WordPress to process the changes and update custom fields in the database, which is done asynchronously. You can view scheduled events by making use of the plugin "Advanced Cron Manager".
    3636
    3737The plugin also creates two custom fields, available on the article edition page under "Event Bus". 
  • ringier-bus/trunk/readme.txt

    r2939921 r2976439  
    33Tags: ringier, bus, api, cde
    44Requires at least: 6.0
    5 Tested up to: 6.2.2
    6 Stable tag: 2.1.0
     5Tested up to: 6.3.1
     6Stable tag: 2.2.0
    77Requires PHP: 8.0.2
    88License: GPLv2 or later
     
    2929Event names: ArticleCreated, ArticleUpdated and ArticleDeleted.
    3030
    31 The events are scheduled to be sent to the Bus with a 2-minute delay. This is to allow WordPress to process the changes and update custom fields in the database, which is done asynchronously. You can view scheduled events by making use of the plugin "Advanced Cron Manager".
     31The events are scheduled to be sent to the Bus with a 1-minute delay. This is to allow WordPress to process the changes and update custom fields in the database, which is done asynchronously. You can view scheduled events by making use of the plugin "Advanced Cron Manager".
    3232
    3333The plugin also creates two custom fields, available on the article edition page under "Event Bus".
     
    7373
    7474== Changelog ==
     75
     76### 2.2.0 (Oct 9, 2023) ###
     77* [NEW] Introduction of the possibility to add a custom Top level primary category - can ENABLE/DISABLED when needed | See Changelog.md
     78* [UPDATE] Refactored the logic for saving custom fields (on gutenberg) to work as soon as the plugin is active, irrespective if the BUS sync is OFF
     79* [FIX] There was a bug that could prevent the primary category of an article from being fetched from the fallback method if the one from Yoast fails
    7580
    7681### 2.1.0 (Jul 18, 2023) ###
  • ringier-bus/trunk/ringier-bus.php

    r2939921 r2976439  
    1111 * Plugin URI: https://github.com/RingierIMU/mkt-plugin-wordpress-bus
    1212 * Description: A plugin to push events to Ringier CDE via the BUS API whenever an article is created, updated or deleted
    13  * Version: 2.1.0
     13 * Version: 2.2.0
    1414 * Requires at least: 6.0
    1515 * Author: Ringier SA, Wasseem Khayrattee
     
    5050 */
    5151define('RINGIER_BUS_DS', DIRECTORY_SEPARATOR);
    52 define('RINGIER_BUS_PLUGIN_VERSION', '2.1.0');
     52define('RINGIER_BUS_PLUGIN_VERSION', '2.2.0');
    5353define('RINGIER_BUS_PLUGIN_MINIMUM_WP_VERSION', '6.0');
    5454define('RINGIER_BUS_PLUGIN_DIR_URL', plugin_dir_url(__FILE__)); //has trailing slash at end
  • ringier-bus/trunk/src/Core/AdminSettingsPage.php

    r2939921 r2976439  
    100100        $this->add_field_validation_publication_reason();
    101101        $this->add_field_validation_article_lifetime();
     102        $this->add_alternate_primary_category_selectbox();
     103        $this->add_alternate_primary_category_textbox();
    102104    }
    103105
     
    346348            'wp_bus_' . Enum::FIELD_SLACK_CHANNEL_NAME,
    347349            // Use $args' label_for to populate the id inside the callback.
    348             'Slack Channel Name',
     350            'Slack Channel Name (or ID)',
    349351            [self::class, 'field_slack_channel_name_callback'],
    350352            Enum::ADMIN_SETTINGS_MENU_SLUG,
     
    554556        unset($timber);
    555557    }
     558
     559    /**
     560     * FIELD - field_status_alt_primary_category
     561     */
     562    public function add_alternate_primary_category_selectbox(): void
     563    {
     564        add_settings_field(
     565            'wp_bus_' . Enum::FIELD_STATUS_ALTERNATE_PRIMARY_CATEGORY,
     566            // Use $args' label_for to populate the id inside the callback.
     567            'Enable custom Top level Primary category',
     568            [self::class, 'field_alt_primary_category_selectbox_callback'],
     569            Enum::ADMIN_SETTINGS_MENU_SLUG,
     570            Enum::ADMIN_SETTINGS_SECTION_1,
     571            [
     572                'label_for' => Enum::FIELD_STATUS_ALTERNATE_PRIMARY_CATEGORY,
     573                'class' => 'ringier-bus-row alt-category-field first',
     574                'field_custom_data' => Enum::FIELD_STATUS_ALTERNATE_PRIMARY_CATEGORY,
     575            ]
     576        );
     577    }
     578
     579    /**
     580     * field bus status callback function.
     581     *
     582     * @param $args
     583     */
     584    public static function field_alt_primary_category_selectbox_callback($args)
     585    {
     586        // Get the value of the setting we've registered with register_setting()
     587        $options = get_option(Enum::SETTINGS_PAGE_OPTION_NAME);
     588
     589        $timber = new Timber();
     590        $field_status_alt_category_tpl = RINGIER_BUS_PLUGIN_VIEWS . 'admin' . RINGIER_BUS_DS . 'field_alternate_primary_category_selectbox.twig';
     591
     592        $bus_status_selected_on = $bus_status_selected_off = '';
     593        if (isset($options[$args['label_for']])) {
     594            $bus_status_selected_on = selected($options[ $args['label_for'] ], 'on', false);
     595            $bus_status_selected_off = selected($options[ $args['label_for'] ], 'off', false);
     596        }
     597
     598        if (file_exists($field_status_alt_category_tpl)) {
     599            //handle select box
     600            $context['field_bus_status_name'] = Enum::SETTINGS_PAGE_OPTION_NAME . '[' . esc_attr($args['label_for']) . ']';
     601            $context['label_for'] = esc_attr($args['label_for']);
     602            $context['field_custom_data'] = esc_attr($args['field_custom_data']);
     603            $context['field_custom_data_selected_on'] = esc_attr($bus_status_selected_on);
     604            $context['field_custom_data_selected_off'] = esc_attr($bus_status_selected_off);
     605
     606            $timber::render($field_status_alt_category_tpl, $context);
     607        }
     608        unset($timber);
     609    }
     610
     611    /**
     612     * FIELD - field_text_alt_primary_category
     613     */
     614    public function add_alternate_primary_category_textbox(): void
     615    {
     616        add_settings_field(
     617            'wp_bus_' . Enum::FIELD_TEXT_ALTERNATE_PRIMARY_CATEGORY,
     618            // Use $args' label_for to populate the id inside the callback.
     619            'Primary category',
     620            [self::class, 'field_alt_primary_category_textbox_callback'],
     621            Enum::ADMIN_SETTINGS_MENU_SLUG,
     622            Enum::ADMIN_SETTINGS_SECTION_1,
     623            [
     624                'label_for' => Enum::FIELD_TEXT_ALTERNATE_PRIMARY_CATEGORY,
     625                'class' => 'ringier-bus-row alt-category-field',
     626                'field_custom_data' => Enum::FIELD_TEXT_ALTERNATE_PRIMARY_CATEGORY,
     627            ]
     628        );
     629    }
     630
     631    /**
     632     * field field_text_alt_primary_category status callback function.
     633     *
     634     * @param $args
     635     */
     636    public static function field_alt_primary_category_textbox_callback($args): void
     637    {
     638        // Get the value of the setting we've registered with register_setting()
     639        $options = get_option(Enum::SETTINGS_PAGE_OPTION_NAME);
     640
     641        $timber = new Timber();
     642        $field_tpl = RINGIER_BUS_PLUGIN_VIEWS . 'admin' . RINGIER_BUS_DS . 'field_alternate_primary_category_textbox.twig';
     643
     644        $field_value = parse_url(get_site_url(), PHP_URL_HOST);
     645        if (isset($options[$args['label_for']])) {
     646            $field_value = $options[$args['label_for']];
     647        }
     648
     649        if (file_exists($field_tpl)) {
     650            $context['field_name'] = Enum::SETTINGS_PAGE_OPTION_NAME . '[' . esc_attr($args['label_for']) . ']';
     651            $context['label_for'] = esc_attr($args['label_for']);
     652            $context['field_custom_data'] = esc_attr($args['field_custom_data']);
     653            $context['field_value'] = esc_attr($field_value);
     654
     655            $timber::render($field_tpl, $context);
     656        }
     657        unset($timber);
     658    }
    556659}
  • ringier-bus/trunk/src/Core/Bus/ArticleEvent.php

    r2939921 r2976439  
    192192    public function buildArticlePayloadData(int $post_ID, \WP_Post $post): array
    193193    {
    194         return [
     194        $payload_array = [
    195195            'reference' => "$post_ID",
    196196            'status' => $this->getFieldStatus(),
     
    234234                    'culture' => ringier_getLocale(),
    235235                    'value' => Utils::truncate(get_the_excerpt($post_ID), 300),
    236                 ],
    237             ],
    238             'body' => [
    239                 [
    240                     'culture' => ringier_getLocale(),
    241                     'value' => Utils::getRawContent($this->fetchArticleContent($post_ID)),
    242236                ],
    243237            ],
     
    255249             * (wasseem | 9th Dec 2022)
    256250             */
    257             'categories' => [
    258                 $this->getParentCategoryArray($post_ID),
    259             ],
     251            'categories' => $this->getAllCategoryListArray($post_ID),
    260252            'sailthru_tags' => $this->getSailthruTags($post_ID),
    261253            'sailthru_vars' => $this->getSailthruVars($post_ID),
     
    263255            'publication_reason' => Utils::getPublicationReason($post_ID),
    264256            'primary_media_type' => $this->getPrimaryMediaType($post),
     257            'body' => [
     258                [
     259                    'culture' => ringier_getLocale(),
     260                    'value' => Utils::getRawContent($this->fetchArticleContent($post_ID)),
     261                ],
     262            ],
    265263        ];
     264
     265        if ($this->isCustomTopLevelCategoryEnabled() === true) {
     266            $payload_array['child_category'] = $this->getBlogParentCategory($post_ID);
     267        }
     268
     269        return $payload_array;
    266270    }
    267271
     
    568572    }
    569573
    570     private function getParentCategoryArray(int $post_ID)
     574    /**
     575     * Will return the primary category array depending on whether any user defined Top level category was ENABLEBD
     576     *
     577     * @param int $post_ID
     578     *
     579     * @throws \Monolog\Handler\MissingExtensionException
     580     *
     581     * @return array
     582     */
     583    private function getParentCategoryArray(int $post_ID): array
     584    {
     585        if ($this->isCustomTopLevelCategoryEnabled() === true) {
     586            return $this->getCustomTopLevelCategory();
     587        } else {
     588            return $this->getBlogParentCategory($post_ID);
     589        }
     590    }
     591
     592    /**
     593     * To check if the custom Top Level category is enabled
     594     * This is done on the Settings page on the admin UI
     595     *
     596     * @return bool
     597     */
     598    private function isCustomTopLevelCategoryEnabled(): bool
     599    {
     600        $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;
     604        }
     605
     606        return false;
     607    }
     608
     609    /**
     610     * This is the array for the custom top level category
     611     *
     612     * @return array
     613     */
     614    private function getCustomTopLevelCategory(): array
     615    {
     616        $options = get_option(Enum::SETTINGS_PAGE_OPTION_NAME);
     617        $field_alt_category = $options[Enum::FIELD_TEXT_ALTERNATE_PRIMARY_CATEGORY];
     618
     619        return [
     620            'id' => 0,
     621            'title' => [
     622                [
     623                    'culture' => ringier_getLocale(),
     624                    'value' => Utils::returnEmptyOnNullorFalse($field_alt_category),
     625                ],
     626            ],
     627            'slug' => [
     628                [
     629                    'culture' => ringier_getLocale(),
     630                    'value' => sanitize_title($field_alt_category),
     631                ],
     632            ],
     633        ];
     634    }
     635
     636    /**
     637     * This is the actual primary category set within WordPress for this blog instance
     638     *
     639     * @param int $post_ID
     640     *
     641     * @throws \Monolog\Handler\MissingExtensionException
     642     *
     643     * @return array
     644     */
     645    private function getBlogParentCategory(int $post_ID): array
    571646    {
    572647        return [
     
    588663
    589664    /**
     665     * To get list of all categories
     666     *
     667     *
     668     *
     669     * @param int $post_ID
     670     *
     671     * @throws \Monolog\Handler\MissingExtensionException
     672     *
     673     * @return array
     674     */
     675    private function getAllCategoryListArray(int $post_ID): array
     676    {
     677        if ($this->isCustomTopLevelCategoryEnabled() === true) {
     678            $data_array[] = $this->getCustomTopLevelCategory();
     679        }
     680        $data_array[] = $this->getBlogParentCategory($post_ID);
     681
     682        return $data_array;
     683    }
     684
     685    /**
    590686     * Get Modified Date for post
    591687     * in the format RFC3339 (ISO8601)
  • ringier-bus/trunk/src/Core/Bus/BusHelper.php

    r2939921 r2976439  
    88namespace RingierBusPlugin\Bus;
    99
     10use Exception;
     11use GuzzleHttp\Exception\GuzzleException;
     12use Monolog\Handler\MissingExtensionException;
     13use Psr\Cache\InvalidArgumentException;
    1014use RingierBusPlugin\Enum;
    1115use RingierBusPlugin\Utils;
     16use WP_Post;
    1217
    1318class BusHelper
     
    2227     * @return array
    2328     */
    24     public static function getImageArrayForApi(int $post_ID, string $image_size_name = 'large_rectangle', string $isHero = 'false')
     29    public static function getImageArrayForApi(int $post_ID, string $image_size_name = 'large_rectangle', string $isHero = 'false'): array
    2530    {
    2631        $image_id = get_post_thumbnail_id($post_ID);
     
    4752    public static function registerBusApiActions(): void
    4853    {
     54        /*
     55         * the logic of saving custom fields like publication_reason or lifetime, etc
     56         * should work as soon as the plugin is active, irrespective if the BUS sync is OFF
     57         */
     58        add_action('save_post', [self::class, 'save_custom_fields'], 10, 3);
     59
    4960        $fieldsObject = new Fields();
    5061        //Register Bus Events ONLY IF it is enabled
    5162        if ($fieldsObject->is_bus_enabled === true) {
    52             add_action('save_post', [self::class, 'save_custom_fields'], 10, 3);
    5363            add_action('transition_post_status', [self::class, 'cater_for_custom_post'], 10, 3);
    5464            add_action('rest_after_insert_post', [self::class, 'triggerArticleEvent'], 10, 1);
     65            add_action('future_to_publish', [self::class, 'cater_for_manually_scheduled_post'], 10, 1);
    5566            add_action('publish_to_trash', [self::class, 'triggerArticleDeletedEvent'], 10, 3);
    5667            add_action(Enum::HOOK_NAME_SCHEDULED_EVENTS, [self::class, 'cronSendToBusScheduled'], 10, 3);
     
    6273     *
    6374     * @param int $post_id
    64      * @param \WP_Post $post
     75     * @param WP_Post $post
    6576     * @param bool $update
    6677     *
    67      * @throws \Exception
    68      */
    69     public static function save_custom_fields(int $post_id, \WP_Post $post, bool $update)
    70     {
    71         //bail if a page
     78     * @throws Exception
     79     */
     80    public static function save_custom_fields(int $post_id, WP_Post $post, bool $update): void
     81    {
    7282        if (strcmp($post->post_type, 'page') == 0) {
    7383            return;
     
    7989            return;
    8090        }
    81         // Bail if we're working on a draft or trashed item
     91
    8292        $wordpress_post_status = $post->post_status;
    83         if (in_array($wordpress_post_status, ['auto-draft', 'draft', 'inherit', 'trash'])) {
     93        if (in_array($wordpress_post_status, ['auto-draft', 'inherit', 'trash'])) {
    8494            return;
    8595        }
     
    91101        }
    92102
    93         if (strcmp($wordpress_post_status, 'publish') == 0) { //save only when in publish state, no for drafts..etc
     103        //MKTC-1750 - should now allow saving when 'saving draft' and 'scheduled' posting
     104        if (in_array($wordpress_post_status, ['publish', 'draft', 'future'])) {
    94105            $post_id = Utils::getParentPostId($post_id);
    95106
     
    100111                    update_post_meta($post_id, Enum::ACF_ARTICLE_LIFETIME_KEY, $article_lifetime_value);
    101112                } else {
    102                     ringier_errorlogthis('[error] BUS: article_lifetime field value not in whitelist');
     113                    ringier_errorlogthis('[warning] BUS: article_lifetime field value not in whitelist or was empty');
    103114                }
    104115            }
     
    110121                    update_post_meta($post_id, Enum::FIELD_PUBLICATION_REASON_KEY, $publication_reason_value);
    111122                } else {
    112                     ringier_errorlogthis('[error] BUS: publication_reason field value not in whitelist');
     123                    ringier_errorlogthis('[warning] BUS: publication_reason field value not in whitelist or was empty');
    113124                }
    114125            }
     
    123134    /**
    124135     * To cater for custom post_type only
     136     * Triggered by hook: transition_post_status
    125137     *
    126138     * @param string $new_status
    127139     * @param string $old_status
    128      * @param \WP_Post $post
    129      */
    130     public static function cater_for_custom_post(string $new_status, string $old_status, \WP_Post $post)
     140     * @param WP_Post $post
     141     */
     142    public static function cater_for_custom_post(string $new_status, string $old_status, WP_Post $post): void
    131143    {
    132144        //bail if a page
     
    151163
    152164    /**
     165     * Triggered by Hook: rest_after_insert_post
     166     *
    153167     * This action will be invoked ONLY when a post in being Created/Updated
    154168     * (Codex for save_post: https://developer.wordpress.org/reference/hooks/save_post/)
     
    159173     * hence previously hook `save_post` was of a not flexible way for us.
    160174     *
    161      * @param int $post_ID
    162      * @param \WP_Post $post
    163      * @param bool $update
    164      *
    165      * @throws \GuzzleHttp\Exception\GuzzleException
     175     * @param WP_Post $post
     176     *
     177     * @throws MissingExtensionException
     178     * @throws Exception
    166179     *
    167180     * @author Wasseem Khayrattee <wasseemk@ringier.co.za>
     
    169182     * @github wkhayrattee
    170183     */
    171     public static function triggerArticleEvent(\WP_Post $post)
     184    public static function triggerArticleEvent(WP_Post $post): void
    172185    {
    173186        $wordpress_post_status = $post->post_status;
     187
    174188        //we don't want to trigger the event if it is a draft, only when in public
    175189        if (strcmp($wordpress_post_status, 'publish') == 0) {
     
    183197             * Hope in the future WordPress exposes a better way for us to get this context
    184198             */
    185             if (is_object($post)) {
    186                 $blogKey = $_ENV[Enum::ENV_BUS_APP_KEY];
    187                 if (Utils::isPostNew($post_ID) === true) {
    188                     $articleTriggerMode = Enum::EVENT_ARTICLE_CREATED;
    189                 } else {
    190                     $articleTriggerMode = Enum::EVENT_ARTICLE_EDITED;
    191                 }
     199            $blogKey = $_ENV[Enum::ENV_BUS_APP_KEY];
     200            if (Utils::isPostNew($post_ID) === true) {
     201                $articleTriggerMode = Enum::EVENT_ARTICLE_CREATED;
     202            } else {
     203                $articleTriggerMode = Enum::EVENT_ARTICLE_EDITED;
    192204            }
    193205            /*
     
    200212
    201213            //push to SLACK
    202             $message = <<<EOF
    203             $blogKey: $articleTriggerMode queued for article (ID: $post_ID)
    204             Scheduled to run in the next minute(s)
    205         EOF;
    206             Utils::l($message);
    207         }
    208     }
    209 
    210     /**
     214            self::pushToSLACK($blogKey, $articleTriggerMode, $post_ID);
     215        }
     216    }
     217
     218    /**
     219     * Triggered by hook: future_to_publish
     220     *
     221     * @param WP_Post $post
     222     *
     223     * @throws MissingExtensionException
     224     */
     225    public static function cater_for_manually_scheduled_post(WP_Post $post): void
     226    {
     227        $wordpress_post_status = $post->post_status;
     228        if (strcmp($wordpress_post_status, 'publish') == 0) {
     229            $blogKey = $_ENV[Enum::ENV_BUS_APP_KEY];
     230            $post_ID = $post->ID;
     231            $post_ID = Utils::getParentPostId($post_ID);
     232            $articleTriggerMode = 'ArticleCreated';
     233            self::scheduleSendToBus($articleTriggerMode, $post_ID, 0, 1);
     234            self::pushToSLACK($blogKey, $articleTriggerMode, $post_ID);
     235        }
     236    }
     237
     238    /**
     239     * Triggered by hook: publish_to_trash
     240     *
    211241     * This action will be invoked ONLY when a post in being Created/Updated
    212242     * I made use of Transitions
    213243     * (Codex for Status Transitions: https://codex.wordpress.org/Post_Status_Transitions)
    214244     *
    215      * @param \WP_Post $post
    216      *
    217      * @throws \GuzzleHttp\Exception\GuzzleException
     245     * @param WP_Post $post
     246     *
     247     * @throws GuzzleException|MissingExtensionException|InvalidArgumentException
    218248     *
    219249     * @author Wasseem<wasseemk@ringier.co.za>
    220250     */
    221     public static function triggerArticleDeletedEvent(\WP_Post $post)
     251    public static function triggerArticleDeletedEvent(WP_Post $post): void
    222252    {
    223253        $post_ID = Utils::getParentPostId($post->ID);
     
    236266     * @param int $countCalled
    237267     *
    238      * @throws \GuzzleHttp\Exception\GuzzleException
    239      * @throws \Monolog\Handler\MissingExtensionException
     268     * @throws GuzzleException
     269     * @throws MissingExtensionException
     270     * @throws InvalidArgumentException
    240271     *
    241272     * @author Wasseem<wasseemk@ringier.co.za>
    242273     */
    243     public static function cronSendToBusScheduled(string $articleTriggerMode, int $post_ID, int $countCalled)
     274    public static function cronSendToBusScheduled(string $articleTriggerMode, int $post_ID, int $countCalled): void
    244275    {
    245276        $blogKey = $_ENV[Enum::ENV_BUS_APP_KEY];
    246277        $message = <<<EOF
    247             $blogKey: Now attempting to execute Queued "Push-to-BUS" for article (ID: $post_ID)..
     278            $blogKey: Now attempting to execute "Push-to-BUS" for article (ID: $post_ID).
    248279                   
    249280            NOTE:
    250                 If no error follows, means push-to-BUS was successful
     281                If no error follows, means successful push
    251282                (else task will be re-queued)
    252283        EOF;
     
    262293     * @param string $articleTriggerMode
    263294     * @param int $post_ID
    264      * @param \WP_Post $post
     295     * @param WP_Post $post
    265296     * @param int $countCalled to keep track of how many times this function was called by the cron
    266297     *
    267      * @throws \GuzzleHttp\Exception\GuzzleException|\Monolog\Handler\MissingExtensionException
    268      */
    269     public static function sendToBus(string $articleTriggerMode, int $post_ID, \WP_Post $post, int $countCalled = 1): void
     298     * @throws GuzzleException|MissingExtensionException|InvalidArgumentException
     299     */
     300    public static function sendToBus(string $articleTriggerMode, int $post_ID, WP_Post $post, int $countCalled = 1): void
    270301    {
    271302        try {
     
    277308                $articleEvent = new ArticleEvent($authClient);
    278309
     310                // Internal to some of the ventures, so not all will have this object, hence the check
    279311                if (class_exists('Brand_settings')) {
    280312                    $articleEvent->brandSettings = new \Brand_settings();
     
    286318                ringier_errorlogthis('[error] A problem with Auth Token');
    287319
    288                 throw new \Exception('A problem with Auth Token');
     320                throw new Exception('A problem with Auth Token');
    289321            }
    290         } catch (\Exception $exception) {
     322        } catch (Exception $exception) {
    291323            self::scheduleSendToBus($articleTriggerMode, $post_ID, $countCalled);
    292324        }
     
    302334     * @param mixed $run_after_minutes
    303335     *
    304      * @throws \Monolog\Handler\MissingExtensionException
    305      */
    306     public static function scheduleSendToBus(string $articleTriggerMode, int $post_ID, int $countCalled = 1, mixed $run_after_minutes = false)
     336     * @throws MissingExtensionException
     337     */
     338    public static function scheduleSendToBus(string $articleTriggerMode, int $post_ID, int $countCalled = 1, mixed $run_after_minutes = false): void
    307339    {
    308340        if ($run_after_minutes === false) {
     
    321353
    322354        /*
    323          * timestmap of any already scheduled event with SAME args
     355         * timestamp of any already scheduled event with SAME args
    324356         *      - needs to be uniquely identified will return false if not scheduled
    325357         */
    326358        $alreadyScheduledTimestamp = wp_next_scheduled($hookSendToBus, $args);
    327         if ($alreadyScheduledTimestamp === false) { //means first time this cron is being scheduled
    328             wp_schedule_single_event($currentTimestampForAction, $hookSendToBus, $args, true);
    329         } else { //is not on first time
     359        if ($alreadyScheduledTimestamp !== false) { //is not on first time
    330360            //unschedule current
    331361            wp_unschedule_event($alreadyScheduledTimestamp, $hookSendToBus, $args); //we want to remove any pre existing ones
     
    333363            //re-schedule same for another time
    334364            $args = [$articleTriggerMode, $post_ID, ++$countCalled]; //2nd time called, need to increment count
    335             wp_schedule_single_event($currentTimestampForAction, $hookSendToBus, $args, true);
    336         }
     365        }
     366        wp_schedule_single_event($currentTimestampForAction, $hookSendToBus, $args, true);
    337367
    338368        $blogKey = $_ENV[Enum::ENV_BUS_APP_KEY];
    339369        $message = <<<EOF
    340370            $blogKey: [Queuing] Push-to-BUS for article (ID: $post_ID) has just been queued.
    341             And will run in the next ($minutesToRun)mins..
     371            And will run in the next ($minutesToRun)mins.
    342372           
    343             Args:
     373            Passed Params (mode, article_id, count_for_time_invoked):
     374           
    344375        EOF;
    345376        Utils::l($message . print_r($args, true)); //push to SLACK
     
    351382     * @return string
    352383     */
    353     public static function scheduledHookName()
     384    public static function scheduledHookName(): string
    354385    {
    355386        return Enum::HOOK_NAME_SCHEDULED_EVENTS;
    356387    }
     388
     389    /**
     390     * @param mixed $blogKey
     391     * @param string $articleTriggerMode
     392     * @param int $post_ID
     393     *
     394     * @throws MissingExtensionException
     395     */
     396    private static function pushToSLACK(mixed $blogKey, string $articleTriggerMode, int $post_ID): void
     397    {
     398        $message = <<<EOF
     399            $blogKey: [Confirming] $articleTriggerMode queued for article (ID: $post_ID)
     400            Scheduled to run in the next minute(s)
     401        EOF;
     402        Utils::l($message);
     403    }
    357404}
  • ringier-bus/trunk/src/Core/BusPluginClass.php

    r2939921 r2976439  
    7575
    7676        /*
     77         * Hide the "Quick Edit" button on Post List screen (wp-admin/edit.php)
     78         * Because with Quick Edit button, we can change an article from draft to publish,
     79         * bypassing the checklist - which we do not want
     80         */
     81        add_action('post_row_actions', [self::class, 'hide_quick_edit_button'], PHP_INT_MAX);
     82
     83        /*
    7784         * Register Bus API Mechanism
    7885         * Note: commented out because we are now fetching values from the UI (dashboard) itself
    7986         */
    8087//        BusHelper::load_vars_into_env();
     88    }
     89
     90    /**
     91     * Hook reference: https://developer.wordpress.org/reference/hooks/post_row_actions/
     92     *
     93     * @param array $actions
     94     *
     95     * @return array
     96     */
     97    public static function hide_quick_edit_button(array $actions): array
     98    {
     99        unset($actions['inline hide-if-no-js']);
     100
     101        return $actions;
    81102    }
    82103
  • ringier-bus/trunk/src/Core/Enum.php

    r2939921 r2976439  
    4545    const FIELD_VALIDATION_PUBLICATION_REASON = 'field_validation_publication_reason';
    4646    const FIELD_VALIDATION_ARTICLE_LIFETIME = 'field_validation_article_lifetime';
     47    const FIELD_STATUS_ALTERNATE_PRIMARY_CATEGORY = 'field_status_alt_primary_category';
     48    const FIELD_TEXT_ALTERNATE_PRIMARY_CATEGORY = 'field_text_alt_primary_category';
    4749
    4850    //ADMIN LOG PAGE
  • ringier-bus/trunk/src/Core/Utils.php

    r2939921 r2976439  
    88namespace RingierBusPlugin;
    99
     10use Monolog\Handler\MissingExtensionException;
    1011use Ramsey\Uuid\Uuid;
    1112use Ramsey\Uuid\UuidInterface;
     
    7778
    7879    /**
    79      * Fetch the property of a category
    8080     * Property is any of the following:
    8181     * WP_Term Object
     
    9696     * @param $property
    9797     *
    98      * @return false|mixed
    99      */
    100     public static function getPrimaryCategoryProperty($post_id, $property)
     98     * @throws MissingExtensionException
     99     *
     100     * @return mixed
     101     */
     102    public static function getPrimaryCategoryProperty($post_id, $property): mixed
    101103    {
    102104        //some post_ids are simply revisions, so make sure we are actually using the parent id
     
    114116
    115117        $categories = get_the_terms($post_id, 'category');
    116         if ((!is_wp_error($term)) && is_array($categories)) {
     118        if ((!is_wp_error($categories)) && is_array($categories)) {
    117119            $primaryCategory = $categories[0];
    118120
    119121            return $primaryCategory->{$property};
    120122        }
     123
     124        ringier_errorlogthis('Warning: Could not find a category for article with ID: ' . $post_id);
     125        Utils::l('Warning: Could not find a category for article with ID: ' . $post_id);
    121126
    122127        return false;
     
    232237     * @param array $context
    233238     *
    234      * @throws \Monolog\Handler\MissingExtensionException
    235      */
    236     public static function l($message, $logLevel = 'alert', array $context = []): void
     239     * @throws MissingExtensionException
     240     */
     241    public static function l($message, string $logLevel = 'alert', array $context = []): void
    237242    {
    238243        //Enable logging to Slack ONLY IF it was enabled
     
    240245            LoggingHandler::getInstance()->log($logLevel, $message, $context);
    241246        } else {
    242             ringier_errorlogthis('[info] - did not to Slack, it is probably OFF');
     247            ringier_errorlogthis('[info] - did not push to Slack, it is probably OFF');
    243248        }
    244249    }
  • ringier-bus/trunk/src/ringier_bus_plugin_helper.php

    r2632675 r2976439  
    44 *
    55 * @author Wasseem Khayrattee <wasseemk@ringier.co.za>
     6 *
    67 * @github wkhayrattee
    78 */
     
    1920 * @throws \Exception
    2021 */
    21 function ringier_infologthis($message)
     22function ringier_infologthis($message): void
    2223{
    2324    if (isset($_ENV['APP_ENV']) && ($_ENV['APP_ENV'] != 'prod')) {
     
    3839 * @throws \Exception
    3940 */
    40 function ringier_errorlogthis($message)
     41function ringier_errorlogthis($message): void
    4142{
    4243    $log = new Logger('ringier_bus_plugin_error_log');
     
    5455 * @return mixed|string
    5556 */
    56 function ringier_getLocale()
     57function ringier_getLocale(): mixed
    5758{
    5859    if (isset($_ENV[Enum::ENV_BUS_API_LOCALE])) {
  • ringier-bus/trunk/views/admin/field_slack_channel_name.twig

    r2632675 r2976439  
    55        style="width: 22rem;">
    66<p>You can normally create a Channel on your slack, if not ask help with your Slack Admin</p>
     7<p>Consider using the <strong>channel ID</strong>, so that if you change your channel's name, nothing breaks!</p>
Note: See TracChangeset for help on using the changeset viewer.