Feebly attempting to hack Block Course Upload tool for 2.0

Feebly attempting to hack Block Course Upload tool for 2.0

by Jason Hollowell -
Number of replies: 8

Hello all,

I am not a trained/educated programmer nor do I understand most of the changes made from 1.9 to 2.0 so I probably shouldn't even be poking around but... smile

There is significant demand/desire for a bulk course upload tool like the one that was available for 1.9 (here). Unfortunately the tool doesn't work under 2.0. I've been poking around with errors and debugging turned on in the hopes that I might be able to make some progress. I've made a little but not enough to make a difference.

I removed/replaced all instances of print_header with echo $OUTPUT ->header (done the same with footers) but still am encountering the following error:

Coding error detected, it must be fixed by a programmer: Invalid state passed to moodle_page::set_state. We are in state 2 and state 1 was requested.

The stack trace I'm getting is:

  • line 697 of /lib/pagelib.php: coding_exception thrown
  • line 600 of /lib/outputrenderers.php: call to moodle_page->set_state()
  • line 102 of /admin/uploadcourse.php: call to core_renderer->header()
  • line 125 of /admin/uploadcourse.php: call to csverror()
  • line 639 of /admin/uploadcourse.php: call to getdefaultcategory()

If anyone could give me a little nudge to point me in the right direction I'd be most appreciative.

Jason

Average of ratings: -
In reply to Jason Hollowell

Re: Feebly attempting to hack Block Course Upload tool for 2.0

by Jason Hollowell -

Since there was no response and I realized that the problem was due to the way the script is trying to print the header, I experiemented with various techniques and ended up getting past this problem for now by commenting out the header output. wink

Anyway, that just pushed me forward to a new problem. The script then runs partially. Partially meaning that it parses the file without issue but then it throws and error for all courses. Then creates categories and finishes. The error is as follows:

Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/moodle20/admin/uploadcourse.php on line 438

The code that I believe is generating this error is:

$temparray = explode(',',$validate[$col][1]);
if($validate[$col][0] == 1 || ($validate[$col][0] == 4  && !checkisint($temparray[0]) ) ) { //String or Domain with strings
$query = $query.''.mystr($course[$col]).', ';
}
else {
$query = $query.''.$course[$col].', ';

I cannot figure out what the root of the error is but it seems to be  related to the use of explode with the temparray. Any assistance will be greatly appreciated.

Jason

In reply to Jason Hollowell

Re: Feebly attempting to hack Block Course Upload tool for 2.0

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I think the the 'print_r' function will help you a lot in this process.

Try adding this line, just before the first line in the code you copied and pasted:

print_r($validate[$col]);

This should output the contents of that column of the $validate array and might help you to find out what is going wrong. I'm afraid I'm not familiar with the bulk_upload tool, so I can't really offer much more helpful advice than that...

In reply to Davo Smith

Re: Feebly attempting to hack Block Course Upload tool for 2.0

by Jason Hollowell -

Davo,

Thanks, I guess this has helped me to move forward a bit. Using print_r to output the contents of the array, I get the following and then the offset error for each course that I'm trying to create:

Array ( [0] => 1 [1] => 254 [2] => 1 ) Array ( [0] => 1 [1] => 15 [2] => 1 ) Array ( [0] => 2 [1] => 4294967295 [2] => 0 ) Array ( [0] => 1 [1] => 0 [2] => 0 ) Array ( [0] => 4 [1] => social,topics,weeks ) Array ( [0] => 4 [1] => 0,1 ) Array ( [0] => 2 [1] => 10 [2] => 0 ) Array ( [0] => 1 [1] => 100 [2] => 1 ) Array ( [0] => 1 [1] => 100 [2] => 1 ) Array ( [0] => 1 [1] => 100 [2] => 1 ) Array ( [0] => 1 [1] => 100 [2] => 1 ) Array ( [0] => 3 )
Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/moodle20/admin/uploadcourse.php on line 438


The problem now is that I'm not sure how to interpret the output. sad Any ideas?

Jason

In reply to Jason Hollowell

Re: Feebly attempting to hack Block Course Upload tool for 2.0

by Jason Hollowell -

Davo,

I'm not sure if you have the time (or interest smile ) to take a look at this but just in case, here is the Bulk Couse Upload tool (heavily hacked) that I'm working with.

The code that I pasted is located on (or around) line 432.

If you have time to take a look and advise it would be most appreciated. If not, I understand.

Jason

In reply to Jason Hollowell

Re: Feebly attempting to hack Block Course Upload tool for 2.0

by Jason Hollowell -

Davo,

Sorry, I'm kind of talking to myself here as I slowly figure out what the problem is/was. The problem is that the old Bulk Course Upload tool was, of course, designed to write into the old DB structure. The course table in 1.9 contained several fields that have been moved elsewhere in 2.0. I just figured this out by browsing the db in instances of both 1.9 and 2.0. Then I removed the fields in question from my file and was able to get the tool to create courses! Yeah! Now I just have to work on modifying the tool so it will write the information needed in the appropriate locations (new/different tables).

Jason

In reply to Jason Hollowell

Re: Feebly attempting to hack Block Course Upload tool for 2.0

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I'd love to offer to help you in more depth, but I'm afraid I'm rather snowed under here at the moment.

Hopefully a combination of phpmyadmin (to examine the database tables) and print_r (to examine the incoming data), will enable you to get there. If you have any specific questions about how to do something, then post them here and hopefully someone will have time to answer your query...

In reply to Davo Smith

Re: Feebly attempting to hack Block Course Upload tool for 2.0

by Jason Hollowell -

Davo,

No problem, you've already helped a ton. I think I can manage to poke around like you said and compare the tables in 1.9 and 2.0 and then rewrite the appropriate areas in the script without too much difficulty.

I never did figure out what the root cause of the Undefined offset problem but it doesn't seem to make the script fail so I'm ignoring it for now. My biggest problem was that I was trying to insert fields in colums that don't exist in the course table anymore.

Thanks again.

Jason