View source
<?php
function book_copy_install() {
drupal_install_schema('book_copy');
db_query("UPDATE {system} SET weight = 15 WHERE name = 'book_copy'");
}
function book_copy_uninstall() {
drupal_uninstall_schema('book_copy');
}
function book_copy_schema() {
$schema['book_copy_history'] = array(
'description' => t('This table maintains source history for books derived via the copy feature'),
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('The new nid of the node copied'),
),
'bid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('The target book (when initially copied)'),
),
'sbid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('The source book'),
),
'snid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('The source nid.'),
),
'copied' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('The datetime this was copied'),
),
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('The new uid of the user initiating the copy.'),
),
),
'primary key' => array(
'nid',
),
);
return $schema;
}
function book_copy_update_6000() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {book_copy_history} ADD uid int(11) NOT NULL");
$result = db_query("SELECT distinct b.bid, u.uid FROM {book} b LEFT JOIN {node} n ON n.nid = b.nid LEFT JOIN {users} u ON n.uid = u.uid;");
while ($row = db_fetch_array($result)) {
db_query("UPDATE {book_copy_history} SET uid = %d WHERE bid = %d", $row['uid'], $row['bid']);
}
$result = db_query("SELECT n.nid, u.uid FROM {book_copy_history} bch LEFT JOIN {node} n ON n.nid = bch.nid LEFT JOIN {users} u ON u.uid = n.uid WHERE bch.uid = 0");
while ($row = db_fetch_array($result)) {
db_query("UPDATE {book_copy_history} SET uid = %d WHERE nid = %d", $row['uid'], $row['nid']);
}
break;
}
return $ret;
}