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

452: CLI: Remove deprecated GP_CLI classes. #454

Merged
merged 1 commit into from
Sep 26, 2017
Merged
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
74 changes: 0 additions & 74 deletions gp-includes/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,77 +26,3 @@ function gp_cli_register() {
// New style commands
WP_CLI::add_command( 'glotpress translation-set', 'GP_CLI_Translation_Set' );
}

class GP_CLI {

public $short_options = '';
public $long_options = array();
public $options = array();
public $program_name = '';
public $usage = '';
public $args;
public $project;
public $locale;
public $translation_set;

public function __construct() {
_deprecated_function( 'GP_CLI::__construct', '', 'WP_CLI_Command' );

global $argv;
if ( gp_array_get( $_SERVER, 'HTTP_HOST' ) ) {
die('CLI only!');
}
if ( !defined( 'STDERR' ) ) {
define( 'STDERR', fopen( 'php://stderr', 'w' ) );
}

$this->program_name = array_shift( $argv );
$this->options = getopt( $this->short_options, $this->long_options );
$this->args = $argv;
}

public function usage() {
$this->error( 'php '.$this->program_name.' '.$this->usage );
}

public function to_stderr( $text, $no_new_line = false ) {
$text .= ($no_new_line? '' : "\n");
fwrite( STDERR, $text );
}

public function error( $message, $exit_code = 1 ) {
$this->to_stderr( $message );
exit( $exit_code );
}
}

class GP_Translation_Set_Script extends GP_CLI {

var $short_options = 'p:l:t:';

var $usage = "-p <project-path> -l <locale> [-t <translation-set-slug>]";

public function run() {
if ( !isset( $this->options['l'] ) || !isset( $this->options['p'] ) ) {
$this->usage();
}
$this->project = GP::$project->by_path( $this->options['p'] );
if ( !$this->project ) $this->error( __( 'Project not found!', 'glotpress' ) );

$this->locale = GP_Locales::by_slug( $this->options['l'] );
if ( !$this->locale ) $this->error( __( 'Locale not found!', 'glotpress' ) );

$this->options['t'] = gp_array_get( $this->options, 't', 'default' );

$this->translation_set = GP::$translation_set->by_project_id_slug_and_locale( $this->project->id, $this->options['t'], $this->locale->slug );
if ( !$this->translation_set ) $this->error( __( 'Translation set not found!', 'glotpress' ) );

$this->action_on_translation_set( $this->translation_set );
}

public function action_on_translation_set( $translation_set ) {
// define this function in a subclass

do_action( 'gp_cli_action_on_translation_set', $translation_set );
}
}