Changeset 3084337
- Timestamp:
- 05/10/2024 06:28:44 AM (22 months ago)
- Location:
- stn-save-to-nextcloud/trunk
- Files:
-
- 3 edited
-
STN.php (modified) (9 diffs)
-
inc/MergeChunk.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
stn-save-to-nextcloud/trunk/STN.php
r3049241 r3084337 8 8 * * Plugin URI: httsp://www.davelopweb.fr/ 9 9 * Description: Sauvegarde wordpress + Bdd mensuelle vers votre instance Nextcloud 10 * * Version: 2.4. 410 * * Version: 2.4.5 11 11 * Author: Dave DELALLEAU 12 12 * Author URI: https://www.davelopweb.fr/#contact … … 112 112 }; 113 113 114 115 114 //reprise suivant l'état de la sauvegarde 116 115 //switch 117 switch ($inProgress['etat']) { 116 switch ($inProgress['etat']) { 117 118 118 119 119 case "0": … … 250 250 }; 251 251 252 exit(); 252 exit(); 253 253 254 254 }; … … 261 261 //clean 262 262 global $wpdb; 263 264 //clean265 263 $wpdb->delete( $wpdb->prefix.'stn_saveInProgress', array("finish" => "0" ) ); 266 267 //nettoyage des fichiers résiduels si existant268 264 $filesInFtp = glob(ABSPATH . "stnSave_*"); 269 265 foreach($filesInFtp as $file){ unlink($file); }; … … 296 292 297 293 stn_save_to_nextcloud::stn_programSave(); 298 299 //lancement des mises à jours, si on a activer l'option pour gérer les auto update300 if(get_option("auto_update_dlwcloud") == "true"){301 302 stn_save_to_nextcloud::stn_run_manual_updates();303 304 };305 294 306 295 }; … … 391 380 } 392 381 } 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 433 385 } 434 386 … … 460 412 //Vue admin 461 413 $save_to_nextcloud=new stn_save_to_nextcloud(); 462 463 414 register_activation_hook( PLUGIN_PATH_STN . 'STN.php',array($save_to_nextcloud,'activate')); 464 415 register_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 467 416 add_action('stn_Save', array($save_to_nextcloud,'stn_Save')); 468 417 add_action('stn_SaveInProgress', array($save_to_nextcloud,'stn_SaveInProgress')); … … 470 419 add_action('admin_post_saveNow',array($save_to_nextcloud,'stn_Save')); 471 420 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'); 480 424 481 425 // 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 426 if ( 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 } 490 478 }; 491 492 479 493 480 /*menu administration*/ … … 769 756 </select> 770 757 </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. 772 759 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>774 760 </tr> 775 761 -
stn-save-to-nextcloud/trunk/inc/MergeChunk.php
r2930061 r3084337 101 101 wp_remote_request(get_option('url_dlwcloud').'/remote.php/dav/uploads/' . get_option('login_dlwcloud'). '/' . $inProgress['uuid'] . "/.file", $args ); 102 102 103 104 //On change l'état de la sauvegarde 103 // Change l'état de la sauvegarde suivant la case bdd only 105 104 $datafinish = array( 106 105 "name" => $finalName, 107 106 "finish" => 1 108 107 ); 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); 111 110 112 //Suppression des anciennes sauvegardes suivant BDD113 include ('CleanSave.php');114 115 // envoi du mail de notification116 111 $info= "La sauvegarde de votre site est terminée et enregistrée sur votre espace nextcloud !"; 117 112 $this->sendInfo("SUCCES",$info); -
stn-save-to-nextcloud/trunk/readme.txt
r3049241 r3084337 4 4 Requires at least: 7.0 5 5 Requires PHP: 7.3 6 Tested up to: 6. 47 Stable tag: 2.4. 46 Tested up to: 6.5 7 Stable tag: 2.4.5 8 8 License: GPLv2 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 51 51 == Changelog == 52 52 53 = 2.4.5 = 54 55 Optimisation de MAJ auto 56 53 57 = 2.4.4 = 54 58
Note: See TracChangeset
for help on using the changeset viewer.