I tried to add a new resource to a page and received this error:
Could not add a new instance or resource
Help!!
Thanks in advance!
Desiree Koons
best,
Tom
Yes, we did. For more details, here's a post made by my colleague:
I carefully backed up and followed the upgrade instruction and received only the following errors during the database upgrade:
(mysql): ALTER TABLE `mdl_user` ADD INDEX user_auth (auth)
1072: Key column 'auth' doesn't exist in table
adodb_mysql._execute( ALTER TABLE `mdl_user` ADD INDEX user_auth (auth) , false) % line 804, file: adodb.inc.php
adodb_mysql.execute( ALTER TABLE `mdl_user` ADD INDEX user_auth (auth) ) % line 30, file: datalib.php
execute_sql( ALTER TABLE `mdl_user` ADD INDEX user_auth (auth) ) % line 848, file: mysql.php
main_upgrade(2004083125) % line 161, file: index.php
Error
(mysql): ALTER TABLE `mdl_course` ADD INDEX idnumber (idnumber)
1072: Key column 'idnumber' doesn't exist in table
adodb_mysql._execute( ALTER TABLE `mdl_course` ADD INDEX idnumber (idnumber) , false) % line 804, file: adodb.inc.php
adodb_mysql.execute( ALTER TABLE `mdl_course` ADD INDEX idnumber (idnumber) ) % line 30, file: datalib.php
execute_sql( ALTER TABLE `mdl_course` ADD INDEX idnumber (idnumber) ) % line 852, file: mysql.php
main_upgrade(2004083125) % line 161, file: index.php
Error
Everything else seems to be fine except that when clicking on any Resources, they do not load. Running tail on the Apache logs gives me these (or very similar) errors:
[Mon Feb 14 20:20:23 2005] [error] PHP Warning: main(/Library/WebServer/rmhs/moodle/mod/resource/type/4/resource.class.php): failed to open stream: No such file or directory in /Library/WebServer/rmhs/moodle/mod/resource/view.php on line 20
[Mon Feb 14 20:20:27 2005] [error] PHP Warning: main(/Library/WebServer/rmhs/moodle/mod/resource/type/6/resource.class.php): failed to open stream: No such file or directory in /Library/WebServer/rmhs/moodle/mod/resource/view.php on line 20
[Mon Feb 14 20:20:33 2005] [error] PHP Warning: main(/Library/WebServer/rmhs/moodle/mod/resource/type/3/resource.class.php): failed to open stream: No such file or directory in /Library/WebServer/rmhs/moodle/mod/resource/view.php on line 20
Any idea what the problem here is? Is the database hosed? Seems that the problem here is related to the resources table.
Thanks for your help!
Now that we've narrowed it down, developers could you lend a hand?
I wish I had the knowledge to figure it out for you. Essentially, we have to add those tables that are missing.
.../moodle/mod/resource/type/text/resource.class.php
If you are able to have a look at the database, the 'resource' table should have a column 'type' with entries such as 'text', 'html', 'file', 'directory'. If it doesn't then this is where the error is. If it does then error lies elsewhere, most likely a corrupted PHP file somewhere.
I setup a separate moodle test server to try to figure this database thing out and I imported a dump from the production server. So, I still have those numerical values for 'type' but--this is the good part--I see that some of the new resources I added when testing have values of "text", "html", etc. for 'type'. So, the fix should be to either manually or with a query script, change the numerical values to the new proper values.
I'll try some and see if this does the trick.
We'll need to change the value in the 'type' column but it seems that we'll also need to populate the 'options' column too.
But, looking at the moodle folder, in /moodle/mod/resource/db the file mysql.sql is a MySQL-Dump of the table structure for mdl_resource.
This line defines the type column:
type varchar(30) NOT NULL default '', (This is a variable-length string).
Our previous version was defined like this:
type tinyint(4) NOT NULL default '0', (This is a 1 byte integer).
That's a big difference. So, for us, the upgrade was a failure because the database did not upgrade properly and convert the values appropriately (I'm assuming it was supposed to); our current "resource types" have integer values but the new Moodle wants string values. Oy!
I have manually changed some of the values from integers to "file" as well as "" and was successful in viewing the resource. It would be nice to know exactly how to translate the integer values to the string values. In other words, what should "0" be and what should "2" be, etc. I may just change them all to "" because that's the easiest value and it works but I'm going to post in the developer forum to see if any of the database brains can answer this one.
It basically does the following:
type = 1 : type = 'html', alltext = [reference field]I've attached a dump of the 'resource' table CREATE for reference.
type = 2 : type = 'file', options = 'frame'
type = 3 : type = 'file'
type = 4 : type = 'text', options = '0'
type = 5 : type = 'file'
type = 6 : type = 'html'
type = 7 : type = 'file'
type = 8 : type = 'text', options = '3'
type = 9 : type = 'directory'
HTH.
Is there a current ER diagram of the database available anywhere? This would be really helpful in understanding the relationships between tables.
Thanks for your help!
A quick fix is to edit the "modules" table, and set the version for "resources" back to 2004070900, then visit the admin page. This will force the resource module to try upgrading itself again.
1060: Duplicate column name 'popup'
adodb_mysql._execute(ALTER TABLE mdl_resource ADD popup TEXT DEFAULT '' AFTER `allt..., false) % line 804, file: adodb.inc.php
adodb_mysql.execute(ALTER TABLE mdl_resource ADD popup TEXT DEFAULT '' AFTER `allt...) % line 30, file: datalib.php
execute_sql(ALTER TABLE mdl_resource ADD popup TEXT DEFAULT '' AFTER `allt...) % line 211, file: datalib.php
table_column(resource, , popup, text, , , , , alltext) % line 19, file: mysql.php
resource_upgrade(2004070900, Object:stdClass) % line 150, file: adminlib.php
1061: Duplicate key name 'course'
adodb_mysql._execute(ALTER TABLE mdl_resource ADD INDEX course (course), false) % line 804, file: adodb.inc.php
adodb_mysql.execute(ALTER TABLE mdl_resource ADD INDEX course (course)) % line 30, file: datalib.php
execute_sql(ALTER TABLE mdl_resource ADD INDEX course (course)) % line 152, file: datalib.php
modify_database(, ALTER TABLE prefix_resource ADD INDEX course (course);) % line 57, file: mysql.php
resource_upgrade(2004070900, Object:stdClass) % line 150, file: adminlib.php
I think I'll go ahead and change the remaining values in the type column and then spend some time checking the tables against the fresh install on my test server or an ER diagram to see if there's anything else that needs to be fixed.
Thanks for your help!
We checked the integrity of the database, and it's fine. We did a clean install of the files, which upgraded the database.
Any ideas anybody? we would appreciate any clues. Thanks!