View source
<?php
function spaces_install() {
drupal_install_schema('spaces');
}
function spaces_uninstall() {
drupal_uninstall_schema('spaces');
}
function spaces_enable() {
db_query("UPDATE {system} SET weight = -1 WHERE name = 'spaces' AND type = 'module'");
}
function spaces_schema() {
$schema = array();
$schema['spaces_overrides'] = array(
'description' => t('Object overrides per space.'),
'fields' => array(
'type' => array(
'description' => t('The space type.'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
),
'id' => array(
'description' => t('The space id.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'object_type' => array(
'description' => t('The override object type.'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
),
'object_id' => array(
'description' => t('The override object id.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'value' => array(
'description' => t('Serialized storage of space-specific override values.'),
'type' => 'text',
'serialize' => TRUE,
),
),
'indexes' => array(
'space' => array(
'type',
'id',
),
'object' => array(
'object_type',
'object_id',
),
),
);
$schema['spaces_presets'] = array(
'description' => t('Spaces presets.'),
'export' => array(
'key' => 'name',
'identifier' => 'spaces_presets',
'default hook' => 'spaces_presets',
'status' => 'spaces_preset_status',
'api' => array(
'owner' => 'spaces',
'api' => 'spaces',
'minimum_version' => 3,
'current_version' => 3,
),
'export callback' => 'spaces_preset_export',
),
'fields' => array(
'name' => array(
'description' => t('The preset string identifier.'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
),
'title' => array(
'description' => t('The human-readable name for this preset.'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
),
'description' => array(
'description' => t('The description for this preset.'),
'type' => 'text',
),
'space_type' => array(
'description' => t('The space type for which this preset applies.'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
),
'value' => array(
'description' => t('A serialized array that represents this preset\'s definition.'),
'type' => 'text',
'serialize' => TRUE,
),
),
'primary key' => array(
'name',
),
'indexes' => array(
'type' => array(
'space_type',
),
),
);
return $schema;
}
function spaces_update_6001() {
$ret = array();
db_query("UPDATE {system} SET weight = -1 WHERE name = 'spaces' AND type ='module'");
$schema = spaces_schema();
db_add_field($ret, 'spaces_features', 'weight', $schema['spaces_features']['fields']['weight']);
return $ret;
}
function spaces_update_6002() {
$modules = array(
'purl',
'features',
);
foreach ($modules as $module) {
if (!module_exists($module)) {
drupal_install_modules(array(
$module,
));
}
}
return array();
}
function spaces_update_6003() {
$ret = array();
$ret[] = update_sql("ALTER TABLE spaces MODIFY sid int(10) NOT NULL");
$ret[] = update_sql("ALTER TABLE spaces_settings MODIFY sid int(10) NOT NULL");
$ret[] = update_sql("ALTER TABLE spaces_features MODIFY sid int(10) NOT NULL");
return $ret;
}
function spaces_update_6301() {
$schema = array();
$schema['spaces_overrides'] = array(
'description' => t('Object overrides per space.'),
'fields' => array(
'type' => array(
'description' => t('The space type.'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
),
'id' => array(
'description' => t('The space id.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'object_type' => array(
'description' => t('The override object type.'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
),
'object_id' => array(
'description' => t('The override object id.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'value' => array(
'description' => t('Serialized storage of space-specific override values.'),
'type' => 'text',
'serialize' => TRUE,
),
),
'indexes' => array(
'space' => array(
'type',
'id',
),
'object' => array(
'object_type',
'object_id',
),
),
);
$schema['spaces_presets'] = array(
'description' => t('Spaces presets.'),
'export' => array(
'key' => 'name',
'identifier' => 'spaces_presets',
'default hook' => 'spaces_presets',
'status' => 'spaces_preset_status',
'api' => array(
'owner' => 'spaces',
'api' => 'spaces',
'minimum_version' => 3,
'current_version' => 3,
),
),
'fields' => array(
'name' => array(
'description' => t('The preset string identifier.'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
),
'title' => array(
'description' => t('The human-readable name for this preset.'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
),
'description' => array(
'description' => t('The description for this preset.'),
'type' => 'text',
),
'space_type' => array(
'description' => t('The space type for which this preset applies.'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
),
'value' => array(
'description' => t('A serialized array that represents this preset\'s definition.'),
'type' => 'text',
'serialize' => TRUE,
),
),
'primary key' => array(
'name',
),
'indexes' => array(
'type' => array(
'space_type',
),
),
);
drupal_install_modules(array(
'ctools',
));
$spaces = array();
$result = db_query('SELECT * FROM {spaces}');
while ($row = db_fetch_object($result)) {
$spaces[$row->type][$row->sid] = $row;
}
$features = array();
$result = db_query('SELECT * FROM {spaces_features}');
while ($row = db_fetch_object($result)) {
$features[$row->type][$row->sid][$row->id] = $row;
}
$settings = array();
$result = db_query('SELECT * FROM {spaces_settings}');
while ($row = db_fetch_object($result)) {
$settings[] = $row;
}
$ret = array();
db_drop_table($ret, 'spaces');
db_drop_table($ret, 'spaces_features');
db_drop_table($ret, 'spaces_presets');
db_create_table($ret, 'spaces_presets', $schema['spaces_presets']);
db_create_table($ret, 'spaces_overrides', $schema['spaces_overrides']);
$known_presets = array(
'og' => array(
'controlled' => 'og_controlled',
'private' => 'og_private',
'public' => 'og_public',
),
);
foreach ($spaces as $type => $type_spaces) {
foreach ($type_spaces as $sid => $space) {
$preset = isset($known_presets[$type][$space->preset]) ? $known_presets[$type][$space->preset] : $space->preset;
db_query("INSERT INTO {spaces_overrides}(type, id, object_type, object_id, value) VALUES('%s', '%s', 'variable', '%s', '%s')", $type, $sid, "spaces_preset_{$type}", serialize($preset));
}
}
foreach ($features as $type => $type_features) {
foreach ($type_features as $sid => $sid_features) {
$weights = array();
foreach ($sid_features as $id => $feature) {
$value = array(
$id => empty($feature->value) ? '0' : '1',
);
if ($override = db_fetch_array(db_query("SELECT * FROM {spaces_overrides} WHERE type = '%s' AND id = '%s' AND object_type = 'variable' AND object_id = 'spaces_features'", $type, $sid))) {
$value += unserialize($override['value']);
db_query("UPDATE {spaces_overrides} SET value ='%s' WHERE type = '%s' AND id = '%s' AND object_type = 'variable' AND object_id = 'spaces_features'", serialize($value), $type, $sid);
}
else {
db_query("INSERT INTO {spaces_overrides}(type, id, object_type, object_id, value) VALUES('%s', '%s', 'variable', 'spaces_features', '%s')", $type, $sid, serialize($value));
}
$weights[$id] = $feature->weight;
}
if (!empty($weights)) {
db_query("INSERT INTO {spaces_overrides}(type, id, object_type, object_id, value) VALUES('%s', '%s', 'variable', 'space_menu_items', '%s')", $type, $sid, serialize($weights));
}
}
}
foreach ($settings as $setting) {
if ($setting->id === 'home') {
db_query("INSERT INTO {spaces_overrides} (type, id, object_type, object_id, value) VALUES ('%s', '%s', 'variable', 'site_frontpage', '%s')", $setting->type, $setting->sid, $setting->value);
}
}
return $ret;
}
function spaces_update_6302() {
$presets = array();
foreach (module_invoke_all('spaces_presets') as $name => $preset) {
$preset = (object) $preset;
if (!isset($preset->api_version)) {
$presets[$name] = $preset;
}
}
spaces_migrate_api_3_presets($presets);
return array();
}
function spaces_migrate_api_3_presets($presets) {
foreach ($presets as $name => $preset) {
if (!db_result(db_query("SELECT name FROM {spaces_presets} WHERE name = '%s'", $name))) {
$new = array(
'name' => $name,
'title' => isset($preset->name) ? $preset->name : $name,
'description' => isset($preset->description) ? $preset->description : '',
'space_type' => $preset->type,
'value' => array(),
);
if (!empty($preset->preset['features'])) {
$new['value']['variable']['spaces_features'] = $preset->preset['features'];
}
if (!empty($preset->preset['settings'])) {
foreach ($preset->preset['settings'] as $key => $value) {
$new['value']['variable']["spaces_setting_{$key}"] = $value;
}
}
if (!empty($preset->preset['og'])) {
foreach ($preset->preset['og'] as $key => $value) {
$new['value']['variable']["spaces_{$key}"] = $value;
}
}
$new['value'] = serialize($new['value']);
db_query("INSERT INTO {spaces_presets} (name,title,description,space_type,value) VALUES ('%s', '%s', '%s', '%s', '%s')", $new['name'], $new['title'], $new['description'], $new['space_type'], $new['value']);
drupal_set_message('Updated spaces preset: ' . $new['name']);
}
}
}