I've made a patch that adds a "Fix duplicate boxes"
button to the admin-layout options. It will wade through
the db and will remove the entries in mod_layout_box,
which have already been defined. We'd still want to fix
the underlying problem, though.
you might also want to check out
http://phpwsforums.com/viewtopic.php?t=43 for a
discussion about the bug.
here you go:
in layout/templates/settings.tpl add:
5a6
> {FIXTABLE}<br /><br />
in layout/class/Forms.php add:
140a141
> $form->add("fixTable", "submit", $_SESSION
["translate"]->it("Fix duplicate boxes"));
175a177,181
> if (isset($_POST["fixTable"])) {
> $GLOBALS['CNT_layout']['content'] = $this-
>fixTable() . "<hr />";
> $this->settings();
> }
>
211a218,324
> }
>
> function get_all_boxcounts() {
> /* returns assoc. array in the format
> theme => number of boxes */
>
> $sql = "SELECT theme, count(theme) FROM ".
> "mod_layout_box GROUP BY theme ORDER
BY theme";
>
> $box_counts = $GLOBALS["core"]->getAssoc($sql,
true);
>
> return($box_counts);
> }
>
> function get_all_boxes() {
> /* returns assoc. array in the format
> id => [ theme, mod_title, content_var ] */
>
> $sql = "SELECT id, theme, mod_title, content_var
FROM ".
> "mod_layout_box ORDER BY id";
>
> $all_boxes = $GLOBALS["core"]->getAllAssoc($sql,
true);
>
> $all_boxes = $GLOBALS["core"]->getAllAssoc($sql,
true);
>
> return($all_boxes);
> }
>
> function get_duplicates($arr) {
>
> $whitelist = array();
> $blacklist = array();
>
> $min_id=0;
>
> foreach($arr as $k => $v) {
> $theme=$v["theme"];
> $mod=$v["mod_title"];
> $content=$v["content_var"];
> $id=$v["id"];
>
> $entry="$theme|$mod|$content";
> $black="$entry|$id";
>
> if(isset($whitelist[$entry]))
> $blacklist[$id]=$black;
> else
> $whitelist[$entry]=$id;
> }
>
> return($blacklist);
> }
>
> function orify($arr) {
>
> $str="";
>
> foreach($arr as $id => $entry) {
> if($str != "")
> $str .= " or ";
>
> $str .= "id='$id'";
> }
>
> return($str);
> }
>
> function rm_duplicates($arr) {
>
> if(count($arr)<=0)
> return("nothing to do!");
>
> $sql = "DELETE FROM mod_layout_box WHERE ".
> $this->orify($arr);
>
> $result = $GLOBALS["core"]->query($sql);
>
> if($result == FALSE)
> return("sorry, didn't work out!</p>");
> else
> return("removed all the duplicates.");
> }
>
> function fixTable() {
> $themes = $this->get_themes();
> $all_boxes = $this->get_all_boxes();
> $dups = $this->get_duplicates($all_boxes);
>
> $dis_themes=implode(", ", $themes);
> if($dis_themes=="")
> $dis_themes="none";
>
> $dis_dups=implode(", ", $dups);
> if($dis_dups=="")
> $dis_dups="none";
>
> $content="<p><em>currently installed
themes:</em> ".
> "$dis_themes</p>\n";
>
> $content.="<p><em>duplicate boxes:</em> ".
> "$dis_dups</p>\n";
>
> if(count($dups) <= 0)
> $content.="<p>nothing to do!</p>";
> else {
> $content.="<p>".$this->rm_duplicates
($dups)."</p>";
> }
>
> return($content);
regards // René!
Logged In: YES
user_id=1035762
the official sourceforge thread on this:
http://sourceforge.net/tracker/?
func=detail&aid=1033652&group_id=15539&atid=115539
Logged In: YES
user_id=656822
Excellent. Works like a champ.
boxfix
Logged In: YES
user_id=225888
I have now applied this patch to CVS.
Steven