| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
/**
|
| 4 |
* sparql.install - SPARQL API installation/uninstallation.
|
| 5 |
*
|
| 6 |
* @author Arto Bendiken <http://bendiken.net/>
|
| 7 |
* @copyright Copyright (c) 2007-2008 Arto Bendiken. All rights reserved.
|
| 8 |
* @license GPL <http://creativecommons.org/licenses/GPL/2.0/>
|
| 9 |
* @package sparql.module
|
| 10 |
*/
|
| 11 |
|
| 12 |
//////////////////////////////////////////////////////////////////////////////
|
| 13 |
// Core API hooks
|
| 14 |
|
| 15 |
/**
|
| 16 |
* Implementation of hook_enable().
|
| 17 |
*/
|
| 18 |
function sparql_enable() {
|
| 19 |
drupal_set_message(t('SPARQL API successfully installed. Please review the available <a href="@settings">configuration settings</a>.', array('@settings' => url('admin/settings/sparql'))));
|
| 20 |
}
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Implementation of hook_install().
|
| 24 |
*/
|
| 25 |
function sparql_install() {
|
| 26 |
drupal_install_schema('sparql');
|
| 27 |
}
|
| 28 |
|
| 29 |
/**
|
| 30 |
* Implementation of hook_uninstall().
|
| 31 |
*/
|
| 32 |
function sparql_uninstall() {
|
| 33 |
drupal_uninstall_schema('sparql');
|
| 34 |
|
| 35 |
db_query("DELETE FROM {variable} WHERE name LIKE 'sparql_%'");
|
| 36 |
cache_clear_all('variables', 'cache');
|
| 37 |
}
|
| 38 |
|
| 39 |
/**
|
| 40 |
* Implementation of hook_requirements().
|
| 41 |
*/
|
| 42 |
function sparql_requirements($phase) {
|
| 43 |
$requirements = array();
|
| 44 |
$t = get_t(); // Ensure translations don't break at install time
|
| 45 |
|
| 46 |
if ($phase == 'install') {
|
| 47 |
if (!class_exists('ARC2')) {
|
| 48 |
$requirements['arc2'] = array(
|
| 49 |
'title' => '',
|
| 50 |
'value' => '',
|
| 51 |
'description' => $t('The ARC2 library is not installed. See the <a href="@status-report">status report</a> for information on how to install this library.', array('@status-report' => url('admin/reports/status'))),
|
| 52 |
'severity' => REQUIREMENT_ERROR,
|
| 53 |
);
|
| 54 |
}
|
| 55 |
}
|
| 56 |
|
| 57 |
return $requirements;
|
| 58 |
}
|
| 59 |
|
| 60 |
//////////////////////////////////////////////////////////////////////////////
|
| 61 |
// Schema API hooks
|
| 62 |
|
| 63 |
/**
|
| 64 |
* Implementation of hook_schema().
|
| 65 |
*/
|
| 66 |
function sparql_schema() {
|
| 67 |
return array(
|
| 68 |
'sparql_nodes' => array(
|
| 69 |
'description' => t('Stores SPARQL node data.'),
|
| 70 |
'fields' => array(
|
| 71 |
'nid' => array(
|
| 72 |
'description' => t("The node's ID from {node}.nid."),
|
| 73 |
'type' => 'int',
|
| 74 |
'unsigned' => TRUE,
|
| 75 |
'not null' => TRUE,
|
| 76 |
'default' => 0,
|
| 77 |
),
|
| 78 |
'vid' => array(
|
| 79 |
'description' => t("The node's version ID from {node}.vid."),
|
| 80 |
'type' => 'int',
|
| 81 |
'unsigned' => TRUE,
|
| 82 |
'not null' => TRUE,
|
| 83 |
'default' => 0,
|
| 84 |
),
|
| 85 |
'endpoint' => array(
|
| 86 |
'description' => t("The SPARQL endpoint's URL."),
|
| 87 |
'type' => 'text',
|
| 88 |
),
|
| 89 |
'query' => array(
|
| 90 |
'description' => t("The SPARQL query."),
|
| 91 |
'type' => 'text',
|
| 92 |
'size' => 'big',
|
| 93 |
),
|
| 94 |
),
|
| 95 |
'primary key' => array('nid', 'vid'),
|
| 96 |
),
|
| 97 |
);
|
| 98 |
}
|
| 99 |
|
| 100 |
//////////////////////////////////////////////////////////////////////////////
|
| 101 |
// Schema API updates
|
| 102 |
|
| 103 |
/**
|
| 104 |
* Installs the database schema; this is necessary when upgrading from any
|
| 105 |
* version prior to 6.x-1.0-alpha2.
|
| 106 |
*
|
| 107 |
* @see http://drupal.org/node/150215
|
| 108 |
* @see http://drupal.org/node/150220
|
| 109 |
*/
|
| 110 |
function sparql_update_6000() {
|
| 111 |
$updates = array();
|
| 112 |
|
| 113 |
db_create_table($updates, 'sparql_nodes', array(
|
| 114 |
'description' => t('Stores SPARQL node data.'),
|
| 115 |
'fields' => array(
|
| 116 |
'nid' => array(
|
| 117 |
'description' => t("The node's ID from {node}.nid."),
|
| 118 |
'type' => 'int',
|
| 119 |
'unsigned' => TRUE,
|
| 120 |
'not null' => TRUE,
|
| 121 |
'default' => 0,
|
| 122 |
),
|
| 123 |
'vid' => array(
|
| 124 |
'description' => t("The node's version ID from {node}.vid."),
|
| 125 |
'type' => 'int',
|
| 126 |
'unsigned' => TRUE,
|
| 127 |
'not null' => TRUE,
|
| 128 |
'default' => 0,
|
| 129 |
),
|
| 130 |
'endpoint' => array(
|
| 131 |
'description' => t("The SPARQL endpoint's URL."),
|
| 132 |
'type' => 'text',
|
| 133 |
),
|
| 134 |
'query' => array(
|
| 135 |
'description' => t("The SPARQL query."),
|
| 136 |
'type' => 'text',
|
| 137 |
'size' => 'big',
|
| 138 |
),
|
| 139 |
),
|
| 140 |
'primary key' => array('nid', 'vid'),
|
| 141 |
));
|
| 142 |
|
| 143 |
return $updates;
|
| 144 |
}
|
| 145 |
|
| 146 |
/**
|
| 147 |
* Converts SPARQL node data from early 6.x-dev format to 6.x-1.0-alpha2.
|
| 148 |
*/
|
| 149 |
function sparql_update_6001() {
|
| 150 |
$updates = array();
|
| 151 |
|
| 152 |
$result = db_query("SELECT nid, vid FROM {node} WHERE type = 'sparql' ORDER BY nid ASC");
|
| 153 |
while ($node = db_fetch_object($result)) {
|
| 154 |
$query = variable_get('sparql_node_' . $node->nid . '_query', '');
|
| 155 |
$endpoint = variable_get('sparql_node_' . $node->nid . '_endpoint', '');
|
| 156 |
|
| 157 |
if (db_query("INSERT INTO {sparql_nodes} (nid, vid, endpoint, query) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->vid, $endpoint, $query)) {
|
| 158 |
variable_del('sparql_node_' . $node->nid . '_query');
|
| 159 |
variable_del('sparql_node_' . $node->nid . '_endpoint');
|
| 160 |
}
|
| 161 |
}
|
| 162 |
|
| 163 |
return $updates;
|
| 164 |
}
|