Plugin Directory

Changeset 3084337


Ignore:
Timestamp:
05/10/2024 06:28:44 AM (22 months ago)
Author:
davelopweb
Message:

update manual save

Location:
stn-save-to-nextcloud/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stn-save-to-nextcloud/trunk/STN.php

    r3049241 r3084337  
    88 *  * Plugin URI: httsp://www.davelopweb.fr/
    99 * Description: Sauvegarde wordpress + Bdd mensuelle vers votre instance Nextcloud
    10  *  * Version: 2.4.4
     10 *  * Version: 2.4.5
    1111 * Author: Dave DELALLEAU
    1212 * Author URI: https://www.davelopweb.fr/#contact
     
    112112        };
    113113               
    114                
    115114        //reprise suivant l'état de la sauvegarde
    116115        //switch
    117         switch ($inProgress['etat']) {                     
     116        switch ($inProgress['etat']) { 
     117                               
    118118                   
    119119            case "0":
     
    250250                };             
    251251                       
    252             exit();             
     252            exit();                
    253253
    254254        };
     
    261261        //clean
    262262        global $wpdb;
    263        
    264         //clean
    265263        $wpdb->delete( $wpdb->prefix.'stn_saveInProgress', array("finish" => "0" ) );
    266        
    267         //nettoyage des fichiers résiduels si existant
    268264        $filesInFtp = glob(ABSPATH . "stnSave_*");
    269265        foreach($filesInFtp as $file){  unlink($file);  }; 
     
    296292           
    297293            stn_save_to_nextcloud::stn_programSave();
    298            
    299             //lancement des mises à jours, si on a activer l'option pour gérer les auto update
    300             if(get_option("auto_update_dlwcloud") == "true"){
    301                
    302                 stn_save_to_nextcloud::stn_run_manual_updates();
    303                
    304             };
    305294                       
    306295        };
     
    391380            }
    392381        }
    393         // Calcul le UTC avec l'heure locale
    394         $decalage = current_time("timestamp") - time();
    395         // Adapte le timestamp à l'heure locale
    396         $adaptedTimestamp = $timestamp - $decalage;
    397 
    398         wp_schedule_single_event($adaptedTimestamp,'stn_Save',array('next'));
    399 
    400     }
    401    
    402    
    403    
    404     function stn_run_manual_updates() {
    405        
    406         // Mise à jour du cœur de WordPress
    407         require_once ABSPATH . 'wp-admin/includes/update.php';
    408         wp_update_core();
    409 
    410         // Récupérer les plugins avec mises à jour automatiques activées
    411         $plugins_with_auto_updates = $this->stn_get_plugins_with_auto_updates();
    412 
    413         // Mise à jour des plugins avec mises à jour automatiques activées
    414         foreach ($plugins_with_auto_updates as $plugin_slug) {
    415             $plugin_update_result = wp_update_plugin($plugin_slug);
    416             // Traitez le résultat ou affichez un message de succès/échec selon vos besoins
    417         }
    418 
    419         // Mise à jour des thèmes
    420         wp_update_themes();
    421        
    422     }
    423 
    424     function stn_get_plugins_with_auto_updates() {
    425         $auto_update_plugins = get_site_transient('update_plugins');
    426         $plugins_with_auto_updates = array();
    427 
    428         foreach ($auto_update_plugins->response as $plugin_slug => $plugin_data) {
    429             $plugins_with_auto_updates[] = $plugin_slug;
    430         }
    431 
    432         return $plugins_with_auto_updates;
     382
     383        wp_schedule_single_event($timestamp,'stn_Save',array('next'));
     384
    433385    }
    434386   
     
    460412//Vue admin
    461413$save_to_nextcloud=new stn_save_to_nextcloud();
    462 
    463414register_activation_hook( PLUGIN_PATH_STN . 'STN.php',array($save_to_nextcloud,'activate'));
    464415register_deactivation_hook( PLUGIN_PATH_STN . 'STN.php',array($save_to_nextcloud,'desactivate'));
    465 add_action('upgrader_process_complete',array($save_to_nextcloud,'update'), 10, 2);
    466 
    467416add_action('stn_Save', array($save_to_nextcloud,'stn_Save'));
    468417add_action('stn_SaveInProgress', array($save_to_nextcloud,'stn_SaveInProgress'));
     
    470419add_action('admin_post_saveNow',array($save_to_nextcloud,'stn_Save'));
    471420
    472 // Fonction rend visible le bouton des mises à jour automatique pour les themes
    473 function activer_maj_auto_theme() {
    474   add_theme_support('automatic-feed-links');
    475 }
    476 
    477 // Appelle la fonction
    478 add_action('after_setup_theme', 'activer_maj_auto_theme');
    479 
     421
     422//activation des maj auto pour WP
     423$next_event_timestamp = wp_next_scheduled('stn_SaveInProgress');
    480424
    481425// Si on a activer l'option pour gérer les auto update
    482 if(get_option("auto_update_dlwcloud") == "true"){
    483 
    484     //si aucune sauvegarde n'a encore été faite, on désactive les mises à jour automatiques
    485     add_filter('auto_update_core', '__return_false');
    486     add_filter('auto_update_theme', '__return_false');                               
    487     add_filter('auto_update_plugin', '__return_false');
    488     add_filter('auto_update_translation', '__return_false');       
    489        
     426if ( get_option("auto_update_dlwcloud") == "true" ) {
     427   
     428    global $wpdb;
     429
     430    // date dernière sauvegarde
     431    $sql = "SELECT name FROM " . $wpdb->prefix . "stn_saveInProgress ORDER BY id_zip DESC LIMIT 1";
     432    $lastSave = $wpdb->get_results($sql);
     433
     434    // Check if there are results
     435    if ($lastSave) {
     436        // Extract the last saved date from the result
     437        $date_str = $lastSave[0]->name;
     438       
     439        if (!empty($date_str)){
     440            // Extract the last 14 characters (assuming the date format is consistent)
     441            $date_substr = substr($date_str, -14, 14);
     442
     443            // Extract date components
     444            $year = substr($date_substr, 0, 4);
     445            $month = substr($date_substr, 4, 2);
     446            $day = substr($date_substr, 6, 2);
     447            $hour = substr($date_substr, 8, 2);
     448            $minute = substr($date_substr, 10, 2);
     449            $second = substr($date_substr, 12, 2);
     450
     451            // Calculate the difference between the current date and the last save date
     452            $last_save_date = new DateTime("$year-$month-$day $hour:$minute:$second");
     453            $current_date = new DateTime();
     454            $date_diff = $current_date->diff($last_save_date);
     455       
     456            // Check if the difference is less than two days
     457            if ($date_diff->days < 2) {
     458                add_filter('auto_update_core', '__return_true');
     459                add_filter('auto_update_theme', '__return_true');
     460                add_filter('auto_update_plugin', '__return_true');
     461                add_filter('auto_update_translation', '__return_true');
     462            } else {
     463                add_filter('auto_update_core', '__return_false');
     464                add_filter('auto_update_theme', '__return_false');
     465                add_filter('auto_update_plugin', '__return_false');
     466                add_filter('auto_update_translation', '__return_false');
     467            }
     468        }else{
     469            //sauvegarde en cours, pas d'auto-update
     470            add_filter('auto_update_core', '__return_false');
     471            add_filter('auto_update_theme', '__return_false');
     472            add_filter('auto_update_plugin', '__return_false');
     473            add_filter('auto_update_translation', '__return_false');           
     474        }
     475       
     476       
     477    }
    490478};
    491 
    492479
    493480/*menu administration*/
     
    769756                    </select>
    770757                    </br><p>Pour la bonne marche de votre site, les mises à jours ne devraient être effectuées qu'après une sauvegarde complète.
    771                     Si vous activez cette option, les plugins, le core et les thèmes pour lesquels vous avez activer les mises à jours automatiques, seront mis à jour automatiquement uniquement après la programmation enregistrée.
     758                    Si vous activez cette option, les plugins, le core et les thèmes seront mis à jour automatiquement uniquement après la programmation enregistrée.
    772759                    En cas de soucis, vous pourrez donc restaurez la dernière sauvegarde de votre site.</p>
    773                     <p>La sauvegarde manuelle n'active pas les mises à jours.</p>
    774760                    </tr>
    775761
  • stn-save-to-nextcloud/trunk/inc/MergeChunk.php

    r2930061 r3084337  
    101101wp_remote_request(get_option('url_dlwcloud').'/remote.php/dav/uploads/' . get_option('login_dlwcloud'). '/' . $inProgress['uuid'] . "/.file", $args ); 
    102102
    103 
    104 //On change l'état de la sauvegarde
     103// Change l'état de la sauvegarde suivant la case bdd only
    105104$datafinish = array(
    106105                "name" => $finalName,
    107106                "finish" => 1
    108107              );
    109 $wherefinish = array( "finish" => 0 );
    110 $wpdb->update( $wpdb->prefix.'stn_saveInProgress' , $datafinish, $wherefinish );
     108$wherefinish = array("finish" => 0);
     109$wpdb->update($wpdb->prefix.'stn_saveInProgress', $datafinish, $wherefinish);                     
    111110
    112 //Suppression des anciennes sauvegardes suivant BDD
    113 include ('CleanSave.php'); 
    114 
    115 // envoi du mail de notification
    116111$info= "La sauvegarde de votre site est terminée et enregistrée sur votre espace nextcloud !";
    117112$this->sendInfo("SUCCES",$info);
  • stn-save-to-nextcloud/trunk/readme.txt

    r3049241 r3084337  
    44Requires at least: 7.0
    55Requires PHP: 7.3
    6 Tested up to: 6.4
    7 Stable tag: 2.4.4
     6Tested up to: 6.5
     7Stable tag: 2.4.5
    88License: GPLv2
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5151== Changelog ==
    5252
     53= 2.4.5 =
     54
     55Optimisation de MAJ auto
     56
    5357= 2.4.4 =
    5458
Note: See TracChangeset for help on using the changeset viewer.