Plugin Directory

Changeset 2742625


Ignore:
Timestamp:
06/15/2022 06:49:53 AM (4 years ago)
Author:
wesleydeveloper
Message:

Corrigindo erro de sincronização automática

Location:
ourivesweb-api
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ourivesweb-api/tags/1.1.1/src/Controller/Products/Product.php

    r2742584 r2742625  
    4141        $tempo = time();
    4242
    43         LOG::phpCreateFile($File_name); //Cria documento
     43        Log::phpCreateFile($File_name); //Cria documento
    4444        Log::write(OURIVES_DIVIDER . "<br/>" . OURIVES_DIVIDER . "<br/>");
    4545        Log::write('-----> Update Started');
  • ourivesweb-api/tags/1.1.1/src/Plugin.php

    r2742584 r2742625  
    159159    public static function syncProductCron()
    160160    {
    161         Log::write('Iniciando uma Sincronização');
     161        Log::write('Iniciando Sincronização Automática');
     162        Model::defineConfigs();
    162163        (new Product())->Update_OurivesWeb_ToWC();
    163164    }
     
    165166    private function crons()
    166167    {
     168        global $wpdb;
    167169        remove_action("woocommerce_update_product", __CLASS__ . '::productUpdated');
    168170        add_action('woocommerce_update_product', __CLASS__ . '::productUpdated');
    169171
    170         add_action('woocommerce_Ourives_Sync_product', 'OurivesWeb\Plugin::syncProductCron');
    171 
    172 
    173         if ((!wp_next_scheduled('woocommerce_Ourives_Sync_product'))) {
    174             global $wpdb;
    175             $results = $wpdb->get_results("SELECT selected FROM OurivesWeb_api_config WHERE config = 'ourivesweb_stock_sync'");
    176 
    177             if ($results[0]->selected == 1) {
    178                 $results = $wpdb->get_results("SELECT selected FROM OurivesWeb_api_config WHERE config = 'ourivesweb_stock_sync_time'");
    179 
    180                 if (!empty($results)) {
    181                     $value = $results[0]->selected;
    182                 } else {
    183                     $value = 1000;
    184                 }
    185                 return wp_schedule_single_event(time() + $value, 'woocommerce_Ourives_Sync_product');
    186             }
    187         }
    188 
    189 
     172        add_action('ourivesweb_woocommerce_products_sync', '\OurivesWeb\Plugin::syncProductCron');
     173        $ourivesweb_stock_sync = absint($wpdb->get_var("SELECT selected FROM OurivesWeb_api_config WHERE config = 'ourivesweb_stock_sync'"));
     174        $next_exec = time() + (absint($wpdb->get_var("SELECT selected FROM OurivesWeb_api_config WHERE config = 'ourivesweb_stock_sync_time'")) ?: 1000);
     175        if ($ourivesweb_stock_sync && !wp_next_scheduled('ourivesweb_woocommerce_products_sync')) {
     176            wp_schedule_single_event($next_exec, 'ourivesweb_woocommerce_products_sync');
     177            Log::write('Finalizando Sincronização Automática');
     178            Log::write(sprintf('Próxima sincronização agendada para %s', date('Y-m-d H:i:s', $next_exec)));
     179        }
    190180        add_action('woocommerce_order_status_changed', '\OurivesWeb\Plugin::autoDoc', 10, 3);
    191181    }
  • ourivesweb-api/tags/1.1.1/src/Views/settings.php

    r2742584 r2742625  
    419419                        <label class="slidecontainer">
    420420                            <?php
    421                             if (defined('OURIVES_STOCK_SYNC_TIME')) {
     421                            if (defined('OURIVESWEB_STOCK_SYNC_TIME')) {
    422422                                echo '
    423423                                    <label for="ourivesweb_stock_sync_time">' . ("Intervalo para sincronização automática") . '<p>Valor: <span id="demo"></span></p></label>
    424                                     <input type="range" min="300" max="43200" step="300" id="myRange" class="slider" placeholder="Intervalo para sincronização automática" name="opt[ourivesweb_stock_sync_time]" value=' . OURIVES_STOCK_SYNC_TIME . '>';
     424                                    <input type="range" min="300" max="43200" step="300" id="myRange" class="slider" placeholder="Intervalo para sincronização automática" name="opt[ourivesweb_stock_sync_time]" value=' . OURIVESWEB_STOCK_SYNC_TIME . '>';
    425425                            } ?>
    426426                        </label>
  • ourivesweb-api/trunk/src/Controller/Products/Product.php

    r2726965 r2742625  
    4141        $tempo = time();
    4242
    43         LOG::phpCreateFile($File_name); //Cria documento
     43        Log::phpCreateFile($File_name); //Cria documento
    4444        Log::write(OURIVES_DIVIDER . "<br/>" . OURIVES_DIVIDER . "<br/>");
    4545        Log::write('-----> Update Started');
  • ourivesweb-api/trunk/src/Plugin.php

    r2742574 r2742625  
    159159    public static function syncProductCron()
    160160    {
    161         Log::write('Iniciando uma Sincronização');
     161        Log::write('Iniciando Sincronização Automática');
     162        Model::defineConfigs();
    162163        (new Product())->Update_OurivesWeb_ToWC();
    163164    }
     
    165166    private function crons()
    166167    {
     168        global $wpdb;
    167169        remove_action("woocommerce_update_product", __CLASS__ . '::productUpdated');
    168170        add_action('woocommerce_update_product', __CLASS__ . '::productUpdated');
    169171
    170         add_action('woocommerce_Ourives_Sync_product', 'OurivesWeb\Plugin::syncProductCron');
    171 
    172 
    173         if ((!wp_next_scheduled('woocommerce_Ourives_Sync_product'))) {
    174             global $wpdb;
    175             $results = $wpdb->get_results("SELECT selected FROM OurivesWeb_api_config WHERE config = 'ourivesweb_stock_sync'");
    176 
    177             if ($results[0]->selected == 1) {
    178                 $results = $wpdb->get_results("SELECT selected FROM OurivesWeb_api_config WHERE config = 'ourivesweb_stock_sync_time'");
    179 
    180                 if (!empty($results)) {
    181                     $value = $results[0]->selected;
    182                 } else {
    183                     $value = 1000;
    184                 }
    185                 return wp_schedule_single_event(time() + $value, 'woocommerce_Ourives_Sync_product');
    186             }
    187         }
    188 
    189 
     172        add_action('ourivesweb_woocommerce_products_sync', '\OurivesWeb\Plugin::syncProductCron');
     173        $ourivesweb_stock_sync = absint($wpdb->get_var("SELECT selected FROM OurivesWeb_api_config WHERE config = 'ourivesweb_stock_sync'"));
     174        $next_exec = time() + (absint($wpdb->get_var("SELECT selected FROM OurivesWeb_api_config WHERE config = 'ourivesweb_stock_sync_time'")) ?: 1000);
     175        if ($ourivesweb_stock_sync && !wp_next_scheduled('ourivesweb_woocommerce_products_sync')) {
     176            wp_schedule_single_event($next_exec, 'ourivesweb_woocommerce_products_sync');
     177            Log::write('Finalizando Sincronização Automática');
     178            Log::write(sprintf('Próxima sincronização agendada para %s', date('Y-m-d H:i:s', $next_exec)));
     179        }
    190180        add_action('woocommerce_order_status_changed', '\OurivesWeb\Plugin::autoDoc', 10, 3);
    191181    }
     
    211201    }
    212202
    213     private function update(){
    214         if(OURIVES_VERSION === '1.1.1') {
     203    private function update()
     204    {
     205        if (OURIVES_VERSION === '1.1.1') {
    215206            global $wpdb;
    216207            $wpdb->query("UPDATE OurivesWeb_api_config SET config='ourivesweb_stock_sync' WHERE config = 'Ourives_stock_sync'");
  • ourivesweb-api/trunk/src/Views/settings.php

    r2742574 r2742625  
    419419                        <label class="slidecontainer">
    420420                            <?php
    421                             if (defined('OURIVES_STOCK_SYNC_TIME')) {
     421                            if (defined('OURIVESWEB_STOCK_SYNC_TIME')) {
    422422                                echo '
    423423                                    <label for="ourivesweb_stock_sync_time">' . ("Intervalo para sincronização automática") . '<p>Valor: <span id="demo"></span></p></label>
    424                                     <input type="range" min="300" max="43200" step="300" id="myRange" class="slider" placeholder="Intervalo para sincronização automática" name="opt[ourivesweb_stock_sync_time]" value=' . OURIVES_STOCK_SYNC_TIME . '>';
     424                                    <input type="range" min="300" max="43200" step="300" id="myRange" class="slider" placeholder="Intervalo para sincronização automática" name="opt[ourivesweb_stock_sync_time]" value=' . OURIVESWEB_STOCK_SYNC_TIME . '>';
    425425                            } ?>
    426426                        </label>
Note: See TracChangeset for help on using the changeset viewer.