tjhunt [Mon, 30 Mar 2009 08:33:13 +0000 (08:33 +0000)]
filters: MDL-17684 Look for the filter name in filter_myfilter.php first.
This makes filters more plugginable, becuase with this lang file name, get_string will look for the filter name in filter/myfilter/lang/en_utf8/filter_myfilter.php.
To do this, there is a new function filter_get_name in filterlib that contains the logic.
Also, a new function filter_get_all_installed to replace the logic for getting all filters that was duplicated in three places.
filter_get_name no longer does such a nice fall-back if the name is missing, to encourage people to supply the right string. The fallback now looks like '[[filtername]] (filter/tidy)'.
tjhunt [Mon, 30 Mar 2009 02:21:27 +0000 (02:21 +0000)]
get_string: Refactoring, performance improvements, bug fixes and unit tests
MDL-18669 get_string refactored to elimiate duplicate code and make it easier to understand.
MDL-17763 parent language not processed correctly when getting a plugin string.
MDL-16181 more intelligent caching to avoid repeated file_exists checks.
MDL-12434 move values to array keys to improve lookup times.
The main part of the refactoring is to create a singleton string_manager class to encapsulate the cached data and the processing, while breaking the code up into more smaller methods.
Other performance improvements include:
* Cache results of plugin name -> locations to search array.
* Cache parent lang lookup.
* Skip eval if the string does not contain $ \ or %.
* Remove the unnecessary sprintf from the eval.
There is a performance testing script in lib/simpletest/getstringperformancetester.php. For now this script has the old get_string implementation copied and pasted to the end, and renamed to old_get_string to allow for comparitive timings.
There are now some unit tests for get_string in lib/simpletest/teststringmanager.php. I think I have managed to cover most of the tricky cases.
fmarier [Fri, 27 Mar 2009 03:21:10 +0000 (03:21 +0000)]
mod/resource: MDL-18691 allow custom resource types to specify their name in their own lang directory
Before this change, the full name of the resource type had to be stored in the "resource" namespace (for example in /mod/resource/lang/en_utf8/resource.php).
Now it can be put in the "resource_foo" namespace:
e.g. in /mod/resource/type/foo/lang/en_utf8/resource_foo.php:
<?php
$string['resourcetypefoo'] = 'Link to a Foo Bar document';
?>
dongsheng [Thu, 26 Mar 2009 08:56:08 +0000 (08:56 +0000)]
"ADMINLIB/MDL-17966, overwrite write_setting to update settings instead execute sql execute in get_settings, this will not hurt performance, merged from 1.9"
dongsheng [Thu, 26 Mar 2009 02:09:28 +0000 (02:09 +0000)]
"MEMORY/MDL-18540,remove hard-coded php memory limit, added system setting for it, create a function reduce_memory_limit to reduce memroy limit and respect php.ini setting in the meanwhile, merged from 1.9"
tjhunt [Mon, 23 Mar 2009 08:15:21 +0000 (08:15 +0000)]
switch roles: MDL-18132 separate database table role_allow_switch instead of re-using role_allow_assign.
This is part 1 that does the back-end:
1. New table role_allow_switch.
2. Upgrade that copies all the allows from role_allow_assign, and then drops the old CFG->allowuserswitchrolestheycantassign.
3. Old function get_assignable_roles_for_switchrole renamed to get_switchable_roles and changed to use the new table. Fixes MDL-18604 in HEAD.
4. Switch callers to use the new function name.
5. Unit tests for this new function.
6. To make those unit tests work, new switch_global_user_id and revert_global_user_id methods in UnitTestCaseUsingDatabase for toggling $USER->id.
I still need to do the editing interface under Administration ► Users ► Permissions ► Define roles. That will be done as a second commit.
tjhunt [Mon, 23 Mar 2009 04:12:37 +0000 (04:12 +0000)]
unit tests: MDL-18607 new way to do unit tests involving the database.
This is not as ambitious as the abortive FakeDBUnitTests scheme, but this one works for simple cases.
There is a new test case class UnitTestCaseUsingDatabase to inherit from. I hope it is sufficiently well documented in its PHPdocs.
* It users $CFG->unittestprefix.
* You can access that database using $this->testdb.
* That database is empty by default, you have to call create_test_table to create the ones you want, and drop_test_table to clean them up in the end. The table definitions are read from the XMLDB file.
* When you are ready to call real Moodle code that users $DB, call switch_to_test_db and then revert_to_real_db when you are done.
* If you forget to call drop_test_table or switch_to_test_db, the class will attempt to clean up after you, but will also print rude developer debug messages telling you not to be stupid.
* There is also a load_test_data method for populating a table from an array.
The is an example of its use in lib/simpletest/testunittestusingdb.php.
tjhunt [Mon, 23 Mar 2009 03:54:50 +0000 (03:54 +0000)]
accesslib: MDL-18620 do not used static to cache things, it makes unit testing impossible.
Instead we have a new $ACCESSLIB_PRIVATE for all caching. Regrettably, the only way to make this work in PHP (other than rewriting everything to be methods of a class rather than functions) is to make this a global variable. However $ACCESSLIB_PRIVATE should not be thought of a global, it is a private implementation detail of accesslib.php. (And there is a comment saying that.)
There is a new function accesslib_clear_all_caches_for_unit_testing(). In a unit test, you need to call this at the start of your test method, before you set up any test data, and again at the end, after you have discarded all your test data.
This new $ACCESSLIB_PRIVATE subsumes the old $ACCESS, $RDEFS and $DITRYCONTEXTS globals.
Also, I took the opportunity to refactor the (inconsistently) duplicated code for adding a context to the caches code into a cache_context function.
tjhunt [Mon, 23 Mar 2009 01:59:30 +0000 (01:59 +0000)]
quiz: MDL-18635 log every single hit to mod/quiz/attempts.php
I don't know why the quiz only logged every 10 minutes. No other part of Moodle worked like that. However, it has always been like that and I did not have a good reason to change it until now.
What was a problem becuase it made it harder to catch people doing a primitive DOS attack against the server by hitting Reload repeatedly.