Subversion Repositories xrowsearch

[/] [trunk/] [classes/] [abstracts/] [xrowExternalSearchPlugin.php] - Blame information for rev 1

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1 rrobert
<?php
2
 
3
abstract class ExternalSearchXMLPlugin
4
{
5
 
6
    function __construct( $params )
7
    {
8
        if ( $params )
9
        {
10
            $this->params = $params;
11
        }
12
        if ( $this->params['Namespace'] )
13
        {
14
            $this->namespace = 'xrowsearch-'. $this->params['Namespace'];
15
        }
16
    }
17
    /*
18
     * @return Records Returns Object Records
19
     */
20
 
21
    abstract protected function structureXml( SimpleXMLElement $xml);
22
 
23
    private $xml;
24
    private $params;
25
    public $namespace;
26
 
27
    public function load()
28
    {
29
        $file_in = file_get_contents( $this->params['ExternalURL'] );
30
        if ( $file_in === false && function_exists( 'curl_init' ) )
31
        {
32
            $ch = curl_init();
33
            $timeout = 5;
34
            curl_setopt( $ch, CURLOPT_URL, $this->params['ExternalURL'] );
35
            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
36
            curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
37
            $file_in = curl_exec( $ch );
38
            curl_close( $ch );
39
        }
40
 
41
        $xml = simplexml_load_string( $file_in );
42
 
43
        if ( $xml === false )
44
        {
45
            throw new Exception( "Failed to read XML file!" );
46
        }
47
        return $this->structureXML( $xml );
48
    }
49
 
50
    public function delete(  )
51
    {
52
        $handler = new xrowSOLRHandler();
53
        $manager = new ezcSearchEmbeddedManager();
54
        $session = new ezcSearchSession( $handler, $manager );
55
 
56
        $session->beginTransaction();
57
 
58
        $handler->deleteByurl( "meta_installation_id_ms:xrowsearch-" . $this->params['Namespace']);
59
 
60
        $session->commit();
61
 
62
        sleep( 3 );
63
    }
64
}