| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
//////////////////////////////////////////////////////////////////////////////
|
| 5 |
// Core API hooks
|
| 6 |
|
| 7 |
/**
|
| 8 |
* Implementation of hook_enable().
|
| 9 |
*/
|
| 10 |
function rdf_enable() {
|
| 11 |
drupal_set_message(t('RDF API successfully installed. Please review the available <a href="@settings">configuration settings</a>.', array('@settings' => url('admin/settings/rdf'))));
|
| 12 |
}
|
| 13 |
|
| 14 |
/**
|
| 15 |
* Implementation of hook_install().
|
| 16 |
*/
|
| 17 |
function rdf_install() {
|
| 18 |
db_query("UPDATE {system} SET weight = -10 WHERE name = 'rdf' AND type = 'module'");
|
| 19 |
|
| 20 |
drupal_install_schema('rdf');
|
| 21 |
db_query("INSERT INTO {rdf_repositories} VALUES ('%s', 'rdf', 'local', 1, 1, 0, '%s')", 'local', serialize(array('title' => t('Local'), 'description' => '')));
|
| 22 |
}
|
| 23 |
|
| 24 |
/**
|
| 25 |
* Implementation of hook_uninstall().
|
| 26 |
*/
|
| 27 |
function rdf_uninstall() {
|
| 28 |
db_query("DELETE FROM {rdf_repositories} WHERE name = '%s'", 'local');
|
| 29 |
drupal_uninstall_schema('rdf');
|
| 30 |
}
|
| 31 |
|
| 32 |
/**
|
| 33 |
* Implementation of hook_requirements().
|
| 34 |
*/
|
| 35 |
function rdf_requirements($phase) {
|
| 36 |
$status = array();
|
| 37 |
$t = get_t(); // Ensure translations don't break at install time
|
| 38 |
|
| 39 |
if ($phase == 'runtime') {
|
| 40 |
$arc2 = class_exists('ARC2');
|
| 41 |
$status['rdf'] = array(
|
| 42 |
'title' => $t('RDF library'),
|
| 43 |
'value' => $arc2 ? $t('ARC2 @version', array('@version' => ARC2::getVersion())) : $t('Not installed'),
|
| 44 |
'description' => $arc2 ? '' : $t('<a href="@arc2">ARC2</a> is not available. It is recommended that you install this library in order to enable support for more RDF formats and for SPARQL queries. To install, <a href="@download">download</a> the latest version of the library and unzip it to %path under the Drupal directory. For more information please refer to the <a href="@handbook">handbook</a>.', array('@arc2' => 'http://arc.semsol.org/', '@download' => 'http://arc.semsol.org/download', '%path' => RDF_ARC2_PATH . '/', '@handbook' => 'http://drupal.org/node/219852')),
|
| 45 |
'severity' => $arc2 ? REQUIREMENT_OK : REQUIREMENT_WARNING,
|
| 46 |
);
|
| 47 |
}
|
| 48 |
|
| 49 |
return $status;
|
| 50 |
}
|
| 51 |
|
| 52 |
//////////////////////////////////////////////////////////////////////////////
|
| 53 |
// Schema API hooks
|
| 54 |
|
| 55 |
/**
|
| 56 |
* Implementation of hook_schema().
|
| 57 |
*/
|
| 58 |
function rdf_schema() {
|
| 59 |
return array(
|
| 60 |
// RDF repositories
|
| 61 |
'rdf_repositories' => array( // added in 6.x-1.0-alpha7
|
| 62 |
'description' => t("RDF repositories"),
|
| 63 |
'fields' => array(
|
| 64 |
'name' => array(
|
| 65 |
'description' => t("Repository name."),
|
| 66 |
'type' => 'varchar',
|
| 67 |
'length' => 64,
|
| 68 |
'not null' => TRUE,
|
| 69 |
),
|
| 70 |
'module' => array(
|
| 71 |
'description' => t("Repository owner module."),
|
| 72 |
'type' => 'varchar',
|
| 73 |
'length' => 255,
|
| 74 |
'not null' => TRUE,
|
| 75 |
),
|
| 76 |
'type' => array(
|
| 77 |
'description' => t("Repository type ('system', 'local', or 'remote')."),
|
| 78 |
'type' => 'varchar',
|
| 79 |
'length' => 16,
|
| 80 |
'not null' => TRUE,
|
| 81 |
),
|
| 82 |
'enabled' => array(
|
| 83 |
'description' => t("Repository enabled? ('0' or '1')."),
|
| 84 |
'type' => 'int',
|
| 85 |
'size' => 'tiny',
|
| 86 |
'not null' => TRUE,
|
| 87 |
'default' => 0,
|
| 88 |
),
|
| 89 |
'mutable' => array(
|
| 90 |
'description' => t("Repository mutable? ('0' or '1')."),
|
| 91 |
'type' => 'int',
|
| 92 |
'size' => 'tiny',
|
| 93 |
'not null' => TRUE,
|
| 94 |
'default' => 0,
|
| 95 |
),
|
| 96 |
'weight' => array(
|
| 97 |
'description' => t("Repository weight."),
|
| 98 |
'type' => 'int',
|
| 99 |
'size' => 'small',
|
| 100 |
'not null' => TRUE,
|
| 101 |
'default' => 0,
|
| 102 |
),
|
| 103 |
'options' => array(
|
| 104 |
'description' => t("Repository options (serialized PHP)."),
|
| 105 |
'type' => 'text',
|
| 106 |
'size' => 'big',
|
| 107 |
),
|
| 108 |
),
|
| 109 |
'primary key' => array('name'),
|
| 110 |
),
|
| 111 |
|
| 112 |
// RDF namespaces
|
| 113 |
'rdf_namespaces' => array(
|
| 114 |
'description' => t("RDF namespaces"),
|
| 115 |
'fields' => array(
|
| 116 |
'prefix' => array(
|
| 117 |
'description' => t("Namespace prefix."),
|
| 118 |
'type' => 'varchar',
|
| 119 |
'length' => 64,
|
| 120 |
'not null' => TRUE,
|
| 121 |
),
|
| 122 |
'uri' => array(
|
| 123 |
'description' => t("Namespace URI."),
|
| 124 |
'type' => 'varchar',
|
| 125 |
'length' => 255,
|
| 126 |
'not null' => TRUE,
|
| 127 |
'default' => '',
|
| 128 |
),
|
| 129 |
),
|
| 130 |
'primary key' => array('prefix'),
|
| 131 |
'indexes' => array('uri' => array('uri')),
|
| 132 |
),
|
| 133 |
|
| 134 |
// RDF resources (URIs)
|
| 135 |
'rdf_resources' => array(
|
| 136 |
'description' => t("RDF resources"),
|
| 137 |
'fields' => array(
|
| 138 |
'rid' => array(
|
| 139 |
'description' => t("Resource ID."),
|
| 140 |
'type' => 'serial',
|
| 141 |
'unsigned' => TRUE,
|
| 142 |
'not null' => TRUE,
|
| 143 |
),
|
| 144 |
'uri' => array(
|
| 145 |
'description' => t("Resource URI."),
|
| 146 |
'type' => 'varchar',
|
| 147 |
'length' => 255,
|
| 148 |
'not null' => TRUE,
|
| 149 |
'default' => '',
|
| 150 |
),
|
| 151 |
),
|
| 152 |
'primary key' => array('rid'),
|
| 153 |
'unique keys' => array('uri' => array('uri')),
|
| 154 |
),
|
| 155 |
|
| 156 |
// RDF statements
|
| 157 |
'rdf_data' => array(
|
| 158 |
'description' => t("RDF statements"),
|
| 159 |
'fields' => array(
|
| 160 |
'did' => array(
|
| 161 |
'description' => t("The datum, or reified statement, identifier for this statement."),
|
| 162 |
'type' => 'serial',
|
| 163 |
'unsigned' => TRUE,
|
| 164 |
'not null' => TRUE,
|
| 165 |
),
|
| 166 |
'uid' => array( // added in 6.x-1.0-alpha4
|
| 167 |
'description' => t("The user ID from {users}.uid."),
|
| 168 |
'type' => 'int',
|
| 169 |
'unsigned' => TRUE,
|
| 170 |
),
|
| 171 |
'created' => array( // added in 6.x-1.0-alpha4
|
| 172 |
'description' => t("The Unix timestamp when the statement was created."),
|
| 173 |
'type' => 'int',
|
| 174 |
'unsigned' => TRUE,
|
| 175 |
),
|
| 176 |
'gid' => array(
|
| 177 |
'description' => t("The graph/context URI from {rdf_resources}.rid."),
|
| 178 |
'type' => 'int',
|
| 179 |
'unsigned' => TRUE,
|
| 180 |
),
|
| 181 |
'sid' => array(
|
| 182 |
'description' => t("The subject URI from {rdf_resources}.rid."),
|
| 183 |
'type' => 'int',
|
| 184 |
'unsigned' => TRUE,
|
| 185 |
'not null' => TRUE,
|
| 186 |
'default' => 0,
|
| 187 |
),
|
| 188 |
'pid' => array(
|
| 189 |
'description' => t("The predicate URI from {rdf_resources}.rid."),
|
| 190 |
'type' => 'int',
|
| 191 |
'unsigned' => TRUE,
|
| 192 |
'not null' => TRUE,
|
| 193 |
'default' => 0,
|
| 194 |
),
|
| 195 |
'oid' => array(
|
| 196 |
'description' => t("The object URI from {rdf_resources}.rid."),
|
| 197 |
'type' => 'int',
|
| 198 |
'unsigned' => TRUE,
|
| 199 |
),
|
| 200 |
'tid' => array(
|
| 201 |
'description' => t("The object literal datatype URI from {rdf_resources}.rid."),
|
| 202 |
'type' => 'int',
|
| 203 |
'unsigned' => TRUE,
|
| 204 |
),
|
| 205 |
'lang' => array(
|
| 206 |
'description' => t("The object literal language."),
|
| 207 |
'type' => 'varchar',
|
| 208 |
'length' => 12,
|
| 209 |
),
|
| 210 |
'data' => array(
|
| 211 |
'description' => t("The object literal data."),
|
| 212 |
'type' => 'text',
|
| 213 |
'size' => 'big',
|
| 214 |
),
|
| 215 |
),
|
| 216 |
'primary key' => array('did'),
|
| 217 |
'indexes' => array(
|
| 218 |
'gspo' => array('gid', 'sid', 'pid', 'oid'),
|
| 219 |
'gpos' => array('gid', 'pid', 'oid', 'sid'),
|
| 220 |
'gosp' => array('gid', 'oid', 'sid', 'pid'),
|
| 221 |
),
|
| 222 |
),
|
| 223 |
);
|
| 224 |
}
|
| 225 |
|
| 226 |
/**
|
| 227 |
* Implementation of hook_schema_alter().
|
| 228 |
*/
|
| 229 |
function rdf_schema_alter($schema) {
|
| 230 |
// This is not executed on installation/uninstallation, but only when the
|
| 231 |
// schema is loaded at runtime; it's needed in order for RDF repositories
|
| 232 |
// created by third-party modules to have a schema without them having to
|
| 233 |
// duplicate the definition of the {rdf_data} table, above.
|
| 234 |
if (function_exists('rdf_get_tables')) {
|
| 235 |
foreach (rdf_get_tables() as $table) {
|
| 236 |
if ($table != RDF_DB_TABLE_DEFAULT) {
|
| 237 |
$schema[$table] = $schema[RDF_DB_TABLE_DEFAULT];
|
| 238 |
}
|
| 239 |
}
|
| 240 |
}
|
| 241 |
}
|
| 242 |
|
| 243 |
//////////////////////////////////////////////////////////////////////////////
|
| 244 |
// Schema API updates
|
| 245 |
|
| 246 |
/**
|
| 247 |
* Converts RDF DB tables from 6.x-1.0-alpha3 to 6.x-1.0-alpha4.
|
| 248 |
*
|
| 249 |
* @since 6.x-1.0-alpha4
|
| 250 |
*/
|
| 251 |
function rdf_update_6000() {
|
| 252 |
$updates = array();
|
| 253 |
|
| 254 |
module_load_include('inc', 'rdf', 'rdf.db');
|
| 255 |
foreach (rdf_get_tables() as $table) {
|
| 256 |
db_add_field($updates, $table, 'uid', array('type' => 'int', 'unsigned' => TRUE));
|
| 257 |
db_add_field($updates, $table, 'created', array('type' => 'int', 'unsigned' => TRUE));
|
| 258 |
}
|
| 259 |
|
| 260 |
return $updates;
|
| 261 |
}
|
| 262 |
|
| 263 |
/**
|
| 264 |
* Converts CCK Date field mapping variables into a new format that provides
|
| 265 |
* support for fields that have both a start and an end date.
|
| 266 |
*
|
| 267 |
* @since 6.x-1.0-alpha6
|
| 268 |
*/
|
| 269 |
function rdf_update_6001() {
|
| 270 |
$updates = array();
|
| 271 |
|
| 272 |
$variables = db_query("SELECT name, value FROM {variable} WHERE name LIKE 'rdf_schema_property_content_%'");
|
| 273 |
while ($variable = db_fetch_object($variables)) {
|
| 274 |
if (preg_match('/^rdf_schema_property_content_(.*)$/', $variable->name, $matches)) {
|
| 275 |
$field_name = $matches[1];
|
| 276 |
if ($db_columns = db_result(db_query("SELECT db_columns FROM {content_node_field} WHERE field_name = '%s' AND module = 'date'", $field_name))) {
|
| 277 |
// Check if this field has a secondary "to" date component enabled:
|
| 278 |
$db_columns = unserialize($db_columns);
|
| 279 |
if (isset($db_columns['value2'])) {
|
| 280 |
// Delete the old mapping variable:
|
| 281 |
$updates[] = update_sql("DELETE FROM {variable} WHERE name = '" . db_escape_string($variable->name) . "'");
|
| 282 |
|
| 283 |
// Insert the new mapping variable, provided one hasn't already been defined by the administrator:
|
| 284 |
if (variable_get('rdf_schema_property_content_' . $field_name . '[from]', FALSE) === FALSE) {
|
| 285 |
$updates[] = update_sql("INSERT INTO {variable} (name, value) VALUES ('" . db_escape_string($variable->name) . "[from]', '" . db_escape_string($variable->value) . "')");
|
| 286 |
}
|
| 287 |
}
|
| 288 |
}
|
| 289 |
}
|
| 290 |
}
|
| 291 |
|
| 292 |
return $updates;
|
| 293 |
}
|
| 294 |
|
| 295 |
/**
|
| 296 |
* Creates the {rdf_repositories} table.
|
| 297 |
*
|
| 298 |
* @since 6.x-1.0-alpha7
|
| 299 |
*/
|
| 300 |
function rdf_update_6002() {
|
| 301 |
$updates = array();
|
| 302 |
db_create_table($updates, 'rdf_repositories',
|
| 303 |
array(
|
| 304 |
'fields' => array(
|
| 305 |
'name' => array(
|
| 306 |
'type' => 'varchar',
|
| 307 |
'length' => 64,
|
| 308 |
'not null' => TRUE,
|
| 309 |
),
|
| 310 |
'module' => array(
|
| 311 |
'type' => 'varchar',
|
| 312 |
'length' => 255,
|
| 313 |
'not null' => TRUE,
|
| 314 |
),
|
| 315 |
'type' => array(
|
| 316 |
'type' => 'varchar',
|
| 317 |
'length' => 16,
|
| 318 |
'not null' => TRUE,
|
| 319 |
),
|
| 320 |
'enabled' => array(
|
| 321 |
'type' => 'int',
|
| 322 |
'size' => 'tiny',
|
| 323 |
'not null' => TRUE,
|
| 324 |
'default' => 0,
|
| 325 |
),
|
| 326 |
'mutable' => array(
|
| 327 |
'type' => 'int',
|
| 328 |
'size' => 'tiny',
|
| 329 |
'not null' => TRUE,
|
| 330 |
'default' => 0,
|
| 331 |
),
|
| 332 |
'weight' => array(
|
| 333 |
'type' => 'int',
|
| 334 |
'size' => 'small',
|
| 335 |
'not null' => TRUE,
|
| 336 |
'default' => 0,
|
| 337 |
),
|
| 338 |
'options' => array(
|
| 339 |
'type' => 'text',
|
| 340 |
'size' => 'big',
|
| 341 |
),
|
| 342 |
),
|
| 343 |
'primary key' => array('name'),
|
| 344 |
)
|
| 345 |
);
|
| 346 |
return $updates;
|
| 347 |
}
|
| 348 |
|
| 349 |
/**
|
| 350 |
* Migrates RDF repository definitions from the {variable} table to the
|
| 351 |
* {rdf_repositories} table.
|
| 352 |
*
|
| 353 |
* @since 6.x-1.0-alpha7
|
| 354 |
*/
|
| 355 |
function rdf_update_6003() {
|
| 356 |
$updates = array();
|
| 357 |
$result = db_query("SELECT name, value FROM {variable} WHERE name LIKE 'rdf_db_repository[%]' ORDER BY name");
|
| 358 |
while ($variable = db_fetch_object($result)) {
|
| 359 |
if (preg_match('/^rdf_db_repository\[([^\]]+)\]$/', $variable->name, $matches)) {
|
| 360 |
$options = unserialize($variable->value);
|
| 361 |
$options = array('title' => @$options['dc:title'], 'description' => @$options['dc:description']); // any other options will be lost
|
| 362 |
$updates[] = $update = rdf_update_sql("INSERT INTO {rdf_repositories} (name, module, type, enabled, mutable, weight, options) VALUES ('" . db_escape_string($matches[1]) . "', 'rdf', 'local', 1, 1, 0, '%s')", serialize($options));
|
| 363 |
if (!empty($update['success'])) {
|
| 364 |
$updates[] = rdf_update_sql("DELETE FROM {variable} WHERE name = '" . db_escape_string($variable->name) . "'");
|
| 365 |
}
|
| 366 |
}
|
| 367 |
}
|
| 368 |
return $updates;
|
| 369 |
}
|
| 370 |
|
| 371 |
//////////////////////////////////////////////////////////////////////////////
|
| 372 |
// Database API helpers
|
| 373 |
|
| 374 |
function rdf_update_sql($sql) {
|
| 375 |
$arguments = array_slice(func_get_args(), 1);
|
| 376 |
return array('success' => (db_query($sql, $arguments) !== FALSE), 'query' => check_plain($sql));
|
| 377 |
}
|