Skip to content

Commit

Permalink
Revert "Urls for minion"
Browse files Browse the repository at this point in the history
  • Loading branch information
toitzi authored Mar 8, 2019
1 parent 210e531 commit 5cd1798
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 219 deletions.
32 changes: 12 additions & 20 deletions modules/minion/classes/Kohana/Minion/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
class Kohana_Minion_CLI {

public static $wait_msg = 'Press any key to continue...';
public static $invalid_option_msg = 'This is not a valid option. Please try again.';


protected static $foreground_colors = [
'black' => '0;30',
'dark_gray' => '1;30',
Expand Down Expand Up @@ -116,11 +115,14 @@ public static function options($options = NULL)
*
* Usage:
*
* // Waits for any key press
* Minion_CLI::read();
*
* // Takes any input
* $color = Minion_CLI::read('What is your favorite color?');
*
* // Will only accept the options in the array
* $ready = Minion_CLI::read('Are you ready?', ['y','n']);
* $ready = Minion_CLI::read('Are you ready?', array('y','n'));
*
* @param string $text text to show user before waiting for input
* @param array $options array of options the user is shown
Expand All @@ -129,24 +131,21 @@ public static function options($options = NULL)
public static function read($text = '', array $options = NULL)
{
// If a question has been asked with the read
$options_output = '';
if ( ! empty($options))
{
$text .= ' [ '.implode(', ', $options).' ]';
}
if ($text != '')
{
$text .= ': ';
$options_output = ' [ '.implode(', ', $options).' ]';
}

fwrite(STDOUT, $text);
fwrite(STDOUT, $text.$options_output.': ');

// Read the input from keyboard.
$input = trim(fgets(STDIN));

// If options are provided and the choice is not in the array, tell them to try again
if ( ! empty($options) && ! in_array($input, $options))
{
Minion_CLI::write(Minion_CLI::$invalid_option_msg);
Minion_CLI::write('This is not a valid option. Please try again.');

$input = Minion_CLI::read($text, $options);
}
Expand Down Expand Up @@ -234,15 +233,7 @@ public static function write_replace($text = '', $end_line = FALSE)
{
// Append a newline if $end_line is TRUE
$text = $end_line ? $text.PHP_EOL : $text;

if (Kohana::$is_windows)
{
fwrite(STDOUT, "\r".$text);
}
else
{
fwrite(STDOUT, "\r\033[K".$text);
}
fwrite(STDOUT, "\r\033[K".$text);
}

/**
Expand All @@ -256,7 +247,7 @@ public static function write_replace($text = '', $end_line = FALSE)
* @param int $seconds number of seconds
* @param bool $countdown show a countdown or not
*/
public static function wait($seconds = 0, $countdown = FALSE)
public static function wait($seconds = 0, $countdown = false)
{
if ($countdown === TRUE)
{
Expand Down Expand Up @@ -320,4 +311,5 @@ public static function color($text, $foreground, $background = null)

return $string;
}

}
22 changes: 0 additions & 22 deletions modules/minion/classes/Kohana/Minion/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,26 +362,4 @@ protected function _compile_task_list(array $files, $prefix = '')
return $output;
}

/**
* Sets the domain name for minion tasks
* Minion tasks have no $_SERVER variables; to use the base url functions
* the domain name can be set in the site config file, or as argument.
*
* @param string $domain_name the url of the server: example https://www.example.com
*/
public static function set_domain_name($domain_name = '')
{
if (Request::$initial === NULL)
{
$domain_name = empty($domain_name) ? Arr::get(Kohana::$config->load('site'), 'minion_domain_name', '') : $domain_name;

// Add trailing slash
Kohana::$base_url = preg_replace('~^https?://[^/]+$~', '$0/', $domain_name);

// Set HTTPS for https based urls
$_SERVER['HTTPS'] = (preg_match_all('#(https)://#i', Kohana::$base_url, $result) === 1);

Request::$initial = Request::factory();
}
}
}
87 changes: 0 additions & 87 deletions modules/minion/guide/minion/cli.md

This file was deleted.

3 changes: 1 addition & 2 deletions modules/minion/guide/minion/menu.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
## [Minion]()
- [Setup](setup)
- [Writing a Task](tasks)
- [CLI](cli)
- [Writing a Task](tasks)
4 changes: 1 addition & 3 deletions modules/minion/guide/minion/setup.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Minion Setup

[!!] Since Kohana `3.3.x`, minion requires no additional setup to use.

[!!] If your code uses links check the [using links](tasks#using-links) under tasks for domain configuration.
[!!] Since Kohana `3.3.x`, minion requires no additional setup to use.
18 changes: 4 additions & 14 deletions modules/minion/guide/minion/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Writing a task in minion is very easy. Simply create a new class called `Task_<T

class Task_Demo extends Minion_Task
{
protected $_options = [
protected $_options = array(
'foo' => 'bar',
'bar' => NULL,
];
);

/**
* This is a demo task
Expand All @@ -26,8 +26,8 @@ Writing a task in minion is very easy. Simply create a new class called `Task_<T
You'll notice a few things here:

- You need a main `_execute()` method. It should take one array parameter.
- This parameter contains any command line options passed to the task.
- For example, if you call the task above with `./minion --task=demo --foo=foobar` then `$params` will contain: `array('foo' => 'foobar', 'bar' => NULL)`
- This parameter contains any command line options passed to the task.
- For example, if you call the task above with `./minion --task=demo --foo=foobar` then `$params` will contain: `array('foo' => 'foobar', 'bar' => NULL)`
- It needs to have a `protected $_options` array. This is a list of parameters you want to accept for this task. Any parameters passed to the task not in this list will be rejected.

## Namespacing Tasks
Expand Down Expand Up @@ -69,13 +69,3 @@ Tasks can have built-in help. Minion will read class docblocks that you specify:
class Minion_Task_Demo extends Minion_Task

The `@` tags in the class comments will also be displayed in a human readable format. When writing your task comments, you should specify how to use it, and any parameters it accepts.

# Using links

If the output task contains links which are generated using the build in URL functions you should configure the domain name for the task.
The `Minion_Task::set_domain_name()` method takes care of this.

There are two options to set the domain:

- As an argument of the function `Minion_Task::set_domain_name('https://www.example.org')`.
- Using the site configuration: add the configuration parameter `minion_domain_name` to the `site.php` config file (`'minion_domain_name' => 'https://www.example.org'`) and call the method in your task without an argument `Minion_Task::set_domain_name()`.
71 changes: 0 additions & 71 deletions modules/minion/tests/minion/TaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,6 @@

class Minion_TaskTest extends Kohana_Unittest_TestCase
{
protected static $initial_request;

/**
* Sets up the environment
*/
// @codingStandardsIgnoreStart
public function setUp()
// @codingStandardsIgnoreEnd
{
parent::setUp();
Kohana::$config->load('url')->set(
'trusted_hosts',
['www\.example\.com', 'www\.example2\.com']
);

Kohana::$config->load('site')->set(
'minion_domain_name',
'http://www.example2.com'
);

// Keep the old request object
self::$initial_request = Request::$initial;
Request::$initial = NULL;
}

/**
* Restores the environment
*/
// @codingStandardsIgnoreStart
public function tearDown()
// @codingStandardsIgnoreEnd
{
Request::$initial = self::$initial_request;

parent::tearDown();
}

/**
* Provides test data for test_convert_task_to_class_name()
*
Expand Down Expand Up @@ -104,38 +67,4 @@ public function test_convert_class_to_task($expected, $class)
{
$this->assertSame($expected, Minion_Task::convert_class_to_task($class));
}

/**
* Provides test data for test_set_domain_name()
*
* @return array
*/
public function provider_set_domain_name()
{
return [
['https://www.example.com/welcome', 'https://www.example.com', 'welcome'],
['http://www.example.com/welcome', 'http://www.example.com', 'welcome'],
['http://www.example2.com/welcome', NULL, 'welcome'],
['http://www.example.com:8080/welcome', 'http://www.example.com:8080', 'welcome'],
];
}

/**
* Tests that a task can be converted to a class name
*
* @test
* @covers Minion_Task::set_domain_name
* @dataProvider provider_set_domain_name
* @param string Expected domain url
* @param string Input domain name
*/
public function test_set_domain_name($expected, $name, $uri)
{
Minion_Task::set_domain_name($name);

$this->assertSame(
$expected,
URL::site($uri, TRUE, FALSE)
);
}
}

0 comments on commit 5cd1798

Please sign in to comment.