Error in developing Local Plugin

Error in developing Local Plugin

by Vamsi Krishna Peruri -
Number of replies: 7

I am trying to write the local plugin in moodle/grade/report in moodle. In settings.php it is showing some warnings.
image.png

I included require_once($CFG->libdir . '/adminlib.php'); even though they are not resolved.
I tried to install without solving to see the error, then I can find the issue:
While upgrading the database, I am getting this error (picture attached below). I verified my XML using Validator, it shows no errors.
Can anyone help me to solve these problems?
Thanks in advance.

image%20%281%29.png

Average of ratings: -
In reply to Vamsi Krishna Peruri

Re: Error in developing Local Plugin

by Michael Hughes -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
You would probably need to post your db/install.xml file but you may have a valid XML file, but if it doesn't include the element (even if you have no tables) then it may fail the XMLDB structure requirements, rather than XML file validation.
In reply to Michael Hughes

Re: Error in developing Local Plugin

by Vamsi Krishna Peruri -
This is my install.xml file:
 
<?xml version="1.0" encoding="UTF-8"?>
<XMLDB PATH="grade/report/custom/db/install.xml" VERSION="2025030300" COMMENT="Custom Grade Report">
    <TABLE NAME="gradereport_custom" COMMENT="Stores user performance data">
        <FIELDS>
            <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" COMMENT="Primary Key"/>
            <FIELD NAME="user_id" TYPE="int" LENGTH="10" NOTNULL="true" COMMENT="User ID"/>
            <FIELD NAME="course_id" TYPE="int" LENGTH="10" NOTNULL="true" COMMENT="Course ID"/>
            <FIELD NAME="performance" TYPE="char" LENGTH="255" NOTNULL="true" COMMENT="Performance level"/>
        </FIELDS>
        <KEYS>
            <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
            <KEY NAME="user_course" TYPE="unique" FIELDS="user_id, course_id"/>
        </KEYS>
    </TABLE>
</XMLDB>

Is it correct?
In reply to Vamsi Krishna Peruri

Re: Error in developing Local Plugin

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

Your error says Missing TABLES section, and your install.xml indeed has no <TABLES> section. You need:

<?xml version="1.0" encoding="UTF-8"?>
<XMLDB PATH="grade/report/custom/db/install.xml" VERSION="2025030300" COMMENT="Custom Grade Report">
  <TABLES>
    <TABLE NAME="gradereport_custom" COMMENT="Stores user performance data">
        ⋮
    </TABLE>
  </TABLES>
</XMLDB>

If in doubt compare your file with any of the install.xml files in Moodle.

In reply to Leon Stringer

Re: Error in developing Local Plugin

by Vamsi Krishna Peruri -
Thank you Leon Stringer. I added it through XMLDB editor. It is installed, and there is one problem: I can't find the table in my DB.
Is there anything wrong with the plugin?
In reply to Vamsi Krishna Peruri

Re: Error in developing Local Plugin

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

The plugin's install.xml is read only once, when the plugin is first installed. If Moodle thinks your plugin is already installed (if it appears on the plugins overview page) then any changes to install.xml won't take effect.

You need to uninstall your plugin – make sure you have a backup of your plugin source code as Moodle will delete this if the web server can write to the source code directory – then with the source code folder in place Moodle will perform the install steps again, including creating the database table(s) in install.xml.

For completeness: any database changes to be made after the plugin's first install are done in db/upgrade.php.

In reply to Vamsi Krishna Peruri

Re: Error in developing Local Plugin

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Don't ever try to write install.xml files by hand.

Use the XMLDB editor under Admin -> Development -> XMLDB. That not only creates the right HTML for you, but checks a bunch of Moodle style rules as you define your tables, which can avoid pain later.