Mercurial > hg > rr-repo
comparison sites/all/modules/sparql/sparql_endpoint/sparql_endpoint.module @ 4:ce11bbd8f642
added modules
author | danieleb <danielebarchiesi@me.com> |
---|---|
date | Thu, 19 Sep 2013 10:38:44 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:b28be78d8160 | 4:ce11bbd8f642 |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * Implements hook_menu(). | |
5 */ | |
6 function sparql_endpoint_menu() { | |
7 // @todo use access RDF data permission instead of access content. | |
8 $items['sparql'] = array( | |
9 'title' => 'SPARQL endpoint', | |
10 'page callback' => 'sparql_endpoint_sparql_endpoint', | |
11 'access arguments' => array('access content'), | |
12 ); | |
13 $items['sparql_endpoint_index'] = array( | |
14 'title' => 'Build RDF index', | |
15 'page callback' => 'sparql_endpoint_index_rdf', | |
16 'access arguments' => array('administer rdf'), | |
17 ); | |
18 return $items; | |
19 } | |
20 | |
21 function sparql_endpoint_index_rdf() { | |
22 // Instantiate the ARC2 local store. | |
23 $store = sparql_get_store('site_endpoint'); | |
24 | |
25 // Emtpy the local store. | |
26 // FIXME optimize by doing this only when creating/saving a node. | |
27 $store->reset(); | |
28 | |
29 // Index all the nodes which are published. | |
30 $query = db_select('node', 'n')->extend('PagerDefault')->extend('TableSort'); | |
31 $query->condition('n.status', 1); | |
32 $ids = $query | |
33 ->fields('n',array('nid')) | |
34 ->limit(500) | |
35 ->execute() | |
36 ->fetchCol(); | |
37 | |
38 foreach ($ids as $id) { | |
39 $rdf = rdfx_get_rdf_model('node', $id); | |
40 $store->insert($rdf->index, $rdf->uri); | |
41 } | |
42 | |
43 // Index all the users. | |
44 $query = db_select('users', 'u')->extend('PagerDefault')->extend('TableSort'); | |
45 $query->condition('u.uid', 0, '<>'); | |
46 $ids = $query | |
47 ->fields('u', array('uid')) | |
48 ->limit(500) | |
49 ->execute() | |
50 ->fetchCol(); | |
51 | |
52 foreach ($ids as $id) { | |
53 $rdf = rdfx_get_rdf_model('user', $id); | |
54 $store->insert($rdf->index, $rdf->uri); | |
55 } | |
56 | |
57 // Index all the terms. | |
58 $query = db_select('taxonomy_term_data', 't')->extend('PagerDefault')->extend('TableSort'); | |
59 $ids = $query | |
60 ->fields('t', array('tid')) | |
61 ->limit(500) | |
62 ->execute() | |
63 ->fetchCol(); | |
64 | |
65 foreach ($ids as $id) { | |
66 $rdf = rdfx_get_rdf_model('taxonomy_term', $id); | |
67 $store->insert($rdf->index, $rdf->uri); | |
68 } | |
69 | |
70 return t('The RDF index of the site has been rebuilt. Browse to the <a href="@endpoint">SPARQL endpoint</a> to query it.', array('@endpoint' => url('sparql'))); | |
71 } | |
72 | |
73 function sparql_endpoint_sparql_endpoint() { | |
74 // Instantiate the ARC2 SPARQL endpoint. | |
75 $ep = sparql_get_store('site_endpoint', SPARQL_ENDPOINT); | |
76 $ep->go(); | |
77 } | |
78 | |
79 /** | |
80 * Implements hook_node_insert(). | |
81 */ | |
82 function sparql_endpoint_node_insert($node) { | |
83 // Instantiate the ARC2 local store. | |
84 $store = sparql_get_store('site_endpoint'); | |
85 | |
86 // Attach RDF mappings and build RDF model for the node. | |
87 $node = node_load($node->nid); | |
88 $rdf = rdfx_get_rdf_model('node', $node); | |
89 | |
90 // Add node to the store. | |
91 $store->insert($rdf->index, $rdf->uri); | |
92 } | |
93 | |
94 /** | |
95 * Implements hook_node_update(). | |
96 */ | |
97 function sparql_endpoint_node_update($node) { | |
98 // Instantiate the ARC2 local store. | |
99 $store = sparql_get_store('site_endpoint'); | |
100 | |
101 // Build RDF model for the node. | |
102 $rdf = rdfx_get_rdf_model('node', $node); | |
103 | |
104 // Cleans out the graph and reindex the node. | |
105 $store->query('DELETE FROM <' . $rdf->uri . '>'); | |
106 $store->insert($rdf->index, $rdf->uri); | |
107 } |