- Patch #19965 by Robin Monks: fixed problem with duplicate block titles.

4.7.x
Dries Buytaert 2005-04-12 18:52:47 +00:00
parent bbb746b814
commit f33f9a5fcd
5 changed files with 39 additions and 14 deletions

View File

@ -154,7 +154,6 @@ CREATE TABLE boxes (
info varchar(128) NOT NULL default '',
format int(4) NOT NULL default '0',
PRIMARY KEY (bid),
UNIQUE KEY title (title),
UNIQUE KEY info (info)
) TYPE=MyISAM;

View File

@ -153,8 +153,7 @@ CREATE TABLE boxes (
info varchar(128) NOT NULL default '',
format smallint NOT NULL default '0',
PRIMARY KEY (bid),
UNIQUE (info),
UNIQUE (title)
UNIQUE (info)
);
--

View File

@ -106,7 +106,8 @@ $sql_updates = array(
"2005-03-18" => "update_127",
"2005-03-21" => "update_128",
"2005-04-08: first update since Drupal 4.6.0 release" => "update_129",
"2005-04-10" => "update_130"
"2005-04-10" => "update_130",
"2005-04-11" => "update_131"
);
function update_32() {
@ -2376,4 +2377,18 @@ function update_130() {
return $ret;
}
function update_131() {
$ret = array();
if ($GLOBALS['db_type'] == 'mysql') {
$ret[] = update_sql("ALTER TABLE {boxes} DROP INDEX title");
$ret[] = update_sql("ALTER TABLE {boxes} ADD INDEX title (title)");
}
elseif ($GLOBALS['db_type'] == 'pgsql') {
$ret[] = update_sql("DROP INDEX boxes_title_idx");;
$ret[] = update_sql("CREATE INDEX title ON {boxes} (title)");
}
return $ret;
}
?>

View File

@ -312,12 +312,13 @@ function block_box_add() {
switch ($op) {
case t('Save block'):
block_box_save($edit);
drupal_set_message(t('The new block has been added.'));
drupal_goto('admin/block');
if (block_box_save($edit)) {
drupal_set_message(t('The new block has been added.'));
drupal_goto('admin/block');
}
// deliberate no break
default:
$form = block_box_form();
$form = block_box_form($edit);
$form .= form_submit(t('Save block'));
$output .= form($form);
}
@ -368,8 +369,13 @@ function block_box_save($edit, $delta = NULL) {
db_query("UPDATE {boxes} SET title = '%s', body = '%s', info = '%s', format = %d WHERE bid = %d", $edit['title'], $edit['body'], $edit['info'], $edit['format'], $delta);
}
else {
if (empty($edit['info']) || db_num_rows(db_query("SELECT info FROM {boxes} WHERE info = '%s'", $edit['info']))) {
form_set_error('title', t('Please ensure each block description is unique.'));
return false;
}
db_query("INSERT INTO {boxes} (title, body, info, format) VALUES ('%s', '%s', '%s', %d)", $edit['title'], $edit['body'], $edit['info'], $edit['format']);
}
return true;
}
/**

View File

@ -312,12 +312,13 @@ function block_box_add() {
switch ($op) {
case t('Save block'):
block_box_save($edit);
drupal_set_message(t('The new block has been added.'));
drupal_goto('admin/block');
if (block_box_save($edit)) {
drupal_set_message(t('The new block has been added.'));
drupal_goto('admin/block');
}
// deliberate no break
default:
$form = block_box_form();
$form = block_box_form($edit);
$form .= form_submit(t('Save block'));
$output .= form($form);
}
@ -368,8 +369,13 @@ function block_box_save($edit, $delta = NULL) {
db_query("UPDATE {boxes} SET title = '%s', body = '%s', info = '%s', format = %d WHERE bid = %d", $edit['title'], $edit['body'], $edit['info'], $edit['format'], $delta);
}
else {
if (empty($edit['info']) || db_num_rows(db_query("SELECT info FROM {boxes} WHERE info = '%s'", $edit['info']))) {
form_set_error('title', t('Please ensure each block description is unique.'));
return false;
}
db_query("INSERT INTO {boxes} (title, body, info, format) VALUES ('%s', '%s', '%s', %d)", $edit['title'], $edit['body'], $edit['info'], $edit['format']);
}
return true;
}
/**