better debugging
This commit is contained in:
parent
e45cdc199d
commit
9c20bae4f3
2 changed files with 58 additions and 22 deletions
|
@ -3,8 +3,8 @@ Contributors: cadeyrn
|
||||||
Donate link: https://paypal.me/petermolnar/3
|
Donate link: https://paypal.me/petermolnar/3
|
||||||
Tags: backup, YAML, flat files
|
Tags: backup, YAML, flat files
|
||||||
Requires at least: 3.0
|
Requires at least: 3.0
|
||||||
Tested up to: 4.4
|
Tested up to: 4.4.2
|
||||||
Stable tag: 0.1
|
Stable tag: 0.1.1
|
||||||
License: GPLv3
|
License: GPLv3
|
||||||
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
||||||
Required minimum PHP version: 5.3
|
Required minimum PHP version: 5.3
|
||||||
|
@ -39,6 +39,11 @@ Version numbering logic:
|
||||||
* every .B version indicates new features.
|
* every .B version indicates new features.
|
||||||
* every ..C indicates bugfixes for A.B version.
|
* every ..C indicates bugfixes for A.B version.
|
||||||
|
|
||||||
|
= 0.1.1 =
|
||||||
|
*2016-03-08*
|
||||||
|
|
||||||
|
* better debugging
|
||||||
|
|
||||||
= 0.1 =
|
= 0.1 =
|
||||||
*2015-12-10*
|
*2015-12-10*
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
Plugin Name: wp-flatbackups
|
Plugin Name: wp-flatbackups
|
||||||
Plugin URI: https://github.com/petermolnar/wp-flatbackups
|
Plugin URI: https://github.com/petermolnar/wp-flatbackups
|
||||||
Description: auto-export WordPress content to flat YAML + Markdown files
|
Description: auto-export WordPress content to flat YAML + Markdown files
|
||||||
Version: 0.1
|
Version: 0.1.1
|
||||||
Author: Peter Molnar <hello@petermolnar.eu>
|
Author: Peter Molnar <hello@petermolnar.eu>
|
||||||
Author URI: http://petermolnar.eu/
|
Author URI: http://petermolnar.eu/
|
||||||
License: GPLv3
|
License: GPLv3
|
||||||
|
@ -54,7 +54,7 @@ class WP_FLATBACKUPS {
|
||||||
public static function export_yaml () {
|
public static function export_yaml () {
|
||||||
|
|
||||||
if (!function_exists('yaml_emit')) {
|
if (!function_exists('yaml_emit')) {
|
||||||
static::debug('`yaml_emit` function missing. Please install the YAML extension; otherwise this plugin will not work');
|
static::debug('`yaml_emit` function missing. Please install the YAML extension; otherwise this plugin will not work', 4);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ class WP_FLATBACKUPS {
|
||||||
foreach ( $mkdir as $dir ) {
|
foreach ( $mkdir as $dir ) {
|
||||||
if ( !is_dir($dir)) {
|
if ( !is_dir($dir)) {
|
||||||
if (!mkdir( $dir )) {
|
if (!mkdir( $dir )) {
|
||||||
static::debug_log('Failed to create ' . $dir . ', exiting YAML creation');
|
static::debug_log('Failed to create ' . $dir . ', exiting YAML creation', 4);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,12 +108,12 @@ class WP_FLATBACKUPS {
|
||||||
$attachment_path = get_attached_file( $aid );
|
$attachment_path = get_attached_file( $aid );
|
||||||
$attachment_file = basename( $attachment_path);
|
$attachment_file = basename( $attachment_path);
|
||||||
$target_file = $flatdir . DIRECTORY_SEPARATOR . $attachment_file;
|
$target_file = $flatdir . DIRECTORY_SEPARATOR . $attachment_file;
|
||||||
//static::debug ('should ' . $post->post_name . ' have this attachment?: ' . $attachment_file );
|
static::debug ('should ' . $post->post_name . ' have this attachment?: ' . $attachment_file, 7 );
|
||||||
if ( !is_file($target_file)) {
|
if ( !is_file($target_file)) {
|
||||||
if (!link( $attachment_path, $target_file )) {
|
if (!link( $attachment_path, $target_file )) {
|
||||||
static::debug("could not hardlink '$attachment_path' to '$target_file'; trying to copy");
|
static::debug("could not hardlink '$attachment_path' to '$target_file'; trying to copy", 5);
|
||||||
if (!copy($attachment_path, $target_file )) {
|
if (!copy($attachment_path, $target_file )) {
|
||||||
static::debug("could not copy '$attachment_path' to '$target_file'; saving attachment failed!");
|
static::debug("could not copy '$attachment_path' to '$target_file'; saving attachment failed!", 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ class WP_FLATBACKUPS {
|
||||||
$cout = yaml_emit($c, YAML_UTF8_ENCODING );
|
$cout = yaml_emit($c, YAML_UTF8_ENCODING );
|
||||||
$cout .= "---\n" . $comment->comment_content;
|
$cout .= "---\n" . $comment->comment_content;
|
||||||
|
|
||||||
//static::debug ('Exporting comment #' . $comment->comment_ID. ' to ' . $cfile );
|
static::debug ('Exporting comment #' . $comment->comment_ID. ' to ' . $cfile, 6 );
|
||||||
file_put_contents ($cfile, $cout);
|
file_put_contents ($cfile, $cout);
|
||||||
touch ( $cfile, $c_timestamp );
|
touch ( $cfile, $c_timestamp );
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ class WP_FLATBACKUPS {
|
||||||
$out = static::yaml();
|
$out = static::yaml();
|
||||||
|
|
||||||
// write log
|
// write log
|
||||||
//static::debug ('Exporting #' . $post->ID . ', ' . $post->post_name . ' to ' . $flatfile );
|
static::debug ('Exporting #' . $post->ID . ', ' . $post->post_name . ' to ' . $flatfile, 6 );
|
||||||
file_put_contents ($flatfile, $out);
|
file_put_contents ($flatfile, $out);
|
||||||
touch ( $flatfile, $post_timestamp );
|
touch ( $flatfile, $post_timestamp );
|
||||||
return true;
|
return true;
|
||||||
|
@ -188,7 +188,7 @@ class WP_FLATBACKUPS {
|
||||||
public static function yaml ( $postid = false ) {
|
public static function yaml ( $postid = false ) {
|
||||||
|
|
||||||
if (!function_exists('yaml_emit')) {
|
if (!function_exists('yaml_emit')) {
|
||||||
static::debug('`yaml_emit` function missing. Please install the YAML extension; otherwise this plugin will not work');
|
static::debug('`yaml_emit` function missing. Please install the YAML extension; otherwise this plugin will not work', 4);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,23 +382,54 @@ class WP_FLATBACKUPS {
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param int $level
|
* @param int $level
|
||||||
|
*
|
||||||
|
* @output log to syslog | wp_die on high level
|
||||||
|
* @return false on not taking action, true on log sent
|
||||||
*/
|
*/
|
||||||
static function debug( $message, $level = LOG_NOTICE ) {
|
public static function debug( $message, $level = LOG_NOTICE ) {
|
||||||
|
if ( empty( $message ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
if ( @is_array( $message ) || @is_object ( $message ) )
|
if ( @is_array( $message ) || @is_object ( $message ) )
|
||||||
$message = json_encode($message);
|
$message = json_encode($message);
|
||||||
|
|
||||||
|
$levels = array (
|
||||||
|
LOG_EMERG => 0, // system is unusable
|
||||||
|
LOG_ALERT => 1, // Alert action must be taken immediately
|
||||||
|
LOG_CRIT => 2, // Critical critical conditions
|
||||||
|
LOG_ERR => 3, // Error error conditions
|
||||||
|
LOG_WARNING => 4, // Warning warning conditions
|
||||||
|
LOG_NOTICE => 5, // Notice normal but significant condition
|
||||||
|
LOG_INFO => 6, // Informational informational messages
|
||||||
|
LOG_DEBUG => 7, // Debug debug-level messages
|
||||||
|
);
|
||||||
|
|
||||||
switch ( $level ) {
|
// number for number based comparison
|
||||||
case LOG_ERR :
|
// should work with the defines only, this is just a make-it-sure step
|
||||||
wp_die( '<h1>Error:</h1>' . '<p>' . $message . '</p>' );
|
$level_ = $levels [ $level ];
|
||||||
exit;
|
|
||||||
default:
|
// in case WordPress debug log has a minimum level
|
||||||
if ( !defined( 'WP_DEBUG' ) || WP_DEBUG != true )
|
if ( defined ( 'WP_DEBUG_LEVEL' ) ) {
|
||||||
return;
|
$wp_level = $levels [ WP_DEBUG_LEVEL ];
|
||||||
break;
|
if ( $level_ > $wp_level ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error_log( __CLASS__ . " => " . $message );
|
// ERR, CRIT, ALERT and EMERG
|
||||||
|
if ( 3 >= $level_ ) {
|
||||||
|
wp_die( '<h1>Error:</h1>' . '<p>' . $message . '</p>' );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$trace = debug_backtrace();
|
||||||
|
$caller = $trace[1];
|
||||||
|
$parent = $caller['function'];
|
||||||
|
|
||||||
|
if (isset($caller['class']))
|
||||||
|
$parent = $caller['class'] . '::' . $parent;
|
||||||
|
|
||||||
|
return error_log( "{$parent}: {$message}" );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -415,4 +446,4 @@ class WP_FLATBACKUPS {
|
||||||
|
|
||||||
$WP_FLATBACKUPS = new WP_FLATBACKUPS();
|
$WP_FLATBACKUPS = new WP_FLATBACKUPS();
|
||||||
|
|
||||||
endif;
|
endif;
|
||||||
|
|
Loading…
Reference in a new issue