• Skip to sidebar navigation
  • Skip to content

Bitbucket

  • More
    ProjectsRepositories
    • Help
      • Online help
      • Learn Git
      • Welcome to Bitbucket
      • Keyboard shortcuts
    • Log In
    Blackrock
    1. Blackrock

    main

    Public
    Actions
    • Clone

    Learn more about cloning repositories

    You have read-only access

    Navigation
    • Source
    • Commits
    • Branches
    • All Branches Graph
    • Graphs
    • Forks
    1. Blackrock
    2. main

    Source

    main/wp-content/plugins/back-in-stock-notifier-for-woocommerce/includes/class-upgrade.php
    Артем ШиряевАртем Ширяев committed 554847ddcb906 Apr 2021
    Raw file
    Source viewDiff to previous
     
    1
    <?php
    2
    ​
    3
    if (!defined('ABSPATH')) {
    4
        exit;
    5
    }
    6
    ​
    7
    if (!class_exists('CWG_Instock_Upgrade')) {
    8
    ​
    9
        class CWG_Instock_Upgrade {
    10
    ​
    11
            public $upgrade_version = '1.0';
    12
    ​
    13
            public function __construct() {
    14
                add_action('upgrader_process_complete', array($this, 'trigger_upgrade_instock'), 10, 2);
    15
                add_action('cwg_instock_upgrade', array($this, 'register_schedule'));
    16
                add_action('cwg_sync_instock_data', array($this, 'perform_upgrade'), 99, 1);
    17
                register_activation_hook(CWGINSTOCK_FILE, array($this, 'register_schedule'));
    18
            }
    19
    ​
    20
            public function trigger_upgrade_instock($upgrader_object, $options) {
    21
                $our_plugin = CWGSTOCKPLUGINBASENAME;
    22
                if ($options['action'] == 'update' && $options['type'] == 'plugin' && isset($options['plugins'])) {
    23
                    foreach ($options['plugins'] as $plugin) {
    24
                        if ($plugin == $our_plugin) {
    25
                            //trigger update functionality here
    26
                            do_action('cwg_instock_upgrade');
    27
                        }
    28
                    }
    29
                }
    30
            }
    31
    ​
    32
            public function register_schedule() {
    33
                //upon update to the plugin perform some actions
    34
                $api = new CWG_Instock_API();
    35
                $get_meta_values = $api->get_meta_values('cwginstock_product_id', 'cwginstocknotifier');
    36
                if ($get_meta_values) {
    37
                    $chunk_data = array_chunk($get_meta_values, 5);
    38
                    foreach ($chunk_data as $each_array) {
    39
                        as_schedule_single_action(time(), 'cwg_sync_instock_data', array('pid' => $each_array));
    40
                    }
    41
                }
    42
            }
    43
    ​
    44
            public function perform_upgrade($ids) {
    45
                global $wpdb;
    46
                if (is_array($ids) && !empty($ids)) {
    47
                    $this->delete_duplicate_metas();
    48
                    $obj = new CWG_Instock_API();
    49
                    foreach ($ids as $each_id) {
    50
                        $get_count = $obj->get_subscribers_count($each_id, 'cwg_subscribed');
    51
                        update_post_meta($each_id, 'cwg_total_subscribers', $get_count);
    52
                    }
    53
                }
    54
            }
    55
    ​
    56
            public function delete_duplicate_metas() {
    57
                global $wpdb;
    58
                $get_option = get_option('cwg_data_upgraded', 0);
    59
                if ($get_option == 0 || $get_option == '0') {
    60
                    //do upgrade process here
    61
                    $key = 'cwg_total_subscribers';
    62
                    $results = $wpdb->get_results($wpdb->prepare("SELECT count(pm.post_id) as cpid FROM {$wpdb->postmeta} pm WHERE pm.meta_key = %s", $key));
    63
                    if ($results) {
    • Git repository management for enterprise teams powered by Atlassian Bitbucket
    • Atlassian Bitbucket v5.10.1
    • Documentation
    • Contact Support
    • Request a feature
    • About
    • Contact Atlassian
    Atlassian

    Everything looks good. Well let you know here if theres anything you should know about.