| 1 |
<?php
|
| 2 |
// $Id: outline.install,v 1.19 2008/11/28 12:01:39 augustin Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_install().
|
| 6 |
*/
|
| 7 |
function outline_install() {
|
| 8 |
// Create tables.
|
| 9 |
drupal_install_schema('outline');
|
| 10 |
|
| 11 |
// Import data from book.module:
|
| 12 |
$result = db_query('SELECT b.*, n.vid, n.uid FROM {book} b JOIN {node} n ON n.nid = b.nid WHERE b.nid = b.bid');
|
| 13 |
while ($book = db_fetch_object($result)) {
|
| 14 |
db_query("INSERT INTO {outline_book} (bid, book_vid, uid) VALUES (%d, %d, %d)",
|
| 15 |
$book->bid, $book->vid, $book->uid);
|
| 16 |
}
|
| 17 |
$result = db_query('SELECT b.*, n.vid, n2.vid AS book_vid FROM {book} b JOIN {node} n on n.nid = b.nid
|
| 18 |
JOIN {node} n2 ON n2.nid = b.bid');
|
| 19 |
while ($page = db_fetch_object($result)) {
|
| 20 |
db_query("INSERT INTO {outline_node} (mlid, nid, vid, bid, book_vid)
|
| 21 |
VALUES (%d, %d, %d, %d, %d)",
|
| 22 |
$page ->mlid, $page->nid, $page->vid, $page->bid, $page->book_vid);
|
| 23 |
}
|
| 24 |
}
|
| 25 |
|
| 26 |
/**
|
| 27 |
* Implementation of hook_enable().
|
| 28 |
*
|
| 29 |
* Check if more nodes have been outlined by book.module after the last time outline.module was enabled.
|
| 30 |
*/
|
| 31 |
function outline_enable() {
|
| 32 |
// 1- Import data from book.module where we don't have a corresponding outline entry:
|
| 33 |
$result = db_query('SELECT b.*, n.vid, n.uid, o.bid AS o_bid FROM {book} b JOIN {node} n ON n.nid = b.nid
|
| 34 |
LEFT JOIN {outline_book} o ON o.bid = b.bid AND o.book_vid = n.vid WHERE b.nid = b.bid AND o.bid IS NULL');
|
| 35 |
while ($book = db_fetch_object($result)) {
|
| 36 |
db_query("INSERT INTO {outline_book} (bid, book_vid, uid) VALUES (%d, %d, %d)",
|
| 37 |
$book->bid, $book->vid, $book->uid);
|
| 38 |
}
|
| 39 |
$result = db_query('SELECT b.*, n.vid, n2.vid AS book_vid, o.nid AS o_nid FROM {book} b JOIN {node} n on n.nid = b.nid
|
| 40 |
JOIN {node} n2 ON n2.nid = b.bid LEFT JOIN {outline_node} o ON o.nid = n.nid AND o.is_default = 1 AND o.vid = n.vid
|
| 41 |
WHERE o.nid IS NULL');
|
| 42 |
while ($page = db_fetch_object($result)) {
|
| 43 |
db_query("INSERT INTO {outline_node} (mlid, nid, vid, bid, book_vid)
|
| 44 |
VALUES (%d, %d, %d, %d, %d)",
|
| 45 |
$page ->mlid, $page->nid, $page->vid, $page->bid, $page->book_vid);
|
| 46 |
}
|
| 47 |
|
| 48 |
// 2- Update data where the vid, the place in the outline has changed, where nodes have been removed, etc...
|
| 49 |
// TODO.
|
| 50 |
}
|
| 51 |
|
| 52 |
/**
|
| 53 |
* Implementation of hook_schema().
|
| 54 |
*/
|
| 55 |
function outline_schema() {
|
| 56 |
|
| 57 |
$schema['outline_book'] = array(
|
| 58 |
'description' => t('Table to hold some per-book settings.'),
|
| 59 |
'fields' => array(
|
| 60 |
'bid' => array(
|
| 61 |
'description' => t(''),
|
| 62 |
'type' => 'int',
|
| 63 |
'unsigned' => TRUE,
|
| 64 |
'not null' => TRUE,
|
| 65 |
'default' => 0
|
| 66 |
),
|
| 67 |
'book_vid' => array(
|
| 68 |
'description' => t(''),
|
| 69 |
'type' => 'int',
|
| 70 |
'unsigned' => TRUE,
|
| 71 |
'not null' => TRUE,
|
| 72 |
'default' => 0
|
| 73 |
),
|
| 74 |
'uid' => array(
|
| 75 |
'description' => t(''),
|
| 76 |
'type' => 'int',
|
| 77 |
'unsigned' => TRUE,
|
| 78 |
'not null' => TRUE,
|
| 79 |
'default' => 0
|
| 80 |
),
|
| 81 |
'default_child_type' => array(
|
| 82 |
'description' => t("The child type for the book's children: either: <default> (i.e. site default), or any valid node type."),
|
| 83 |
'type' => 'varchar',
|
| 84 |
'length' => '255',
|
| 85 |
'default' => '<default>',
|
| 86 |
'not null' => TRUE
|
| 87 |
),
|
| 88 |
'default_toc_depth' => array(
|
| 89 |
'description' => t("How many levels shall we show in the TOC? Values can be -1 for the site default, or 0~9 for custom setting."),
|
| 90 |
'type' => 'int',
|
| 91 |
'unsigned' => FALSE,
|
| 92 |
'not null' => TRUE,
|
| 93 |
'default' => -1
|
| 94 |
),
|
| 95 |
'book_role_perm' => array(
|
| 96 |
'description' => t('Bool. If TRUE, then check {outline_perm} for permissions per role. If FALSE, behave like book.module.'),
|
| 97 |
'type' => 'int',
|
| 98 |
'unsigned' => TRUE,
|
| 99 |
'not null' => TRUE,
|
| 100 |
'default' => 0
|
| 101 |
),
|
| 102 |
'book_user_perm' => array(
|
| 103 |
'description' => t('Bool. If TRUE, then do extra DB lookups to see which additional users have extra permissions.'),
|
| 104 |
'type' => 'int',
|
| 105 |
'unsigned' => TRUE,
|
| 106 |
'not null' => TRUE,
|
| 107 |
'default' => 0
|
| 108 |
),
|
| 109 |
'restricted_types' => array(
|
| 110 |
'description' => t('Not currently used.'),
|
| 111 |
'type' => 'int',
|
| 112 |
'unsigned' => TRUE,
|
| 113 |
'not null' => TRUE,
|
| 114 |
'default' => 0
|
| 115 |
)
|
| 116 |
),
|
| 117 |
'primary key' => array('book_vid'),
|
| 118 |
'indexes' => array(
|
| 119 |
'bid' => array('bid'),
|
| 120 |
'book_role_perm' => array('book_role_perm'),
|
| 121 |
'book_user_perm' => array('book_user_perm')
|
| 122 |
),
|
| 123 |
);
|
| 124 |
|
| 125 |
$schema['outline_node'] = array(
|
| 126 |
'description' => t(''),
|
| 127 |
'fields' => array(
|
| 128 |
'mlid' => array(
|
| 129 |
'description' => t(''),
|
| 130 |
'type' => 'int',
|
| 131 |
'unsigned' => TRUE,
|
| 132 |
'not null' => TRUE,
|
| 133 |
'default' => 0
|
| 134 |
),
|
| 135 |
'nid' => array(
|
| 136 |
'description' => t(''),
|
| 137 |
'type' => 'int',
|
| 138 |
'unsigned' => TRUE,
|
| 139 |
'not null' => TRUE,
|
| 140 |
'default' => 0
|
| 141 |
),
|
| 142 |
'vid' => array(
|
| 143 |
'description' => t(''),
|
| 144 |
'type' => 'int',
|
| 145 |
'unsigned' => TRUE,
|
| 146 |
'not null' => TRUE,
|
| 147 |
'default' => 0
|
| 148 |
),
|
| 149 |
'bid' => array(
|
| 150 |
'description' => t(''),
|
| 151 |
'type' => 'int',
|
| 152 |
'unsigned' => TRUE,
|
| 153 |
'not null' => TRUE,
|
| 154 |
'default' => 0
|
| 155 |
),
|
| 156 |
'book_vid' => array(
|
| 157 |
'description' => t('The $vid of the book cover node related to this page.
|
| 158 |
This is always the latest $vid of the book cover, regardless of the version the book was
|
| 159 |
when the page was last edited.
|
| 160 |
The field is added here to make for easier JOINs between {outline_node} and {outline_book}'),
|
| 161 |
'type' => 'int',
|
| 162 |
'unsigned' => TRUE,
|
| 163 |
'not null' => TRUE,
|
| 164 |
'default' => 0
|
| 165 |
),
|
| 166 |
'is_default' => array(
|
| 167 |
'description' => t(''),
|
| 168 |
'type' => 'int',
|
| 169 |
'unsigned' => TRUE,
|
| 170 |
'not null' => TRUE,
|
| 171 |
'default' => 1
|
| 172 |
),
|
| 173 |
'child_type' => array(
|
| 174 |
'description' => t("The child type for the node's children: either: <default> (i.e. book default), or any valid node type."),
|
| 175 |
'type' => 'varchar',
|
| 176 |
'length' => '255',
|
| 177 |
'default' => '<default>',
|
| 178 |
'not null' => TRUE
|
| 179 |
),
|
| 180 |
'toc_depth' => array(
|
| 181 |
'description' => t("How many levels shall we show in the TOC? Values can be -1 for the book default, or 0~9 for custom setting."),
|
| 182 |
'type' => 'int',
|
| 183 |
'unsigned' => FALSE,
|
| 184 |
'not null' => TRUE,
|
| 185 |
'default' => -1
|
| 186 |
)
|
| 187 |
),
|
| 188 |
'primary key' => array('vid'),
|
| 189 |
'indexes' => array(
|
| 190 |
'mlid' => array('mlid'),
|
| 191 |
'nid' => array('nid'),
|
| 192 |
'bid' => array('bid'),
|
| 193 |
'book_vid' => array('book_vid'),
|
| 194 |
'is_default' => array('is_default')
|
| 195 |
),
|
| 196 |
);
|
| 197 |
|
| 198 |
$schema['outline_perm'] = array(
|
| 199 |
'description' => t(''),
|
| 200 |
'fields' => array(
|
| 201 |
'bid' => array(
|
| 202 |
'description' => t('The bid in {outline_book}.'),
|
| 203 |
'type' => 'int',
|
| 204 |
'unsigned' => TRUE,
|
| 205 |
'not null' => TRUE,
|
| 206 |
'default' => 0
|
| 207 |
),
|
| 208 |
'perm' => array(
|
| 209 |
'description' => t('The permission name as defined in admin/content/book/$bid/permission'),
|
| 210 |
'type' => 'varchar',
|
| 211 |
'length' => '255',
|
| 212 |
'not null' => TRUE
|
| 213 |
),
|
| 214 |
'type' => array(
|
| 215 |
'description' => t('Either "role" or "user".'),
|
| 216 |
'type' => 'varchar',
|
| 217 |
'length' => '255',
|
| 218 |
'not null' => TRUE
|
| 219 |
),
|
| 220 |
'type_id' => array(
|
| 221 |
'description' => t('The ID of the role or of the user according to "type".'),
|
| 222 |
'type' => 'int',
|
| 223 |
'unsigned' => TRUE,
|
| 224 |
'not null' => TRUE,
|
| 225 |
'default' => 0
|
| 226 |
)
|
| 227 |
),
|
| 228 |
'indexes' => array(
|
| 229 |
'bid' => array('bid'),
|
| 230 |
'type' => array('type'),
|
| 231 |
'perm' => array('perm')
|
| 232 |
),
|
| 233 |
);
|
| 234 |
|
| 235 |
$schema['outline_types'] = array(
|
| 236 |
'description' => t(''),
|
| 237 |
'fields' => array(
|
| 238 |
'bid' => array(
|
| 239 |
'description' => t(''),
|
| 240 |
'type' => 'int',
|
| 241 |
'unsigned' => TRUE,
|
| 242 |
'not null' => TRUE,
|
| 243 |
'default' => 0
|
| 244 |
),
|
| 245 |
'node_type' => array(
|
| 246 |
'description' => t(''),
|
| 247 |
'type' => 'varchar',
|
| 248 |
'length' => '255',
|
| 249 |
'not null' => TRUE
|
| 250 |
)
|
| 251 |
),
|
| 252 |
'indexes' => array(
|
| 253 |
'bid' => array('bid'),
|
| 254 |
'node_type' => array('node_type')
|
| 255 |
),
|
| 256 |
);
|
| 257 |
|
| 258 |
|
| 259 |
return $schema;
|
| 260 |
}
|
| 261 |
|
| 262 |
|
| 263 |
/**
|
| 264 |
* Import the data from the D5 tables into the new D6 tables.
|
| 265 |
*/
|
| 266 |
function outline_update_6000() {
|
| 267 |
$ret = array();
|
| 268 |
if (!module_exists('book')) {
|
| 269 |
module_enable(array('book'));
|
| 270 |
if (!db_table_exists('book')) {
|
| 271 |
drupal_install_modules(array('book'));
|
| 272 |
}
|
| 273 |
}
|
| 274 |
|
| 275 |
db_rename_table($ret, 'outline_volume', 'outline_volume_D5');
|
| 276 |
|
| 277 |
// Repeat the whole starting schema here, because using drupal_install_schema() is not safe.
|
| 278 |
// See Updating tables #2: Don't use hook_schema! http://drupal.org/node/150220
|
| 279 |
$schema['outline_book'] = array(
|
| 280 |
'fields' => array(
|
| 281 |
'bid' => array(
|
| 282 |
'type' => 'int',
|
| 283 |
'unsigned' => TRUE,
|
| 284 |
'not null' => TRUE,
|
| 285 |
'default' => 0
|
| 286 |
),
|
| 287 |
'book_vid' => array(
|
| 288 |
'type' => 'int',
|
| 289 |
'unsigned' => TRUE,
|
| 290 |
'not null' => TRUE,
|
| 291 |
'default' => 0
|
| 292 |
),
|
| 293 |
'uid' => array(
|
| 294 |
'type' => 'int',
|
| 295 |
'unsigned' => TRUE,
|
| 296 |
'not null' => TRUE,
|
| 297 |
'default' => 0
|
| 298 |
),
|
| 299 |
'default_child_type' => array(
|
| 300 |
'type' => 'varchar',
|
| 301 |
'length' => '255',
|
| 302 |
'default' => '<default>',
|
| 303 |
'not null' => TRUE
|
| 304 |
),
|
| 305 |
'default_toc_depth' => array(
|
| 306 |
'type' => 'int',
|
| 307 |
'unsigned' => FALSE,
|
| 308 |
'not null' => TRUE,
|
| 309 |
'default' => -1
|
| 310 |
),
|
| 311 |
'book_role_perm' => array(
|
| 312 |
'type' => 'int',
|
| 313 |
'unsigned' => TRUE,
|
| 314 |
'not null' => TRUE,
|
| 315 |
'default' => 0
|
| 316 |
),
|
| 317 |
'book_user_perm' => array(
|
| 318 |
'type' => 'int',
|
| 319 |
'unsigned' => TRUE,
|
| 320 |
'not null' => TRUE,
|
| 321 |
'default' => 0
|
| 322 |
),
|
| 323 |
'restricted_types' => array(
|
| 324 |
'type' => 'int',
|
| 325 |
'unsigned' => TRUE,
|
| 326 |
'not null' => TRUE,
|
| 327 |
'default' => 0
|
| 328 |
)
|
| 329 |
),
|
| 330 |
'primary key' => array('book_vid'),
|
| 331 |
'indexes' => array(
|
| 332 |
'bid' => array('bid'),
|
| 333 |
'book_role_perm' => array('book_role_perm'),
|
| 334 |
'book_user_perm' => array('book_user_perm')
|
| 335 |
),
|
| 336 |
);
|
| 337 |
|
| 338 |
$schema['outline_node'] = array(
|
| 339 |
'fields' => array(
|
| 340 |
'mlid' => array(
|
| 341 |
'type' => 'int',
|
| 342 |
'unsigned' => TRUE,
|
| 343 |
'not null' => TRUE,
|
| 344 |
'default' => 0
|
| 345 |
),
|
| 346 |
'nid' => array(
|
| 347 |
'type' => 'int',
|
| 348 |
'unsigned' => TRUE,
|
| 349 |
'not null' => TRUE,
|
| 350 |
'default' => 0
|
| 351 |
),
|
| 352 |
'vid' => array(
|
| 353 |
'type' => 'int',
|
| 354 |
'unsigned' => TRUE,
|
| 355 |
'not null' => TRUE,
|
| 356 |
'default' => 0
|
| 357 |
),
|
| 358 |
'bid' => array(
|
| 359 |
'type' => 'int',
|
| 360 |
'unsigned' => TRUE,
|
| 361 |
'not null' => TRUE,
|
| 362 |
'default' => 0
|
| 363 |
),
|
| 364 |
'book_vid' => array(
|
| 365 |
'type' => 'int',
|
| 366 |
'unsigned' => TRUE,
|
| 367 |
'not null' => TRUE,
|
| 368 |
'default' => 0
|
| 369 |
),
|
| 370 |
'is_default' => array(
|
| 371 |
'type' => 'int',
|
| 372 |
'unsigned' => TRUE,
|
| 373 |
'not null' => TRUE,
|
| 374 |
'default' => 1
|
| 375 |
),
|
| 376 |
'child_type' => array(
|
| 377 |
'type' => 'varchar',
|
| 378 |
'length' => '255',
|
| 379 |
'default' => '<default>',
|
| 380 |
'not null' => TRUE
|
| 381 |
),
|
| 382 |
'toc_depth' => array(
|
| 383 |
'type' => 'int',
|
| 384 |
'unsigned' => FALSE,
|
| 385 |
'not null' => TRUE,
|
| 386 |
'default' => -1
|
| 387 |
)
|
| 388 |
),
|
| 389 |
'primary key' => array('vid'),
|
| 390 |
'indexes' => array(
|
| 391 |
'mlid' => array('mlid'),
|
| 392 |
'nid' => array('nid'),
|
| 393 |
'bid' => array('bid'),
|
| 394 |
'book_vid' => array('book_vid'),
|
| 395 |
'is_default' => array('is_default')
|
| 396 |
),
|
| 397 |
);
|
| 398 |
|
| 399 |
$schema['outline_perm'] = array(
|
| 400 |
'fields' => array(
|
| 401 |
'bid' => array(
|
| 402 |
'type' => 'int',
|
| 403 |
'unsigned' => TRUE,
|
| 404 |
'not null' => TRUE,
|
| 405 |
'default' => 0
|
| 406 |
),
|
| 407 |
'perm' => array(
|
| 408 |
'type' => 'varchar',
|
| 409 |
'length' => '255',
|
| 410 |
'not null' => TRUE
|
| 411 |
),
|
| 412 |
'type' => array(
|
| 413 |
'type' => 'varchar',
|
| 414 |
'length' => '255',
|
| 415 |
'not null' => TRUE
|
| 416 |
),
|
| 417 |
'type_id' => array(
|
| 418 |
'type' => 'int',
|
| 419 |
'unsigned' => TRUE,
|
| 420 |
'not null' => TRUE,
|
| 421 |
'default' => 0
|
| 422 |
)
|
| 423 |
),
|
| 424 |
'indexes' => array(
|
| 425 |
'bid' => array('bid'),
|
| 426 |
'type' => array('type'),
|
| 427 |
'perm' => array('perm')
|
| 428 |
),
|
| 429 |
);
|
| 430 |
|
| 431 |
$schema['outline_types'] = array(
|
| 432 |
'fields' => array(
|
| 433 |
'bid' => array(
|
| 434 |
'type' => 'int',
|
| 435 |
'unsigned' => TRUE,
|
| 436 |
'not null' => TRUE,
|
| 437 |
'default' => 0
|
| 438 |
),
|
| 439 |
'node_type' => array(
|
| 440 |
'type' => 'varchar',
|
| 441 |
'length' => '255',
|
| 442 |
'not null' => TRUE
|
| 443 |
)
|
| 444 |
),
|
| 445 |
'indexes' => array(
|
| 446 |
'bid' => array('bid'),
|
| 447 |
'node_type' => array('node_type')
|
| 448 |
),
|
| 449 |
);
|
| 450 |
db_create_table($ret, 'outline_book', $schema['outline_book']);
|
| 451 |
db_create_table($ret, 'outline_node', $schema['outline_node']);
|
| 452 |
db_create_table($ret, 'outline_perm', $schema['outline_perm']);
|
| 453 |
db_create_table($ret, 'outline_types', $schema['outline_types']);
|
| 454 |
|
| 455 |
$book = array(); // store the mlid for each node.
|
| 456 |
$result = db_query('SELECT o.*, v.*, n.title, n.vid, n.uid
|
| 457 |
FROM {outline_nodes} o
|
| 458 |
JOIN {outline_volume_D5} v ON v.volume_id = o.volume_id
|
| 459 |
JOIN {node} n ON n.nid = o.nid
|
| 460 |
{ORDER BY o.volume_id, parent');
|
| 461 |
while ($item = db_fetch_object($result)) {
|
| 462 |
if ($item->parent == 0) {
|
| 463 |
// create a new book.
|
| 464 |
db_query("INSERT INTO {menu_links} (menu_name, plid, link_path, router_path, link_title, module, options, depth)
|
| 465 |
VALUES ('%s', 0, '%s', '%s', '%s', 'book', '%s', 1)",
|
| 466 |
'book-toc-'. $item->nid, 'node/'. $item->nid, 'node/%', $item->title, 'a:0:{}' );
|
| 467 |
$mlid = db_last_insert_id('menu_links', 'mlid');
|
| 468 |
db_query('UPDATE {menu_links} SET p1 = %d WHERE mlid = %d', $mlid, $mlid);
|
| 469 |
db_query('INSERT INTO {book} (mlid, nid, bid) VALUES (%d, %d, %d)', $mlid, $item->nid, $item->nid);
|
| 470 |
// Update own tables:
|
| 471 |
db_query("INSERT INTO {outline_book} (bid, book_vid, uid, default_child_type, default_toc_depth, book_role_perm, book_user_perm)
|
| 472 |
VALUES (%d, %d, %d, '%s', '%s', %d, %d)",
|
| 473 |
$item->nid, $item->vid, $item->uid, $item->default_child_type, $item->default_toc_depth, 0, 0);
|
| 474 |
db_query("INSERT INTO {outline_node} (mlid, nid, vid, bid, book_vid, is_default, child_type, toc_depth)
|
| 475 |
VALUES (%d, %d, %d, %d, %d, 1, '%s', %d)",
|
| 476 |
$mlid, $item->nid, $item->vid, $item->nid, $item->vid, $item->child_type, $item->toc_depth);
|
| 477 |
$book[$item->nid] = $mlid;
|
| 478 |
}
|
| 479 |
else {
|
| 480 |
_outline_update_6000($item, $book);
|
| 481 |
}
|
| 482 |
}
|
| 483 |
|
| 484 |
db_drop_table($ret, 'outline_volume_D5');
|
| 485 |
db_drop_table($ret, 'outline_nodes');
|
| 486 |
return $ret;
|
| 487 |
}
|
| 488 |
|
| 489 |
/**
|
| 490 |
* Helper function
|
| 491 |
* @param $item: object from {outline_nodes}
|
| 492 |
* @param $book: array of nodes => mlid.
|
| 493 |
*/
|
| 494 |
function _outline_update_6000($item, &$book) {
|
| 495 |
// check it hasn't been inserted yet.
|
| 496 |
if (!isset($book[$item->nid])) {
|
| 497 |
// Check if the parent has been inserted.
|
| 498 |
if(!isset($book[$item->parent])) {
|
| 499 |
// get the parent item from {outline_nodes}
|
| 500 |
$parent = db_fetch_object(db_query('SELECT * FROM {outline_nodes} WHERE nid = %d', $item->parent));
|
| 501 |
_outline_update_6000($parent, $book);
|
| 502 |
}
|
| 503 |
|
| 504 |
$parent = db_fetch_object(db_query('SELECT * FROM {menu_links} WHERE mlid = %d', $book[$item->parent]));
|
| 505 |
// Set the values for p1 to p9
|
| 506 |
$p = array(1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0);
|
| 507 |
$d = $parent->depth;
|
| 508 |
for ($i = 1; $i <= $d; $i++) {
|
| 509 |
$key = 'p'. $i;
|
| 510 |
$p[$i] = $parent->$key;
|
| 511 |
}
|
| 512 |
db_query("INSERT INTO {menu_links}
|
| 513 |
(menu_name, plid, link_path, router_path, link_title, module, options, depth, p1, p2, p3, p4, p5, p6, p7, p8, p9)
|
| 514 |
VALUES ('%s', %d, '%s', '%s', '%s', 'book', '%s', %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)",
|
| 515 |
$parent->menu_name, $parent->mlid, 'node/'. $item->nid, 'node/%', $item->title, 'a:0:{}', $parent->depth + 1,
|
| 516 |
$p[1], $p[2], $p[3], $p[4], $p[5], $p[6], $p[7], $p[8], $p[9]);
|
| 517 |
$mlid = db_last_insert_id('menu_links', 'mlid');
|
| 518 |
$bid = db_result(db_query('SELECT bid FROM {book} WHERE mlid = %d', $parent->mlid));
|
| 519 |
db_query('INSERT INTO {book} (mlid, nid, bid) VALUES (%d, %d, %d)', $mlid, $item->nid, $bid);
|
| 520 |
$book[$item->nid] = $mlid;
|
| 521 |
|
| 522 |
// Tell the parent that it has a child :)
|
| 523 |
db_query('UPDATE {menu_links} SET has_children = 1 WHERE mlid = %d', $parent->mlid);
|
| 524 |
$p[$i] = $mlid;
|
| 525 |
db_query('UPDATE {menu_links} SET p%d = %d WHERE mlid = %d', $i, $mlid, $mlid);
|
| 526 |
$d = $parent->depth +1;
|
| 527 |
|
| 528 |
// Update own tables:
|
| 529 |
$book_vid = db_result(db_query('SELECT vid FROM {node} WHERE nid = %d', $bid));
|
| 530 |
db_query("INSERT INTO {outline_node} (mlid, nid, vid, bid, book_vid, is_default, child_type, toc_depth)
|
| 531 |
VALUES (%d, %d, %d, %d, %d, 1, '%s', %d)",
|
| 532 |
$mlid, $item->nid, $item->vid, $bid, $book_vid, $item->child_type, $item->toc_depth);
|
| 533 |
}
|
| 534 |
// else it has already been inserted. move on.
|
| 535 |
}
|
| 536 |
|
| 537 |
|
| 538 |
/**
|
| 539 |
* Delete obsolete variable.
|
| 540 |
*/
|
| 541 |
function outline_update_6001() {
|
| 542 |
$ret = array();
|
| 543 |
variable_del('outline_supported');
|
| 544 |
return $ret;
|
| 545 |
}
|
| 546 |
|
| 547 |
/**
|
| 548 |
* Clean menu cache because of updated outline_menu().
|
| 549 |
*/
|
| 550 |
function outline_update_6002() {
|
| 551 |
$ret = array();
|
| 552 |
menu_cache_clear_all();
|
| 553 |
$ret[] = array('success' => TRUE, 'query' => 'The menu cache has been cleared. Check the new permission settings at admin > Content management > Books > edit permissions. Thank you for supporting charitable web sites. :)');
|
| 554 |
return $ret;
|
| 555 |
}
|
| 556 |
|
| 557 |
/**
|
| 558 |
* Implementation of hook_uninstall().
|
| 559 |
*/
|
| 560 |
function outline_uninstall() {
|
| 561 |
db_query('DROP TABLE {outline_book}');
|
| 562 |
db_query('DROP TABLE {outline_node}');
|
| 563 |
db_query('DROP TABLE {outline_perm}');
|
| 564 |
db_query('DROP TABLE {outline_types}');
|
| 565 |
db_query("DELETE FROM {variable} WHERE name LIKE 'outline_%%'");
|
| 566 |
}
|
| 567 |
|
| 568 |
|