cleanup + fail in php < 5.2 + log tune

This commit is contained in:
Peter Molnar 2016-01-05 22:58:06 +00:00
parent d086701481
commit e45cdc199d
3 changed files with 19 additions and 22 deletions

View file

@ -2,7 +2,7 @@
"name": "petermolnar/wp-flatbackups", "name": "petermolnar/wp-flatbackups",
"description": "WordPress plugin to auto-export WordPress content to flat YAML + HTML files", "description": "WordPress plugin to auto-export WordPress content to flat YAML + HTML files",
"require": { "require": {
"php": ">=5.3.0", "php": ">=5.3.0",
"ext-yaml": "^1.2" "ext-yaml": "^1.2"
}, },
"license": "GPLv3", "license": "GPLv3",
@ -10,7 +10,7 @@
{ {
"name": "Peter Molnar", "name": "Peter Molnar",
"email": "hello@petermolnar.eu", "email": "hello@petermolnar.eu",
"homepage": "https://petermolnar.eu" "homepage": "https://petermolnar.eu"
} }
] ]
} }

View file

@ -1,6 +1,6 @@
=== wp-flatbackups === === wp-flatbackups ===
Contributors: cadeyrn Contributors: cadeyrn
Donate link: 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

View file

@ -31,12 +31,21 @@ if (!class_exists('WP_FLATBACKUPS')):
class WP_FLATBACKUPS { class WP_FLATBACKUPS {
public function __construct () { public function __construct () {
if (!function_exists('yaml_emit')) { register_activation_hook( __FILE__ , array( &$this, 'plugin_activate' ) );
static::debug('`yaml_emit` function missing. Please install the YAML extension; otherwise this plugin will not work'); add_action( 'wp_footer', array( &$this, 'export_yaml'));
}
/**
* activate hook
*/
public static function plugin_activate() {
if ( version_compare( phpversion(), 5.3, '<' ) ) {
die( 'The minimum PHP version required for this plugin is 5.3' );
} }
add_action( 'wp_footer', array( &$this, 'export_yaml')); if (!function_exists('yaml_emit')) {
die('`yaml_emit` function missing. Please install the YAML extension; otherwise this plugin will not work');
}
} }
/** /**
@ -99,7 +108,7 @@ 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 );
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");
@ -152,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 );
file_put_contents ($cfile, $cout); file_put_contents ($cfile, $cout);
touch ( $cfile, $c_timestamp ); touch ( $cfile, $c_timestamp );
} }
@ -165,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 );
file_put_contents ($flatfile, $out); file_put_contents ($flatfile, $out);
touch ( $flatfile, $post_timestamp ); touch ( $flatfile, $post_timestamp );
return true; return true;
@ -392,18 +401,6 @@ class WP_FLATBACKUPS {
error_log( __CLASS__ . " => " . $message ); error_log( __CLASS__ . " => " . $message );
} }
/**
* debug log messages, if needed
*
public static function debug( $message) {
if (is_object($message) || is_array($message))
$message = json_encode($message);
if ( defined('WP_DEBUG') && WP_DEBUG == true )
error_log ( __CLASS__ . ' => ' . $message);
}
*/
/** /**
* *
*/ */