<commit_before><?php
App::uses('Folder', 'Utility');
App::uses('File', 'Utility');
App::uses('BackgroundJobsTool', 'Tools');
require_once 'AppShell.php';

/**
 * @property Job $Job
 * @property Server $Server
 * @property Feed $Feed
 * @property User $User
 */
class ServerShell extends AppShell
{
    public $uses = array('Server', 'Task', 'Job', 'User', 'Feed');

    public function list()
    {
        $servers = $this->Server->find('all', [
            'fields' => ['Server.id', 'Server.name', 'Server.url'],
            'recursive' => 0
        ]);
        foreach ($servers as $server) {
            echo sprintf(
                '%sServer #%s :: %s :: %s',
                PHP_EOL,
                $server['Server']['id'],
                $server['Server']['name'],
                $server['Server']['url']
            );
        }
        echo PHP_EOL;
    }

    public function listServers()
    {
        $servers = $this->Server->find('all', [
            'fields' => ['Server.id', 'Server.name', 'Server.url'],
            'recursive' => 0
        ]);
        $res = ['servers' => array_column($servers, 'Server')];
        echo $this->json($res) . PHP_EOL;
    }

    public function test()
    {
        if (empty($this->args[0])) {
            die('Usage: ' . $this->Server->command_line_functions['console_automation_tasks']['data']['Test'] . PHP_EOL);
        }

        $serverId = intval($this->args[0]);
        $server = $this->getServer($serverId);

        $res = $this->Server->runConnectionTest($server, false);
        echo $this->json($res) . PHP_EOL;
    }

    public function pullAll()
    {
        if (empty($this->args[0])) {
            die('Usage: ' . $this->Server->command_line_functions['console_automation_tasks']['data']['PullAll'] . PHP_EOL);
        }

        $userId = $this->args[0];
        $user = $this->getUser($userId);

        if (!empty($this->args[1])) {
            $technique = $this->args[1];
        } else {
            $technique = 'full';
        }<commit_msg>new: [CLI] Option to fetch remote server index<commit_after><?php
App::uses('Folder', 'Utility');
App::uses('File', 'Utility');
App::uses('BackgroundJobsTool', 'Tools');
require_once 'AppShell.php';

/**
 * @property Job $Job
 * @property Server $Server
 * @property Feed $Feed
 * @property User $User
 */
class ServerShell extends AppShell
{
    public $uses = array('Server', 'Task', 'Job', 'User', 'Feed');

    public function getOptionParser()
    {
        $parser = parent::getOptionParser();
        $parser->addSubcommand('fetchIndex', [
            'help' => __('Fetch remote instance event index.'),
            'parser' => array(
                'arguments' => array(
                    'server_id' => ['help' => __('Remote server ID.'), 'required' => true],
                ),
            )
        ]);
        return $parser;
    }

    public function list()
    {
        $servers = $this->Server->find('all', [
            'fields' => ['Server.id', 'Server.name', 'Server.url'],
            'recursive' => 0
        ]);
        foreach ($servers as $server) {
            echo sprintf(
                '%sServer #%s :: %s :: %s',
                PHP_EOL,
                $server['Server']['id'],
                $server['Server']['name'],
                $server['Server']['url']
            );
        }
        echo PHP_EOL;
    }

    public function listServers()
    {
        $servers = $this->Server->find('all', [
            'fields' => ['Server.id', 'Server.name', 'Server.url'],
            'recursive' => 0
        ]);
        $res = ['servers' => array_column($servers, 'Server')];
        echo $this->json($res) . PHP_EOL;
    }

    public function test()
    {
        if (empty($this->args[0])) {
            die('Usage: ' . $this->Server->command_line_functions['console_automation_tasks']['data']['Test'] . PHP_EOL);
        }

        $serverId = intval($this->args[0]);
        $server = $this->getServer($serverId);

        $res = $this->Server->runConnectionTest($server, false);
        echo $this->json($res) . PHP_EOL;
    }

    public function fetchIndex()
    {
        $serverId = intval($this->args[0]);
        $server = $this->getServer($serverId);
        $serverSync = new ServerSyncTool($server, $this->Server->setupSyncRequest($server));
        $index = $this->Server->getEventIndexFromServer($serverSync);
        echo $this->json($index) . PHP_EOL;
    }

    public function pullAll()
    {
        if (empty($this->args[0])) {
            die('Usage: ' . $this->Server->command_line_functions['console_automation_tasks']['data']['PullAll'] . PHP_EOL);
        }

        $userId = $this->args[0];
        $user = $this->getUser($userId);

        if (!empty($this->args[1])) {
            $technique = $this->args[1];
        } else {
            $technique = 'full';
        }
{'fraction_non_alphanumeric': 0.1888111888111888, 'fraction_numerical': 0.0034965034965034965, 'mean_word_length': 2.141472868217054, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7230214', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1458, 'n_words': 276}