| 1 |
<?php
|
| 2 |
// $Id: better_formats.install,v 1.7.2.3 2009/02/25 06:44:17 dragonwize Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Installs the better_formats module.
|
| 7 |
*
|
| 8 |
* Creates a database for use of multi-layered default formats and sets
|
| 9 |
* default settings.
|
| 10 |
*/
|
| 11 |
|
| 12 |
|
| 13 |
/**
|
| 14 |
* Implementation of hook_schema().
|
| 15 |
*/
|
| 16 |
function better_formats_schema() {
|
| 17 |
$schema['better_formats_defaults'] = array(
|
| 18 |
'fields' => array(
|
| 19 |
'rid' => array(
|
| 20 |
'type' => 'int',
|
| 21 |
'size' => 'normal',
|
| 22 |
'unsigned' => TRUE,
|
| 23 |
'not null' => TRUE,
|
| 24 |
),
|
| 25 |
'type' => array(
|
| 26 |
'type' => 'varchar',
|
| 27 |
'length' => 255,
|
| 28 |
'not null' => TRUE,
|
| 29 |
),
|
| 30 |
'format' => array(
|
| 31 |
'type' => 'int',
|
| 32 |
'size' => 'medium',
|
| 33 |
'unsigned' => TRUE,
|
| 34 |
'not null' => TRUE,
|
| 35 |
),
|
| 36 |
'type_weight' => array(
|
| 37 |
'type' => 'int',
|
| 38 |
'size' => 'tiny',
|
| 39 |
'default' => 0,
|
| 40 |
'unsigned' => TRUE,
|
| 41 |
'not null' => TRUE,
|
| 42 |
),
|
| 43 |
'weight' => array(
|
| 44 |
'type' => 'int',
|
| 45 |
'size' => 'tiny',
|
| 46 |
'default' => 0,
|
| 47 |
'unsigned' => FALSE,
|
| 48 |
'not null' => TRUE,
|
| 49 |
),
|
| 50 |
),
|
| 51 |
'primary key' => array('rid', 'type'),
|
| 52 |
);
|
| 53 |
|
| 54 |
return $schema;
|
| 55 |
}
|
| 56 |
|
| 57 |
/**
|
| 58 |
* Implementation of hook_install().
|
| 59 |
*/
|
| 60 |
function better_formats_install() {
|
| 61 |
// Create tables.
|
| 62 |
drupal_install_schema('better_formats');
|
| 63 |
|
| 64 |
// Increase module weight to prevent compatibility issues.
|
| 65 |
$sql = "UPDATE {system}
|
| 66 |
SET weight = 100
|
| 67 |
WHERE name = 'better_formats'";
|
| 68 |
db_query($sql);
|
| 69 |
|
| 70 |
// Insert format defaults.
|
| 71 |
$roles = user_roles();
|
| 72 |
$sql = "INSERT INTO {better_formats_defaults}
|
| 73 |
VALUES (%d, '%s', %d, %d, %d)";
|
| 74 |
foreach ($roles as $rid => $role) {
|
| 75 |
db_query($sql, $rid, 'node', 0, 1, 0);
|
| 76 |
db_query($sql, $rid, 'comment', 0, 1, 0);
|
| 77 |
}
|
| 78 |
|
| 79 |
// Set default perms to be like core defaults.
|
| 80 |
$default_perms = ', show format selection, show format tips, show more format tips link, collapsible format selection, collapse format fieldset by default';
|
| 81 |
// Get current core perms.
|
| 82 |
$sql = "SELECT *
|
| 83 |
FROM {permission}
|
| 84 |
WHERE rid IN (1,2)";
|
| 85 |
$result = db_query($sql);
|
| 86 |
$row_perms = array();
|
| 87 |
while ($row = db_fetch_object($result)) {
|
| 88 |
$role_perms[] = $row;
|
| 89 |
}
|
| 90 |
// Add perms to core roles (anonymous user, authenticated user).
|
| 91 |
foreach ($role_perms as $perms) {
|
| 92 |
$sql = "UPDATE {permission}
|
| 93 |
SET perm = '%s'
|
| 94 |
WHERE pid = %d";
|
| 95 |
db_query($sql, $perms->perm . $default_perms, $perms->pid);
|
| 96 |
}
|
| 97 |
|
| 98 |
// Clear the cached pages
|
| 99 |
cache_clear_all();
|
| 100 |
}
|
| 101 |
|
| 102 |
/**
|
| 103 |
* Implementation of hook_uninstall().
|
| 104 |
*/
|
| 105 |
function better_formats_uninstall() {
|
| 106 |
// Remove tables.
|
| 107 |
drupal_uninstall_schema('better_formats');
|
| 108 |
|
| 109 |
// Delete settings from varible table.
|
| 110 |
$sql = "DELETE FROM {variable}
|
| 111 |
WHERE name LIKE 'better_formats%'";
|
| 112 |
db_query($sql);
|
| 113 |
}
|