problem - NEWMODULE doesn't work

problem - NEWMODULE doesn't work

by L M -
Number of replies: 16

Hello,

I want to develop my own module, but I am a raw recruit. I have some basics in PHP and MySQL. At the beginning I followed this tutorial: http://docs.moodle.org/dev/NEWMODULE_Documentation

First I want to give you my system-information:
Windows 7, 64 bit
XAMMP 1.8.3. with PHP 5.5.6
Moodle 2.5 (latest)

At the tutorial there are three newmodule-zips offered. The first one (for 2.x) doesn’t work for me. If I copy it (with all renames) into the mod-directory the whole moodle-platform doesn’t work anymore and shows me just blank sites. So I tried the third zip. First, there was the same problem, but when I change the structure a little bit, it works for the next step (not NEWMODULE/lang/en_utf8/newmodule.php, but NEWMODULE/lang/en/newmodule.php and without the help-directory).
Allright. I copied my module-files into the mod-directory and started the update with Service Administration -> Notofications. I got just the information “success”. After this I switched to my course and tried to add my new activity. I could choose my widget (there was no icon sad ). I agreed and nothing happened. I got just a blank site with this address: “http://localhost/moodle/course/modedit.php?add=newwidget&type=&course=2&section=1&return=0&sr=0”
No new activity was added. I tried also another tutorial, but the same result…

I’m very unhappy, because I searched lots of time without a solution. I hope you can help me! If there is someone, who want to be my “personal mentor” and gives me some start-up aid, I would be very grateful. Then I haven’t to tease the forum all the time wink.

Thanks a lot in advance!

Average of ratings: Useful (1)
In reply to L M

Re: problem - NEWMODULE doesn't work

by L M -

Is there ANYTHING I could check or try? Do I have to use another newmodule.zip for moodle 2.5?

I would be grateful for every hint! smile

In reply to L M

Re: problem - NEWMODULE doesn't work

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Don't be too discouraged. That is how it starts when you write a plugin, especially your first one.

In fact you were able to get your mod installed, which is pretty good progress. As a plugin dev. error messages are definitely your friends. So check the link that Davo gave you. If you send error messages to the html page, that can speed up development.

But "500 errors" (often syntax errors, missed semi colons, unclosed brackets etc) can kill the page before it is displayed, aka blank screen. So you also need to keep looking at the last few lines of your server's error log. If you don't know where that is, that should be the next thing you find out. On a shared host, that can be accessed via cpanel.  If you can't find it, google the question and you should get the location pretty fast. The log will usually tell you the filename and line number where the error occurs. 

It also helps to have browser based tool to spot javascript errors, or to see what files are giving 404 errors (can't be found). In google Chrome that is the built in "developer tools." In Firefox it is Firebug(though you have to download it separately).

In Moodle 2, a lot changed and the location of english language files became /lang/en/newmodule.php because everything is now utf8 and there is no need to labor the point. It looks like your project template is a little dated.

Average of ratings: Useful (1)
In reply to Justin Hunt

Re: problem - NEWMODULE doesn't work

by L M -

Thank you very much for your answers. I turned the debugging on and got this message after copying my new module in the mod-directory:

“Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\moodle\lib\moodlelib.php on line 8371”

I looked it up and found the foreach-loop you can see in the attachement screenshot01. After this I added some code to the moodle/config.php, that I have found in the internet (ini_set ('display_errors', 'on'); ini_set ('log_errors', 'on'); …). I reloaded the notifications-site and now I had the possibility to install my module (now named just facebook). After this I got the new hints you can see on the screenshot02.
But why does it work now? But it’s not a real success. If I go back to the home-site I got just a diffused website of my moodle platform. No style and no icons.

I can’t find some error.log-files in the moodle-directory. Just from Apache. But I can’t find out, which ones are the important logs.

I started a second try. I deleted my new module and copied it in the mod-file again. After a click of Notifications I got this error:

“Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\moodle\lib\filelib.php on line 3291”

I was looking up the code -> screenshot03 So what could be the problem?

PS: When I start Apache (with XAMPP) I got this warning, but it still runs: [22-Jan-2014 07:48:03 UTC] PHP Warning: PHP Startup: in Unknown on line 0

Attachment screenshot01.JPG
Attachment screenshot02.JPG
Attachment screenshot03.JPG
In reply to L M

Re: problem - NEWMODULE doesn't work

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Sorry L M

I don't have time to get that specific on the issues. Perhaps some else can say something. But it looks like the plugin you are installing is based on an older format (Moodle 1.9?) and that is causing you the bulk of the difficulties.

I have a few templates that I use personally when making other kinds of plugins (tinyMCE plugins, assignment submissions etc) , but not a mod /activity template.  Perhaps you would be better to modify a working moodle 2.x mod from the plugins database to get started?

I learned a lot from the flashcards mod when I was first starting out in Moodle. Sorry not to be able to give more specific help. 

In reply to Justin Hunt

Re: problem - NEWMODULE doesn't work

by L M -

Thank you for your answer. I agree, it must be an template, which is too old. But I can’t find other templates as this ones: http://docs.moodle.org/dev/NEWMODULE_Documentation

The template for “2.x” also doesn’t work for moodle 2.5.

Does anyone have a link to a newer one?

In reply to L M

Re: problem - NEWMODULE doesn't work

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

There is no newer one. You could make a massive contribution to global Moodle development by creating one.

Average of ratings: Useful (1)
In reply to L M

Re: problem - NEWMODULE doesn't work

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

The template linked to from that page ( https://github.com/moodlehq/moodle-mod_newmodule ) looks up to date to me. I haven't got time to test it just at the moment, but I can't see any immediate reason why it wouldn't work in Moodle 2.5 (after you've renamed the directory + all mentions of 'newmodule' to your chosen name; if you don't rename it, then Moodle is hard-coded to ignore it).

You say that it 'doesn't work for moodle 2.5' - in what what way doesn't it work?

What was the error message?

Did you rename it, as mentioned above + in the README file that comes with it?

Have you turned on debugging ( http://docs.moodle.org/25/en/Debugging )?

In reply to Davo Smith

Re: problem - NEWMODULE doesn't work

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Ahh, for some reason I was thinking of the old Question Type skeleton which has not been updated in a while. That module skeleton looks like it has been kept up to date based on David Mudraks commits.

In reply to Davo Smith

Re: problem - NEWMODULE doesn't work

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Looking back over your error messages, it is clear that you have been using the 1.9 new module.

That is why the language files were in en_utf8 and you got some of those other errors. A 1.9 plugin won't work in Moodle 2.x

I attached a screenshot of that page showing which module to take.

I personally downloaded the 2.x template, renamed it and installed it. So I can confirm that it works without error.  I noticed that if I did not specify a version number that the mod would not install at all. By default the new module template has the version set at 0. Perhaps this was the problem you initially had?

After I specified a version number it installed fine. Do that in version.php. Usually it is the current date + a two digit revision number.  So in this case I set the version number to 2014012400

On the New Module docs page they offer some suggestions as to how to change the module name. However you do it, I suggest you don't do it by hand. I used notepad++ on a windows machine. Using notepad++ is possible from the search menu's  "find in files" to recursively go through a directory replacing a string of text with another. That is what I did.

Hope that helps

Attachment スクリーンショット_012414_012116_PM.jpg
In reply to Justin Hunt

Re: problem - NEWMODULE doesn't work

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

I agree with Justin. Surely the new plugin you are wanting to create is similar to an already existing plugin (either in Moodle core or one of the many add-ons in the plugins repository).

For me, the best strategy has always been to not start from scratch but to find an existing plugin similar to what I wanted to create and adapt it to my needs.

Unless you are developing a "top secret" plugin thoughtful, it might help us help you if you described here what you actually want to achieve.

Joseph

In reply to Joseph Rézeau

Re: problem - NEWMODULE doesn't work

by L M -

Hi,


thank you very very much for your answers! Sorry for answering so late. I had lots to do.

@Marcus Green and Joseph Rézeau: I’m sure that I haven’t enough know how to create a new one on my own wink.
But it is a very simple and brilliant idea to take an existing 2.5-module as a pattern!
I don’t have a special aim for my module. I just want to get in touch with it and learn more about moodle modules. A simple “Hello World” would be nice for the beginning.

I tried to create a new module with moodle 1.9 -> no problem!

@Justin Hunt: I tried all three templates, but I never changed the version-number. Thanks! I didn’t know these consequences! I used notepad++ for renaming, so I hope there isn’t such a mistake.

So I started a new try: template for 2.x and with the changed version number -> after clicking on notifications I got this error message:
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\moodledata25\lang\de\admin.php on line 26”

Line 26: “defined('MOODLE_INTERNAL') || die();”

I don’t know what this code is for.

After this, I also resume the moodle version number. Now I have the problem with this function again (attachment).
(“Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\moodle25\lib\filelib.php on line 3291”)

@Davo Smith: I have turned on the debugging. I can’t say, what the exactly error message was. There were many different errors (fatal errors on a blank site).

In reply to L M

Re: problem - NEWMODULE doesn't work

by L M -

sorry -> missing screenshot

Attachment 04.JPG
In reply to L M

Re: problem - NEWMODULE doesn't work

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

It is hard to say specifically what the cause of the timeout errors is. I know installing plugins can take Moodle a while, though I don't know why. So perhaps it is just as the error says, and you need to increase your PHP max execution time.

To do that, find your php.ini and set

max_execution_time = 300

(it is probably set to 30 now)

Xampp probably has a shortcut to the php.ini somewhere so that would be the best way to find php.ini on your machine. You will need to restart Apache after making the change. 

Average of ratings: Useful (1)
In reply to Justin Hunt

Re: problem - NEWMODULE doesn't work

by L M -

It works!

Thank you VERY VERY VERY much! I can't believe, that the short execution time was my problem. Wow... Thanks, Justin Hunt and all the others!