View source
<?php
function legal_install() {
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
$query1 = db_query("CREATE TABLE IF NOT EXISTS {legal_accepted} (\n legal_id int(10) NOT NULL auto_increment,\n uid int(10) NOT NULL default '0',\n tc_id int(10) NOT NULL default '0',\n accepted int(11) NOT NULL default '0',\n PRIMARY KEY (legal_id),\n KEY uid (uid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
$query2 = db_query("CREATE TABLE IF NOT EXISTS {legal_conditions} (\n tc_id int(10) NOT NULL auto_increment,\n conditions longtext NOT NULL,\n date int(11) NOT NULL default '0',\n extras text,\n changes text,\n PRIMARY KEY (tc_id)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
if ($query1 && $query2) {
$created = TRUE;
}
break;
default:
break;
}
if ($created) {
drupal_set_message(t('Legal module installed successfully.'));
}
else {
drupal_set_message(t('Table installation for the Legal module was unsuccessful. The tables may need to be installed by hand. See legal.install file for a list of the installation queries.'), 'error');
}
return;
}
function legal_update_1() {
_system_update_utf8(array(
'legal_accepted',
'legal_conditions',
));
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
$ret[] = update_sql("ALTER TABLE {legal_conditions} ADD extras TEXT");
$ret[] = update_sql("ALTER TABLE {legal_conditions} ADD changes TEXT");
break;
default:
break;
}
return $ret;
}
function legal_uninstall() {
db_query('DROP TABLE {legal_accepted}');
db_query('DROP TABLE {legal_conditions}');
variable_del('legal_display');
}
function legal_update_2() {
$limit = 50;
if (!isset($_SESSION['legal_update_2'])) {
$conditions = db_fetch_array(db_query_range("SELECT * FROM {legal_conditions} ORDER BY tc_id DESC", 0, 1));
if (empty($conditions['conditions'])) {
return;
}
$extras = empty($conditions['extras']) ? NULL : array_keys(unserialize($conditions['extras']));
$_SESSION['legal_update_2'] = array(
'uid' => 0,
'max' => db_result(db_query('SELECT MAX(uid) FROM {users}')),
'extras' => $extras,
);
}
$result = db_query_range("SELECT uid, data FROM {users} WHERE uid > %d AND data LIKE '%%s:10:\"conditions\"%%'", $_SESSION['legal_update_2']['uid'], 0, $limit);
while ($user = db_fetch_object($result)) {
$data = unserialize($user->data);
unset($data['conditions']);
if (!empty($_SESSION['legal_update_2']['extras'])) {
foreach ($_SESSION['legal_update_2']['extras'] as $extra) {
unset($data[$extra]);
}
}
db_query("UPDATE {users} SET data = '%s' WHERE uid = %d", serialize($data), $user->uid);
$_SESSION['legal_update_2']['uid'] = $user->uid;
}
if (db_num_rows($result) == $limit) {
return array(
'#finished' => $_SESSION['legal_update_2']['uid'] / ($_SESSION['legal_update_2']['max'] + 1),
);
}
else {
unset($_SESSION['legal_update_2']);
return array();
}
}