Subversion Repositories xrowsearch

[/] [trunk/] [bin/] [xrowsearch.php] - Blame information for rev 1

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1 rrobert
<?php
2
 
3
$cli = eZCLI::instance();
4
$script = eZScript::instance( array(
5
    'description' => ( "eZ Publish Script Executor\n\n" . "Allows execution of simple PHP scripts which uses eZ Publish functionality,\n" . "when the script is called all necessary initialization is done\n" . "\n" . "ezexec.php myscript.php" ) ,
6
    'use-session' => false ,
7
    'use-modules' => true ,
8
    'use-extensions' => true
9
) );
10
 
11
$script->startup();
12
 
13
$options = $script->getOptions( "", "[provider]", array() );
14
 
15
$script->initialize();
16
 
17
$provider = $options['arguments'][1];
18
 
19
if ( ! $provider )
20
{
21
    echo "Please enter a keyword ('update' or 'delete')!\n";
22
}
23
else
24
{
25
    if ( $provider == "update" )
26
 
27
    {
28
        $handler = new xrowSOLRHandler();
29
        $manager = new ezcSearchEmbeddedManager();
30
        $session = new ezcSearchSession( $handler, $manager );
31
 
32
        $session->beginTransaction();
33
 
34
        $handler->deleteByurl( "*:*" );
35
 
36
        $session->commit();
37
 
38
        sleep( 3 );
39
 
40
        global $cli, $isQuiet;
41
 
42
        $plugins = xrowExternalSearchProvider::getExternalProviders();
43
 
44
        $cli = $GLOBALS['cli'];
45
 
46
        foreach ( $plugins as $plug )
47
        {
48
 
49
            if ( ! $plug instanceof ExternalSearchXMLPlugin )
50
            {
51
                throw new Exception( "Provider Plugin not found." );
52
            }
53
 
54
            $records = $plug->load();
55
            // setup
56
            $handler = new xrowSOLRHandler();
57
            $manager = new ezcSearchEmbeddedManager();
58
            $session = new ezcSearchSession( $handler, $manager );
59
 
60
            $session->beginTransaction();
61
 
62
            if ( ! $isQuiet )
63
            {
64
                $amount = count( $records );
65
                $cli->output( "Adding $amount items to the index." );
66
                $output = new ezcConsoleOutput();
67
                $bar = new ezcConsoleProgressbar( $output, $amount );
68
            }
69
            foreach ( $records as $key => $elem )
70
            {
71
                if ( ( $key % 499 ) === 0 and $key !== 0 )
72
                {
73
 
74
                    $session->commit();
75
 
76
                    sleep( 3 );
77
 
78
                    $session->beginTransaction();
79
 
80
                }
81
                $session->index( $elem );
82
                if ( isset( $bar ) )
83
                {
84
                    $bar->advance();
85
                }
86
            }
87
            if ( ! $isQuiet )
88
            {
89
                $bar->finish();
90
                $cli->output( "\n" );
91
            }
92
 
93
            $session->commit();
94
 
95
            sleep( 3 );
96
 
97
        }
98
    }
99
    elseif ( $provider == "delete" )
100
    {
101
 
102
        $cli = eZCLI::instance();
103
        $script = eZScript::instance( array(
104
            'description' => ( "eZ Publish Script Executor\n\n" . "Allows execution of simple PHP scripts which uses eZ Publish functionality,\n" . "when the script is called all necessary initialization is done\n" . "\n" . "ezexec.php myscript.php" ) ,
105
            'use-session' => false ,
106
            'use-modules' => true ,
107
            'use-extensions' => true
108
        ) );
109
 
110
        $script->startup();
111
 
112
        $options = $script->getOptions( "", "[provider]", array() );
113
 
114
        $script->initialize();
115
 
116
        $provider = $options['arguments'][2];
117
 
118
        if ( ! $provider )
119
        {
120
            echo "Please give the name you want to delete !\n";
121
        }
122
        else
123
        {
124
            $searchini = eZINI::instance( 'xrowsearch.ini' );
125
 
126
            $filename = $searchini->variable( $provider, 'Namespace' );
127
            echo $filename;
128
            // setup
129
 
130
            $handler = new xrowSOLRHandler();
131
            $manager = new ezcSearchEmbeddedManager();
132
            $session = new ezcSearchSession( $handler, $manager );
133
 
134
            $session->beginTransaction();
135
 
136
            $handler->deleteByurl( "meta_installation_id_ms:xrowsearch-" . "$filename" );
137
 
138
            $session->commit();
139
 
140
            echo "XML data has benn deleted !";
141
 
142
            $script->shutdown();
143
        }
144
 
145
    }
146
    else
147
    {
148
        echo "Please enter a keyword ('upload' or 'delete')!\n";
149
    }
150
}