Block doesn't move at all

Block doesn't move at all

by Longfei Yu -
Number of replies: 12

Guys,

I am on 2.0.1, and Oracle 11g.

I am trying to move the block from one position to another position, and I always got the following error message from the log file. However, if I extract the INSERT SQL STATEMENT out, and excuted in oracle directly, it succeeded, but, the block position still stayed at the original place, and did not move at all. Anyone met this problem also?

[Thu Feb 24 10:13:58 2011] [error] [client 128.119.164.178] Default exception handler: Error writing to database Debug: ORA-00001: unique constraint (MOODLEUSER.M_BLOCPOSI_BLOCONPAGSUB_UIX) violated\nINSERT INTO m_block_positions (region,weight,blockinstanceid,contextid,pagetype,subpage,visible) VALUES (:region,:weight,:blockinstanceid,:contextid,:pagetype,:subpage,:visible) RETURNING id INTO :oracle_id\n[array (\n  'region' => 'side-post',\n  'weight' => -1,\n  'blockinstanceid' => '185',\n  'contextid' => '793',\n  'pagetype' => 'course-view-weeks',\n  'subpage' => '',\n  'visible' => '1',\n)]\n* line 394 of /lib/dml/moodle_database.php: dml_write_exception thrown\n* line 268 of /lib/dml/oci_native_moodle_database.php: call to moodle_database->query_end()\n* line 1147 of /lib/dml/oci_native_moodle_database.php: call to oci_native_moodle_database->query_end()\n* line 1190 of /lib/dml/oci_native_moodle_database.php: call to oci_native_moodle_database->insert_record_raw()\n* line 752 of /lib/blocklib.php: call to oci_native_moodle_database->insert_record()\n* line 1394 of /lib/blocklib.php: call to block_manager->reposition_block()\n* line 1041 of /lib/blocklib.php: call to block_manager->process_url_move()\n* line 1178 of /lib/pagelib.php: call to block_manager->process_url_actions()\n* line 702 of /lib/pagelib.php: call to moodle_page->starting_output()\n* line 600 of /lib/outputrenderers.php: call to moodle_page->set_state()\n* line 196 of /course/view.php: call to core_renderer->header()\n, referer: http://moodlexxx.yyy.uwww.edu/course/view.php?id=31&sesskey=doLNH1Xg4S&bui_moveid=185

Average of ratings: -
In reply to Longfei Yu

Re: Block doesn't move at all

by Nick Thompson -

Longfei,

Is this related to the issue you reported the next day, or are they unrelated (http://moodle.org/mod/forum/discuss.php?d=169718)?

This issue looks like it might have been a predecessor to the one linked above.

Nick

In reply to Nick Thompson

Re: Block doesn't move at all

by Longfei Yu -
Yes, it is related. I think there is a logic issue with the program. Should not always be INSERT, sometime should be UPDATE.
In reply to Longfei Yu

Re: Block doesn't move at all

by Longfei Yu -

Here is the code I have suspicion: /lib/blocklib.php

738             if ($bi->blockpositionid) {

739                 $bp->id = $bi->blockpositionid;

740                 $DB->update_record('block_positions', $bp);

741

742             } else {

743                 $bp->blockinstanceid = $bi->id;

744                 $bp->contextid = $this->page->context->id;

745                 $bp->pagetype = $this->page->pagetype;

746                 if ($this->page->subpage) {

747                     $bp->subpage = $this->page->subpage;

748                 } else {

749                     $bp->subpage = '';

750                 }

751                 $bp->visible = $bi->visible;

752                 $DB->insert_record('block_positions', $bp);

753             }

754         }

755     }

What I am thinking is: if that blockinstance always has a record in the BLOCK_POSITIONS table, then, go to IF, UPDATE_RECORD, otherwise, go to ELSE, to INSERT_RECORD. I do not know why it looks like it always enter ELSE, trying to INSERT, and then throw me the UNIQUE CONSTAINT exception. By the way, I think the WEIGHT calculation is completely correct.

I have two concerns right now:

1. Why the program seems always go to ELSE block to INSERT

2. For the block display, why the program does not get the data from the WEIGHT in BLOCK_POSITIONS table, always get DEFAULTWEIGHT from BLOCK_INSTANCES table.

Thanks.

In reply to Longfei Yu

Re: Block doesn't move at all

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

That is good detective work, but actually, I think the problem is not here. This is only where the symptom really becomes apparent.

The key point is your observation 2. That is, the block positions are being ignored when the data is loaded, and if that is happening then $bi->blockpositionid will be null which explains why this update code takes the wrong path.

So, we need too look at the tricky query in load_blocks, starting on line 553 of the same file. Is the left join ever actually finding the right block_positions record?

In reply to Tim Hunt

Re: Block doesn't move at all

by Longfei Yu -
I am not at work right now. Will check the join later. The BLOCK move function is performing well with MYSQL? I doubt it is a DATABASE specific issue or not, since I am using ORACLE 11g. If it is not a DATABASE specific issue, then how to explain I always got the UNIQUE VIOLATION exception? What I am thinking is it should update if the BLOCKINSTANCE is already in the BLOCK_POSITIONS table, rather than INSERT always. Longfei
In reply to Longfei Yu

Re: Block doesn't move at all

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Well, the code worked when I originally wrote it about 18 months ago now.

And it is working for me now on my development server MySQL. As far as I am aware, it works on my other Postgres development server.

The Unique violation is naturally explained if it tried to insert a new row rather than updating the existing row that it should have found, but cannot.

I am very surprised that that SQL is not working on Oracle, as it does not seem to be doing anything that would not work across databases.

I think, however, that the next thing we need to do is for you to check the values returned by that query on your Oracle server.

Just add

print_object($bi);

inside the

foreach ($blockinstances as $bi) {

loop. Thanks.
In reply to Tim Hunt

Re: Block doesn't move at all

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I may have worked it out. Try the attached patch.

The problem is that Oracle thinks that the zero-length string and NULL are the same thing, which we have to work-around in various places, and I forgot to work-around it in the load_blocks query.

The attached patch adds the work-around. Please could you test it, when you can get to your Oracle server. Thanks.

In reply to Tim Hunt

Re: Block doesn't move at all

by Longfei Yu -

Thanks a lot, Tim.

Yes, it is working on our testing server. We need to do more test before we move it to Production.

Thanks again!

Longfei

In reply to Longfei Yu

Re: Block doesn't move at all

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

That sounds promising.

Do we have a tracker issue about this yet? If not, we need to get one created, and then submit the patch to be reviewed.

In reply to Tim Hunt

Re: Block doesn't move at all

by Longfei Yu -

ehhh, I just created one, please see at:

http://tracker.moodle.org/browse/MDL-26618

Let me know if you think it is accurate enough.

In reply to Longfei Yu

Re: Block doesn't move at all

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Great thanks. I just made my patch into a proper commit and added a comment.

In doing so, I noticed I had made a stupid error. My patch set $params['subpage1'] twice, when it should have set $params['subpage1'] and $params['subpage2']. You should correct that before doing more testing.

In reply to Tim Hunt

Re: Block doesn't move at all

by Longfei Yu -

Ah, Tim, I noticed the [subpage1] problem when I first looked at the patch, actually I corrected it to [subpage2] before I put it on our testing system. I forgot to mention this in my previous replies.

Thanks. Hopefully the code will work well.

Longfei