Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formatting & basic tests #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[{*.md,*.json,*.sh,*.js,*.css}]
indent_size = 2

[{*.md,*.json}]
max_line_length = null
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
*.lock
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: php
php:
- '5.6'
- nightly
install: composer install
script: composer test
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# WP Sync DB CLI
An addon for [WP Sync DB](https://github.com/slang800/wp-sync-db) that allows you to execute migrations using a function call or via WP-CLI

An addon for [WP Sync DB](https://github.com/slang800/wp-sync-db) that allows you to execute migrations using a function call or via WP-CLI.
58 changes: 30 additions & 28 deletions class/command.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,40 @@
/**
* Migrate your DB using WP Sync DB.
*/
class WPSDBCLI extends WP_CLI_Command {
class WPSDBCLI extends WP_CLI_Command
{

/**
* Run a migration.
*
* ## OPTIONS
*
* <profile>
* : ID of the profile to use for the migration.
*
* ## EXAMPLES
*
* wp wpsdb migrate 1
*
* @synopsis <profile>
*
* @since 1.0
*/
public function migrate( $args, $assoc_args ) {
$profile = $args[0];
/**
* Run a migration.
*
* ## OPTIONS
*
* <profile>
* : ID of the profile to use for the migration.
*
* ## EXAMPLES
*
* wp wpsdb migrate 1
*
* @synopsis <profile>
*
* @since 1.0
*/
public function migrate($args, $assoc_args)
{
$profile = $args[0];

$result = wpsdb_migrate( $profile );
$result = wpsdb_migrate($profile);

if ( true === $result ) {
WP_CLI::success( __( 'Migration successful.', 'wp-sync-db-cli' ) );
return;
}
if (true === $result) {
WP_CLI::success(__('Migration successful.', 'wp-sync-db-cli'));
return;
}

WP_CLI::warning( $result->get_error_message() );
return;
}
WP_CLI::warning($result->get_error_message());
return;
}

}

WP_CLI::add_command( 'wpsdb', 'WPSDBCLI' );
WP_CLI::add_command('wpsdb', 'WPSDBCLI');
361 changes: 195 additions & 166 deletions class/wpsdb-cli.php

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
"keywords": ["plugin","wordpress","wp-sync-db","cli"],
"require": {
"composer/installers": "~1.0.6"
},
"require-dev": {
"phpfmt/fmt": "^19.6"
},
"scripts": {
"test": "./test.sh"
}
}
11 changes: 11 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e
set -o pipefail

files=(*.php class/*.php);
for file in "${files[@]}"
do
php -l "$file";
php vendor/phpfmt/fmt/fmt.phar --psr1 --psr2 -o=- "$file" | diff -U3 \
--label "$file (correct formatting)" --label "$file (original)" - "$file";
done
42 changes: 23 additions & 19 deletions wp-sync-db-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,36 @@
Version: 1.0b1
Author URI: http://slang.cx
Network: True
*/
*/

require_once 'version.php';
$GLOBALS['wpsdb_meta']['wp-sync-db-cli']['folder'] = basename( plugin_dir_path( __FILE__ ) );
$GLOBALS['wpsdb_meta']['wp-sync-db-cli']['folder'] = basename(plugin_dir_path(__FILE__));

function wp_sync_db_cli_loaded() {
if ( ! class_exists( 'WPSDB_Addon' ) ) return;
function wp_sync_db_cli_loaded()
{
if (!class_exists('WPSDB_Addon')) {
return;
}

require_once __DIR__ . '/class/wpsdb-cli.php';
require_once __DIR__ . '/class/wpsdb-cli.php';

// register with wp-cli if it's running, and command hasn't already been defined elsewhere
if ( defined( 'WP_CLI' ) && WP_CLI && ! class_exists( 'WPSDBCLI' ) ) {
require_once __DIR__ . '/class/command.php';
}
// register with wp-cli if it's running, and command hasn't already been defined elsewhere
if (defined('WP_CLI') && WP_CLI && !class_exists('WPSDBCLI')) {
require_once __DIR__ . '/class/command.php';
}

load_plugin_textdomain( 'wp-sync-db-cli', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
load_plugin_textdomain('wp-sync-db-cli', false, dirname(plugin_basename(__FILE__)) . '/languages/');

global $wpsdb_cli;
$wpsdb_cli = new WPSDB_CLI( __FILE__ );
global $wpsdb_cli;
$wpsdb_cli = new WPSDB_CLI(__FILE__);
}
add_action( 'plugins_loaded', 'wp_sync_db_cli_loaded', 20 );
add_action('plugins_loaded', 'wp_sync_db_cli_loaded', 20);

function wpsdb_migrate( $profile ) {
global $wpsdb_cli;
if( empty( $wpsdb_cli ) ) {
return new WP_Error( 'wpsdb_cli_error', __( 'WP Sync DB CLI class not available', 'wp-sync-db-cli' ) );
}
return $wpsdb_cli->cli_migration( $profile );
function wpsdb_migrate($profile)
{
global $wpsdb_cli;
if (empty($wpsdb_cli)) {
return new WP_Error('wpsdb_cli_error', __('WP Sync DB CLI class not available', 'wp-sync-db-cli'));
}
return $wpsdb_cli->cli_migration($profile);
}