xref: /plugin/elasticsearch/cli.php (revision 390782ab860b2914538559ad513c713f9f031393)
1*390782abSAndreas Gohr#!/usr/bin/php
2*390782abSAndreas Gohr<?php
3*390782abSAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__).'/../../../').'/');
4*390782abSAndreas Gohrdefine('NOSESSION', 1);
5*390782abSAndreas Gohrrequire_once(DOKU_INC.'inc/init.php');
6*390782abSAndreas Gohrrequire_once dirname(__FILE__) . '/vendor/autoload.php';
7*390782abSAndreas Gohr
8*390782abSAndreas Gohrclass elasticsearch_cli extends DokuCLI {
9*390782abSAndreas Gohr
10*390782abSAndreas Gohr    /**
11*390782abSAndreas Gohr     * Register options and arguments on the given $options object
12*390782abSAndreas Gohr     *
13*390782abSAndreas Gohr     * @param DokuCLI_Options $options
14*390782abSAndreas Gohr     * @return void
15*390782abSAndreas Gohr     */
16*390782abSAndreas Gohr    protected function setup(DokuCLI_Options $options) {
17*390782abSAndreas Gohr        $options->setHelp('Manage the elastic search index');
18*390782abSAndreas Gohr        $options->registerCommand('index', 'Index all pages in the wiki');
19*390782abSAndreas Gohr        $options->registerCommand('createmapping', 'Create the needed field mapping at the configured servers');
20*390782abSAndreas Gohr    }
21*390782abSAndreas Gohr
22*390782abSAndreas Gohr    /**
23*390782abSAndreas Gohr     * Your main program
24*390782abSAndreas Gohr     *
25*390782abSAndreas Gohr     * Arguments and options have been parsed when this is run
26*390782abSAndreas Gohr     *
27*390782abSAndreas Gohr     * @param DokuCLI_Options $options
28*390782abSAndreas Gohr     * @return void
29*390782abSAndreas Gohr     */
30*390782abSAndreas Gohr    protected function main(DokuCLI_Options $options) {
31*390782abSAndreas Gohr        $cmd = $options->getCmd();
32*390782abSAndreas Gohr        switch ($cmd) {
33*390782abSAndreas Gohr            case 'createmapping':
34*390782abSAndreas Gohr                /** @var helper_plugin_elasticsearch_client $hlp */
35*390782abSAndreas Gohr                $hlp = plugin_load('helper', 'elasticsearch_client');
36*390782abSAndreas Gohr                $result = $hlp->createMapping();
37*390782abSAndreas Gohr                if($result->hasError()){
38*390782abSAndreas Gohr                    $this->error($result->getError());
39*390782abSAndreas Gohr                } else {
40*390782abSAndreas Gohr                    $this->success('Mapping created');
41*390782abSAndreas Gohr                }
42*390782abSAndreas Gohr                break;
43*390782abSAndreas Gohr            default:
44*390782abSAndreas Gohr                $this->error('No command provided');
45*390782abSAndreas Gohr                exit(1);
46*390782abSAndreas Gohr        }
47*390782abSAndreas Gohr
48*390782abSAndreas Gohr
49*390782abSAndreas Gohr    }
50*390782abSAndreas Gohr
51*390782abSAndreas Gohr
52*390782abSAndreas Gohr}
53*390782abSAndreas Gohr
54*390782abSAndreas Gohr$cli = new elasticsearch_cli();
55*390782abSAndreas Gohr$cli->run();