]> git.mjollnir.org Git - moodle.git/log
moodle.git
17 years agoaccesslib: get_user_access_bycontext() fetches all relevant rdefs
martinlanghoff [Wed, 19 Sep 2007 07:53:49 +0000 (07:53 +0000)]
accesslib: get_user_access_bycontext() fetches all relevant rdefs

get_user_access_bycontext() was narrowing down too much the rdefs it
was fetching. With this patch, it now correctly retrieves the rdefs for
new roles assigned in lower contexts, and also correctly retrieves
rdefs present in the course context (fixing MDL-11220).

This also means that we now do the job in 2 DB queries (instead of 3),
and we move a bit more data, but those rows are actually needed ;-)

17 years agocalendar/lib: calendar_set_filters() use pre-fetched context and course recs
martinlanghoff [Wed, 19 Sep 2007 07:53:33 +0000 (07:53 +0000)]
calendar/lib: calendar_set_filters() use pre-fetched context and course recs

Showing the calendar block was causing 2 DB queries per course the
user is enrolled in. Instead, use the data available in the array that
is passed as a parameter, and spare the DB a ton of needless traffic.

Fixes MDL-11221 Calendar not using context stuff from get_my_courses

Author: Martin Dougiamas

17 years agocourse/index: remove call to rebuild_context_rel()
martinlanghoff [Wed, 19 Sep 2007 07:53:17 +0000 (07:53 +0000)]
course/index: remove call to rebuild_context_rel()

Very last caller to rebuild_context_rel() and any XX_context_rel()
function. move_category() already takes care of calling
context_moved(), which does the required context.path maintenance.

Addresses MDL-11219

17 years agoaccesslib upgrade: remove stray build_context_rel(), force path rebuild
martinlanghoff [Wed, 19 Sep 2007 07:53:00 +0000 (07:53 +0000)]
accesslib upgrade: remove stray build_context_rel(), force path rebuild

Fixes problems during upgrades from 1.7x/1.8.x to mdl19-perf.

17 years agoweblib: build_navigation() try to avoid pointless capchecks
martinlanghoff [Wed, 19 Sep 2007 07:52:42 +0000 (07:52 +0000)]
weblib: build_navigation() try to avoid pointless capchecks

Prevent calls to has_capability() in build_navigation() from messing
with upgrades.

Most calls to has_capability() in weblib should be moved to the callers.

17 years agocourse/lib: print_course() fix bug when $course->managers was not set
martinlanghoff [Wed, 19 Sep 2007 07:52:27 +0000 (07:52 +0000)]
course/lib: print_course() fix bug when $course->managers was not set

Fix a thinko in a variable assignment that prevented us from grabbing
the correct roles as managers. Addresses Yu's report at
MDL-11182 admin shows up as teacher.

17 years agoaccesslib: has_cap_fad() respect local-context-wins permissions rule
martinlanghoff [Wed, 19 Sep 2007 07:52:06 +0000 (07:52 +0000)]
accesslib: has_cap_fad() respect local-context-wins permissions rule

The initial implementation of has_cap_fad() just added the permission
values regardless of the locality of the context. This patch adds
support (read: fixes bug) for the "local context wins" rule.

Additionally, it removes a related bug where we were exiting early
if we found a CAP_PROHIBIT, ignoring the $doanything flag.

17 years agocourse/lib: print_my_moodle() - ask get_my_courses() for the summary
martinlanghoff [Wed, 19 Sep 2007 07:51:50 +0000 (07:51 +0000)]
course/lib: print_my_moodle() - ask get_my_courses() for the summary

get_my_courses() now defaults to a much leaner dataset, but accepts an
array of "additional" fields we want. So ask nicely for the summary,
so that we can print_course() later with it.

17 years agodatalib: get_my_courses() honour $fields array
martinlanghoff [Wed, 19 Sep 2007 07:51:36 +0000 (07:51 +0000)]
datalib: get_my_courses() honour $fields array

If the caller passes a fields array, then merge it as we say we will do.

17 years agoaccesslib: get_my_courses() fix when called when empty sort
martinlanghoff [Wed, 19 Sep 2007 07:51:19 +0000 (07:51 +0000)]
accesslib: get_my_courses() fix when called when empty sort

get_my_courses() was failing if called with an empty sortorder on a
cached courselist. Fix.

17 years agoindex.php: drop unused $hidesitecourse parameter when calling print_courses()
martinlanghoff [Wed, 19 Sep 2007 07:51:02 +0000 (07:51 +0000)]
index.php: drop unused $hidesitecourse parameter when calling print_courses()

And this is the only user of print_courses() that mentions it
explicitly. Other callers have been checked and don't need or use the
sitecourse.

17 years agocourse/lib: print_courses() drop $hidesitecourse parameter
martinlanghoff [Wed, 19 Sep 2007 07:50:41 +0000 (07:50 +0000)]
course/lib: print_courses() drop $hidesitecourse parameter

The $hidesitecourse and related code seem to be dead code. An audit of
the callers did not turn up any interesting/valid use of it.

17 years agoRevert "course/lib: print_courses() - no need to worry about sitecourse"
martinlanghoff [Wed, 19 Sep 2007 07:50:28 +0000 (07:50 +0000)]
Revert "course/lib: print_courses() - no need to worry about sitecourse"

This reverts commit d7816749a4ceda352a2fac6e82d7f02f435473ed.

17 years agoaccesslib - Ensure newly-created categories have a context
martinlanghoff [Wed, 19 Sep 2007 07:50:05 +0000 (07:50 +0000)]
accesslib - Ensure newly-created categories have a context

New categories need a context immediately, and for top-level
categories, they also need to taint the "root" context to trigger
a reload of $USER->access.

This fixes problems with creation of initial courses(MDL-11178),
duplicate misc categories, etc.

17 years agoRevert "textlib: Don't require_once() class.t3lib_div.php which we never use"
martinlanghoff [Wed, 19 Sep 2007 07:49:49 +0000 (07:49 +0000)]
Revert "textlib: Don't require_once() class.t3lib_div.php which we never use"

Turns out class.t3lib_cs.php depends on class.t3lib_div.php. Will drop
the two commits before we go into HEAD.

This reverts commit 5768bf6fb4dfa334dc81a80d26111904c4d13abd.

17 years agoaccesslib: get_user_access_bycontext() remove 2 unused var declarations (trivial)
martinlanghoff [Wed, 19 Sep 2007 07:49:35 +0000 (07:49 +0000)]
accesslib: get_user_access_bycontext() remove 2 unused var declarations (trivial)

17 years agocourse/lib: print_courses() - no need to worry about sitecourse
martinlanghoff [Wed, 19 Sep 2007 07:49:23 +0000 (07:49 +0000)]
course/lib: print_courses() - no need to worry about sitecourse

get_courses_wmanagers() excludes the sitecourse, so we no longer
check for it. And check explicitly for an empty course array.

17 years agodatalib: get_courses_wmanagers() exclude the sitecourse
martinlanghoff [Wed, 19 Sep 2007 07:49:10 +0000 (07:49 +0000)]
datalib: get_courses_wmanagers() exclude the sitecourse

Should never return the sitecourse - so we exclude it explicitly.

17 years agocourse/index: Bring back Petr's MDL-9647 simplify dealing with headers/footers in...
martinlanghoff [Wed, 19 Sep 2007 07:48:56 +0000 (07:48 +0000)]
course/index: Bring back Petr's MDL-9647 simplify dealing with headers/footers in admin sections

I had mistakenly reverted some of Petr's changes.

Fixes MDL-11179 19PERF: Notice on /course/index.php as admin

17 years agoaccesslib: is_siteadmin() bugfixes
martinlanghoff [Wed, 19 Sep 2007 07:48:43 +0000 (07:48 +0000)]
accesslib: is_siteadmin() bugfixes

Fixed two horrid bugs in is_siteadmin(). Both userid and the check for
matching cpabilities lines were wrong.

17 years agoaccesslib: fix SQL CAST()s to work on MySQL and PostgreSQL
martinlanghoff [Wed, 19 Sep 2007 07:48:31 +0000 (07:48 +0000)]
accesslib: fix SQL CAST()s to work on MySQL and PostgreSQL

CAST() target types aren't very portable. Use DECIMAL which works
for MySQL and Pg.

DECIMAL does seem to be supported in Oracle - but the syntax seems
different. We may still need a compat function.

17 years agoaccesslib: remove has_capability_including_child_contexts()
martinlanghoff [Wed, 19 Sep 2007 07:48:19 +0000 (07:48 +0000)]
accesslib: remove has_capability_including_child_contexts()

No code is calling it, and it never appeared in any release.

17 years agomoodlelib: isediting() uses $PAGE->user_allowed_editing(), drop editcourseallowed()
martinlanghoff [Wed, 19 Sep 2007 07:48:03 +0000 (07:48 +0000)]
moodlelib: isediting() uses $PAGE->user_allowed_editing(), drop editcourseallowed()

With this commit, isediting() checks with the page if the user is
allowed editing. And as the last caller of editcourseallowed() is gone,
remove it.

17 years agoindex: use $PAGE->edit_course_allowed() instead of editcourseallowed()
martinlanghoff [Wed, 19 Sep 2007 07:47:49 +0000 (07:47 +0000)]
index: use $PAGE->edit_course_allowed() instead of editcourseallowed()

$PAGE->edit_course_allowed() has been reworked and is faster/smarter
than editcourseallowed(). It can also be made more specific on a
per-page-type basis.

17 years agoblocks/admin_tree: applicable_formats() is called as a class method
martinlanghoff [Wed, 19 Sep 2007 07:47:38 +0000 (07:47 +0000)]
blocks/admin_tree: applicable_formats() is called as a class method

Can't find it documented anywhere, but applicable_formats() is only
ever called as a class method, so it cannot say $this. Instead, say
block_admin_tree::has_admin_caps().

17 years agoRevert "datalib: Introducing sql_intarray_to_in()"
martinlanghoff [Wed, 19 Sep 2007 07:47:26 +0000 (07:47 +0000)]
Revert "datalib: Introducing sql_intarray_to_in()"

We don't need sql_intarray_to_in(), use implode() instead.

This reverts commit 3ef7fc54d9df780c837c64a8ace1fc565d6d7744.

17 years agoaccesslib: replace join() and sql_intarray_to_in() with implode()
martinlanghoff [Wed, 19 Sep 2007 07:47:11 +0000 (07:47 +0000)]
accesslib: replace join() and sql_intarray_to_in() with implode()

implode() is the PHP-ish way of saying this. join() is too Perlish and
may get confused (or misgrepped) with a SQL JOIN.

17 years agotextlib: Don't require_once() class.t3lib_div.php which we never use
martinlanghoff [Wed, 19 Sep 2007 07:46:54 +0000 (07:46 +0000)]
textlib: Don't require_once() class.t3lib_div.php which we never use

The largest of the 2 typo3 libs we ship in Moodle is never used. So
don't even parse it.

This takes Moodle's "default homepage" from 1.8MB to 1.6MB of PHP.
Tiny, but every bit helps...

17 years agomoodlelib: moodle_request_shutdown() prints included files
martinlanghoff [Wed, 19 Sep 2007 07:46:39 +0000 (07:46 +0000)]
moodlelib: moodle_request_shutdown() prints included files

If MDL_PERFINC is defined, we now print to errorlog a listing
of the files included, their size, and then a total size.

The total size isn't the most important metric, though it does give us
a good idea of how much PHP the PHP engine is parsing for us. The main
cost is still in the seeks involved.

Even when using precompilers -- our best-case scenario -- each include
or require forces at least 2 stat()s to compare timestamps in the php
file vs the precompiled file. If the working set fits in buffers we are
fine, but our 60+ stat() calls per page is quite a bit.

17 years agoblocks/admin_tree: Show the block if some admin privs present...
martinlanghoff [Wed, 19 Sep 2007 07:46:24 +0000 (07:46 +0000)]
blocks/admin_tree: Show the block if some admin privs present...

Dan Poltawski said:
> Previously users with different permissions could have granular
> access to the admin menu for the items they have access to, so
> limiting to only users with moodle/site:config would break that.
> Although I agree that that menu is slowww to render and needs
> fixing. Perhaps permissions for the various elements could be
> gathered and checked first

This commit addresses the problem checking for all the caps that are
mentioned by code in /admin (according to grep, at least). Some light
testing with the "moodle/user:create" seems to work properly.

This burdens us with maintaining the list in has_admin_caps() -- less
than ideal, but easier than rewriting /admin.

17 years agoaccesslib upgrade: admin/upgradesettings may need to load_all_capabilities()
martinlanghoff [Wed, 19 Sep 2007 07:46:12 +0000 (07:46 +0000)]
accesslib upgrade: admin/upgradesettings may need to load_all_capabilities()

This shouldn't happen, but sometimes admin/upgradesettings needs to
reload_all_capabilities(). So do it.

17 years agoaccesslib 1.9 upgrade: homepage check to see if we need to upgrade
martinlanghoff [Wed, 19 Sep 2007 07:45:45 +0000 (07:45 +0000)]
accesslib 1.9 upgrade: homepage check to see if we need to upgrade

This check adds a DB query _only when the upgrade is pending_. So
for a few minutes at the most.

17 years agoaccesslib rework: Upgrade block to populate context.path and friends
martinlanghoff [Wed, 19 Sep 2007 07:42:42 +0000 (07:42 +0000)]
accesslib rework: Upgrade block to populate context.path and friends

Note: this upgrade changes how accesslib works.

17 years agoaccesslib: Introducing is_siteadmin() to reliably check for siteadmins
martinlanghoff [Wed, 19 Sep 2007 07:30:09 +0000 (07:30 +0000)]
accesslib: Introducing is_siteadmin() to reliably check for siteadmins

is_siteadmin checks a few key capabilities to suss out if the user is
an admin. The main virtue of the function is that it does not use
the accesslib infrastructure -- it reads directly from the DB, which
is useful for the 1.9 accesslib upgrade.

17 years agoadmin/index: Populate the context path JIT for the new admin user
martinlanghoff [Wed, 19 Sep 2007 07:29:55 +0000 (07:29 +0000)]
admin/index: Populate the context path JIT for the new admin user

With this call to build_context_path() the admin rights of the new
user are loaded just before they are first needed.

17 years agoaccesslib: get_user_courses_bycap() fix to deal with empty $order
martinlanghoff [Wed, 19 Sep 2007 07:29:43 +0000 (07:29 +0000)]
accesslib: get_user_courses_bycap() fix to deal with empty $order

If we are passed an empty string for $order, still create valid
SQL. Some callers in 1.9 seem to not care about order, passing
an explicit ''. Shocking! ;-)

17 years agoaccesslib: remove references to deprecated context_rel table and insert_context_rel()
martinlanghoff [Wed, 19 Sep 2007 07:29:31 +0000 (07:29 +0000)]
accesslib: remove references to deprecated context_rel table and insert_context_rel()

These references to the deprecated functions were erroring out. Remove
them.

Note however that other role related cleanups done as part of
MDL-10679 "improvement to context_rel table and load_user_capability()"
are kept.

17 years agoadmin/cron: move accesslib stuff to occasional cleanups, add build_context_path()
martinlanghoff [Wed, 19 Sep 2007 07:29:20 +0000 (07:29 +0000)]
admin/cron: move accesslib stuff to occasional cleanups, add build_context_path()

The accesslib cleanups aren't needed every 5. Also, add
build_context_path() and instructions on how to run it
as build_context_path(true) to force a path rebuild.

17 years agoaccesslib: build_context_path() is now much much cheaper
martinlanghoff [Wed, 19 Sep 2007 07:29:07 +0000 (07:29 +0000)]
accesslib: build_context_path() is now much much cheaper

We now populate the context.path only where it's empty,
this means that we take 0.15s instead of 0.6s. More importantly,
we avoid thrashing the DB's indexes pointlessly.

We also support Oracle and its dirty hack here.

And the function now has a $force parameter that can be used to
actually overwrite the paths/depths in case they've been corrupted.

17 years agobackup/restore_form.html: tiny XHTML compliance fix
martinlanghoff [Wed, 19 Sep 2007 07:28:54 +0000 (07:28 +0000)]
backup/restore_form.html: tiny XHTML compliance fix

There is something _weird_ about the table setup on this page
and I cannot figure it out. This change "fixes" it in that
FF stops complaining.

However, the fix looks very broken to me.

17 years agodatalib: get_categories() - remove PostgreSQL-ism
martinlanghoff [Wed, 19 Sep 2007 07:28:43 +0000 (07:28 +0000)]
datalib: get_categories() - remove PostgreSQL-ism

17 years agoaccesslib: Use sql_compat() to remove unportable PostgreSQL-isms
martinlanghoff [Wed, 19 Sep 2007 07:28:31 +0000 (07:28 +0000)]
accesslib: Use sql_compat() to remove unportable PostgreSQL-isms

17 years agoaccesslib: get_assignable_roles() reworked to be constant-queries
martinlanghoff [Wed, 19 Sep 2007 07:27:46 +0000 (07:27 +0000)]
accesslib: get_assignable_roles() reworked to be constant-queries

get_assignable_roles() was calling user_can_assign() (cost of 1~2 DBq)
once-per-role. Instead, we can do a single DB query that answers
all our questions in one go.

On a Moodle w 8 roles defined, saves 19 DB queries for the course page
for teachers/admins.

NOTE NOTE NOTE! With this patch we drop the insane strip/escape bit.
Only the caller knows if this is for display on html or for other uses,
so we'll be true and not mangle the data.

A review of all callers in 1.8 shows no problem - the strings were being
strip/escaped already.

17 years agocourse/index: minor context-related fixes
martinlanghoff [Wed, 19 Sep 2007 07:27:31 +0000 (07:27 +0000)]
course/index: minor context-related fixes

 - The code uses the system context a lot. Declare
   $sysctx at the top and use it.

 - If the category has a context property, use it
   (saves 1 DB query per category displayed)

The DB costs of this page in editing mode are

 - ~100 DB queries for fix_course_sortorder()

 - ~50 DB queries for the categories listing

If we rewrite both to lose the recursion, we could resolve the
page in perhaps 5 DBq.

17 years agodatalib: get_categories() returns context, supports !shallow
martinlanghoff [Wed, 19 Sep 2007 07:27:20 +0000 (07:27 +0000)]
datalib: get_categories() returns context, supports !shallow

With this patch, get_categories() now adds a nice context
sub-object to the returned object, which means callers can
save DB traffic.

It now also supports "deep" retrievals, which means we can
rewrite the course categories display pages to avoid
costly recursion.

17 years agodatalib: fix_course_sortorder() - minor optimisation
martinlanghoff [Wed, 19 Sep 2007 07:27:08 +0000 (07:27 +0000)]
datalib: fix_course_sortorder() - minor optimisation

Don't update fields unnecessarily. Cuts 3 DB queries per category
on course/index page (45 in a 15 category setup).

fix_course_sortorder() should be fixed to avoid recursion.

17 years agocourse/lib: print_courses() and print_course() rework
martinlanghoff [Wed, 19 Sep 2007 07:26:54 +0000 (07:26 +0000)]
course/lib: print_courses() and print_course() rework

print_course() can now recognise a $course object that already has a
$course->context obj and a $course->managers array, which means that
there will be no DB access triggered by print_course().

(Backwards compat is retained so it still works the old way for
callers that get a single course printed anyway (during enrolment
for example.)

And print_courses() now uses get_courses_wmanagers(), and passes the
returned $course objects to print_course().

With this patch, a homepage listing 9 courses (with varying numbers of
teachers) sheds 63 DB queries (88 to 25). A course listing page with
3 courses sheds 9 (33 to 24).

On a single server overall time spent serving the homepage is reduced just
a little bit (262ms to 238ms) -- on a clustered environment, less DB queries
mean much lower latency and DB costs.

17 years agodatalib: Introducing get_courses_wmanagers() for print_courses() usage
martinlanghoff [Wed, 19 Sep 2007 07:26:42 +0000 (07:26 +0000)]
datalib: Introducing get_courses_wmanagers() for print_courses() usage

For an efficient print_courses() we need to grab in a constant number
of queries...

 - course data
 - "course manager" role assignments
 - user records for the coursemanagers' fullname()

So here we do it in 2 DB queries. The 2nd one (grabbing RAs and user
records) can be expensive if we are dealing with a large number of
courses.

Which we shouldn't - When the number of courses is large the course
listing doesn't come this way anyway...

17 years agocourse/lib: print_course() bugfix when $rusers is empty
martinlanghoff [Wed, 19 Sep 2007 07:26:27 +0000 (07:26 +0000)]
course/lib: print_course() bugfix when $rusers is empty

17 years agoaccesslib: get_parent_contexts() bugfix
martinlanghoff [Wed, 19 Sep 2007 07:26:15 +0000 (07:26 +0000)]
accesslib: get_parent_contexts() bugfix

17 years agoaccesslib: has_capability() now loads sub-course accessdata for $ACCESS
martinlanghoff [Wed, 19 Sep 2007 07:26:02 +0000 (07:26 +0000)]
accesslib: has_capability() now loads sub-course accessdata for $ACCESS

When querying capabilities of non-logged-in users, has_capability()
will now load accessdata for the subcontexts as needed.

Without this patch, below-the-course RAs and rdefs were ignored when
checking caps for a user different from $USER. I don't think it is
ever done in current moodle code, so the problem wasn't visible.

In any case - it's fixed ;-)

17 years agomoodlelib: require_login() rework
martinlanghoff [Wed, 19 Sep 2007 07:25:49 +0000 (07:25 +0000)]
moodlelib: require_login() rework

A bit of rework around require_login()

 - Fixed a subtle bug in the check whether a user can see sitecourse
   hidden activities

 - Save 1 DBq and 2 includes per call by only calling
   get_auth_plugin() only when needed.

 - Grab the contexts we are interested in only once and keep them in
   variables.

17 years agoaccesslib: Fix dirty paths checks on PHPv4
martinlanghoff [Wed, 19 Sep 2007 07:25:37 +0000 (07:25 +0000)]
accesslib: Fix dirty paths checks on PHPv4

$DIRTYPATHS and its derivatives are all arrays. Not objects.

Drop the silly -> notation.

17 years agoaccesslib: phpdoc update get_child_contexts()
martinlanghoff [Wed, 19 Sep 2007 07:25:25 +0000 (07:25 +0000)]
accesslib: phpdoc update get_child_contexts()

17 years agoaccesslib: rm get_role_context_capability() and update phpdoc
martinlanghoff [Wed, 19 Sep 2007 07:25:10 +0000 (07:25 +0000)]
accesslib: rm get_role_context_capability() and update phpdoc

Remove unused function.

17 years agoaccesslib: remove role_add_lastaccess_entries(),role_remove_lastaccess_entries()
martinlanghoff [Wed, 19 Sep 2007 07:24:57 +0000 (07:24 +0000)]
accesslib: remove role_add_lastaccess_entries(),role_remove_lastaccess_entries()

Both of them are dead code in 18_STABLE and HEAD. And if
role_add_lastaccess_entries() is ever used on a large site it will
hammer the DB to bits.

Remove before anyone is foolish enough to try it.

17 years agoaccesslib: require_capability() phpdoc notes
martinlanghoff [Wed, 19 Sep 2007 07:24:43 +0000 (07:24 +0000)]
accesslib: require_capability() phpdoc notes

17 years agoaccesslib: get_parent_cats() goes away too...
martinlanghoff [Wed, 19 Sep 2007 07:24:26 +0000 (07:24 +0000)]
accesslib: get_parent_cats() goes away too...

Not used anymore, and very inefficient.

If you need something like it, use course_category.path
just like we use context.path .

17 years agoaccesslib: remove get_role_caps() merge_role_caps()
martinlanghoff [Wed, 19 Sep 2007 07:24:14 +0000 (07:24 +0000)]
accesslib: remove get_role_caps() merge_role_caps()

Both unused, and not part of the external API.

17 years agoaccesslib: remove validate_context()
martinlanghoff [Wed, 19 Sep 2007 07:24:02 +0000 (07:24 +0000)]
accesslib: remove validate_context()

No longer used anywhere. Not really useful outside of accesslib, so no
point in keeping it.

17 years agoaccesslib: get_context_instance() - ignore clearcache
martinlanghoff [Wed, 19 Sep 2007 07:23:41 +0000 (07:23 +0000)]
accesslib: get_context_instance() - ignore clearcache

"cleacache" is no longer needed, and nothing is calling it.

Still - handle it as a noop to avoid erroring out with custom/contrib
code.

17 years agoaccesslib: get_parent_contexts() reworked to use context.path
martinlanghoff [Wed, 19 Sep 2007 07:23:30 +0000 (07:23 +0000)]
accesslib: get_parent_contexts() reworked to use context.path

Now that we can use $context->path trivially, and avoid touching the db
for data we already have... Just Do It!

17 years agoaccesslib: remove insert_context_rel(), build_context_rel() and others
martinlanghoff [Wed, 19 Sep 2007 07:23:15 +0000 (07:23 +0000)]
accesslib: remove insert_context_rel(), build_context_rel() and others

The context_rel table is not used anymore. Get rid of all references
to it.

TODO: Drop the orphaned table - but we'll do that on HEAD.

17 years agoaccesslib: mark_context_dirty() - fix race condition
martinlanghoff [Wed, 19 Sep 2007 07:23:01 +0000 (07:23 +0000)]
accesslib: mark_context_dirty() - fix race condition

We had a 1s race condition where a user could get their rights loaded
at the exact time an admin is changing roles/caps and see the "old"
data. Or even see a half-updated view of the access controls.

Yuck.

So we fix the race condition backdating the dirtyness. Cheap, but
effective. And then we backdate it some more to cover for minor clock
flutter on clusters (you still need ntp however!).

17 years agoaccesslib: mark_context_dirty() don't mark it there is no path
martinlanghoff [Wed, 19 Sep 2007 07:22:49 +0000 (07:22 +0000)]
accesslib: mark_context_dirty() don't mark it there is no path

17 years agodatalib: add_to_log() fix a bug and better error handling
martinlanghoff [Wed, 19 Sep 2007 07:22:37 +0000 (07:22 +0000)]
datalib: add_to_log() fix a bug and better error handling

All the $db->Execute calls now do proper err handling, and send their
message to debugging().

17 years agoblocks/admin_tree: exit early for non-admins
martinlanghoff [Wed, 19 Sep 2007 07:22:24 +0000 (07:22 +0000)]
blocks/admin_tree: exit early for non-admins

Saves >10DBq and 18 includes at the homepage for all nonadmin users.
For non admin users, this makes the homepage _much_ more lightweight.

  Before: inc 101  DBq 51 time 1.2s
  After:  inc  76  DBq 36 time 0.2s

So this commit shaves 1 full second for the non-logged-in homepage.

Still pretty bad on the includes, but shaved a good 25 files and 15 DBqs.

17 years agoaccesslib: get_user_access_sitewide() fix invalid SQL for users without RAs
martinlanghoff [Wed, 19 Sep 2007 07:22:12 +0000 (07:22 +0000)]
accesslib: get_user_access_sitewide() fix invalid SQL for users without RAs

17 years agodatalib: get_admin() - cache in a static var
martinlanghoff [Wed, 19 Sep 2007 07:22:01 +0000 (07:22 +0000)]
datalib: get_admin() - cache in a static var

get_admin is called a zillion times during cron, and is a tiny
bit of data we can safely keep around... so...

(shaves 2 queries per email we send!)

17 years agouser/view: show user courses that are hidden, with dimmed class
martinlanghoff [Wed, 19 Sep 2007 07:21:47 +0000 (07:21 +0000)]
user/view: show user courses that are hidden, with dimmed class

If the $USER can see them, there is no reason to hide courses that
may be hidden. But show them dimmed to indicate so.

17 years agodatalib: get_my_courses() now returns invisible courses if visible to $USER
martinlanghoff [Wed, 19 Sep 2007 07:21:35 +0000 (07:21 +0000)]
datalib: get_my_courses() now returns invisible courses if visible to $USER

So admins can see the appropriate user listing in the profile page.

In fact, probably _all_ the visibility checks should be done by callers.
Hmmm...

17 years agoaccesslib: has_capability() - fix warnings about FULLME constant
martinlanghoff [Wed, 19 Sep 2007 07:21:23 +0000 (07:21 +0000)]
accesslib: has_capability() - fix warnings about FULLME constant

17 years agomod/chat: chat_update_chat_times() smarter
martinlanghoff [Wed, 19 Sep 2007 07:21:09 +0000 (07:21 +0000)]
mod/chat: chat_update_chat_times() smarter

If cron hasn't run for a few days, it would take
several runs for chat_update_chat_times() to get things back on track.

Now it's all fixed in one go, saving a bit of DB traffic. It all adds
up...

17 years agomod/chat: reduce number of queries in cron.
martinlanghoff [Wed, 19 Sep 2007 07:20:52 +0000 (07:20 +0000)]
mod/chat: reduce number of queries in cron.

Delete stale msgs in one DB query rather than in 1-per-chat-instance.

(From 600 DB queries to 1 on a site with 600 chat instances.)

Also - a walkthrough of chat_update_chat_times(), which seems buggy.

17 years agoaccesslib: has_capability() now supports fake $USER for forum cron
martinlanghoff [Wed, 19 Sep 2007 07:20:24 +0000 (07:20 +0000)]
accesslib: has_capability() now supports fake $USER for forum cron

has_capability() can handle the fake user that forum cron sets up
and will load the appropriate accessdata into $USER->access.

This makes forum cron work again. A test comparison between before
this patchseries yields:

With 1 forum post, sent total 24 times
 - Before 11 000 DB queries (approx)
 - After     506 DB queries

With 6 forum posts, sent a total of 452 times
 - Before 47 876 DB queries
 - After   8 256 DB queries

There is a very high variability, but we are going from 100-500
queries per sent email to 18-21 queries per sent email. The
variability probably stems from 2 of the 6 posts being in a 200-user
forum.

Still huge - by the time we are sending the email, we should know
everything we need to know about the user, the forum/thread/post and
the form. The average should be well below 1 DB query per email sent!

17 years agouser/index: make use of the smarter print_user_picture() -
martinlanghoff [Wed, 19 Sep 2007 07:20:01 +0000 (07:20 +0000)]
user/index: make use of the smarter print_user_picture() -

Switch to using the smarter codepath in print_user_picture. Saves
20 DB queries in the normal page. One per user acct.

17 years agocourse/participants: fix sort order when last access is null
martinlanghoff [Wed, 19 Sep 2007 07:19:46 +0000 (07:19 +0000)]
course/participants: fix sort order when last access is null

17 years agoweblib: print_user()/print_user_picture() optimisations
martinlanghoff [Wed, 19 Sep 2007 07:19:35 +0000 (07:19 +0000)]
weblib: print_user()/print_user_picture() optimisations

print_user_picture() was forcing an unneeded dbquery
if you need an imagealt. And who doesn't need one these days.

So - teach print_user_picture() to take either $userid
_or_ $userobj as the first parameter. If that first
parameter has the fields we need, never touch the db.

In other words, only touch the DB as a last resort.

There is a bit of ugliness in testing whether we have
the fields or not, because these fields are inconsistently
with/without NOT NULL in the DB definitions. So we cannot
use isset() because it barfs on nulls. And we cannot use empty()
because it will match both on "missing key" and ''.

And while at it, silence warnings that we are missing string
for the year(s). Also fixes a missing string bug in really boring
courses that noone's visitied in many years ;-)

17 years agomoodlelib: require_login() - rework course/category visibility checks
martinlanghoff [Wed, 19 Sep 2007 07:19:20 +0000 (07:19 +0000)]
moodlelib: require_login() - rework course/category visibility checks

Reworked the logic of the visibility checks so that we evaluate in a
chain:

   - can view course   (visible or user can see hidden)
   - can view category (visible or user can see hidden)

Without this patch, users that could see hidden categories could not get
into courses inside of them.

While at it, fix reference to the old $USER->switchrole

17 years agodatalib:course_parent_visible() rework, remove category_parent_visible()
martinlanghoff [Wed, 19 Sep 2007 07:19:05 +0000 (07:19 +0000)]
datalib:course_parent_visible() rework, remove category_parent_visible()

Reworked course_parent_visible() to always return in a constant
number of db queries (2 worst case) regardless of nesting depth.

The rewritten version has a small cache, but if you are going to
walk many courses, it's still 1~2 DB queries per category seen,
so the right thing to do is to check it in the caller, as seen
in get_my_courses().

17 years agodatalib: get_my_courses() - add course visibility checks
martinlanghoff [Wed, 19 Sep 2007 07:18:54 +0000 (07:18 +0000)]
datalib: get_my_courses() - add course visibility checks

Reworked gmc to perform the course visibility checks. These are
very cheap if $CFG->allowvisiblecoursesinhiddencategories is true.

However, where we have to enforce category visibility, it adds a bit
of work. In simple terms, it adds a DB query to read all the categories,
and extra checks to make sure we are doing the right thing WRT

 - course visibility   vs the permission to see hidden courses
 - category visibility vs the permission to see hidden categories

and still do it quickly.

17 years agoaccesslib: get_user_courses_bycap() also returns categorypath
martinlanghoff [Wed, 19 Sep 2007 07:18:37 +0000 (07:18 +0000)]
accesslib: get_user_courses_bycap() also returns categorypath

Costs next to nothing according to testing, and allows us to walk
the categories very cheaply. We'll need this in get_my_courses()...

What a cheapskates I am...

17 years agoaccesslib: has_cap_fad() - merge switchrole with defaultuserrole
martinlanghoff [Wed, 19 Sep 2007 07:18:23 +0000 (07:18 +0000)]
accesslib: has_cap_fad() - merge switchrole with defaultuserrole

If you are a teacher in course X, you have at least
teacher-in-X + defaultloggedinuser-sitewide. So in the
course you'll have techer+defaultloggedinuser.
We try to mimic that in switchrole.

Thanks to Petr for pointing me to a similar fix in CVS.

Probably related: MDL-10945

17 years agoaccesslib: remove unused static var
martinlanghoff [Wed, 19 Sep 2007 07:18:10 +0000 (07:18 +0000)]
accesslib: remove unused static var

17 years agoaccesslib: remove deprecated load_defaultuser_role()
martinlanghoff [Wed, 19 Sep 2007 07:17:57 +0000 (07:17 +0000)]
accesslib: remove deprecated load_defaultuser_role()

17 years agomoodlelib:remove_course_contents() does not need to 'clearcache'
martinlanghoff [Wed, 19 Sep 2007 07:17:45 +0000 (07:17 +0000)]
moodlelib:remove_course_contents() does not need to 'clearcache'

Now that delete_context() marks things dirty, we no longer
need to clearcache. Which is deprecated anyway.

17 years agoaccesslib: delete_context() now appropriately marks the context dirty.
martinlanghoff [Wed, 19 Sep 2007 07:17:34 +0000 (07:17 +0000)]
accesslib: delete_context() now appropriately marks the context dirty.

17 years agoInteractive enrolment/unenrolments: make sure we unset mycourses
martinlanghoff [Wed, 19 Sep 2007 07:17:23 +0000 (07:17 +0000)]
Interactive enrolment/unenrolments: make sure we unset mycourses

17 years agoaccesslib: load_all_capabilities() must clear USER->mycourses
martinlanghoff [Wed, 19 Sep 2007 07:17:08 +0000 (07:17 +0000)]
accesslib: load_all_capabilities() must clear USER->mycourses

17 years agoaccesslib: drop rdef mangling part two
martinlanghoff [Wed, 19 Sep 2007 07:16:56 +0000 (07:16 +0000)]
accesslib: drop rdef mangling part two

We had quite a bit of leftover rdef and ra mangling.
Be more thorough and clear it up.

While at it, make load_user_accessdata() and load_all_capabilities()
more consistent.

17 years agomoodlelib: require_login() - assign tempguest role using load_temp_role()
martinlanghoff [Wed, 19 Sep 2007 07:16:43 +0000 (07:16 +0000)]
moodlelib: require_login() - assign tempguest role using load_temp_role()

And remove the explicit handling of deprecated $USER->capabilities

17 years agoaccesslib: intro load_temp_role() for temporary guest access
martinlanghoff [Wed, 19 Sep 2007 07:16:29 +0000 (07:16 +0000)]
accesslib: intro load_temp_role() for temporary guest access

Loads a "ghost" role assignment, and all the needed rdef data
into an accessinfo array.

Also minor phpdoc update on get_role_access()

17 years agoaccesslib: drop rdef mangling for default role - check in has_cap_fad()
martinlanghoff [Wed, 19 Sep 2007 07:16:18 +0000 (07:16 +0000)]
accesslib: drop rdef mangling for default role - check in has_cap_fad()

There are some exceptions when checking for caps that are inherited
from the default role. Move the check into has_cap_fad() and stop
mangling the data we put in $ad[rdef].

We now also set $ad[dr] to record default roles added.

This will later allow us to share rdef across many users in $ACCESS.

Affects:
  load_user_accessdata()
  has_cap_fad()

While at it, document has_cap_fad() a bit.

17 years agoaccesslib:load_all_capabilities() - fix guest user setup for multi-enrol
martinlanghoff [Wed, 19 Sep 2007 07:16:04 +0000 (07:16 +0000)]
accesslib:load_all_capabilities() - fix guest user setup for multi-enrol

When setting things up for the guest user, the RA entry in accessdata
was not multi-enrol-friendly. Must have glossed it over in the
multi-enrol rework.

17 years agoaccesslib/moodlelib: check $USER->access[rsw] for roleswitches
martinlanghoff [Wed, 19 Sep 2007 07:15:50 +0000 (07:15 +0000)]
accesslib/moodlelib: check $USER->access[rsw] for roleswitches

17 years agocourse/unenrol: check $USER->access[rsw] for role switches
martinlanghoff [Wed, 19 Sep 2007 07:15:38 +0000 (07:15 +0000)]
course/unenrol: check $USER->access[rsw] for role switches

17 years agoaccesslib: Document accessdata, public api, stale accessdata
martinlanghoff [Wed, 19 Sep 2007 07:15:27 +0000 (07:15 +0000)]
accesslib: Document accessdata, public api, stale accessdata

17 years agoaccesslib: rename "sess" and "accessinfo" to accessdata
martinlanghoff [Wed, 19 Sep 2007 07:15:12 +0000 (07:15 +0000)]
accesslib: rename "sess" and "accessinfo" to accessdata

The name for new data structure holding access control data
is "accessdata". And we have a new moniker "fad", short for
"from accessdata".

So
 - has_cap_fromsess()    -> has_cap_fad()
 - access_inaccessdata() -> path_inaccessdata()
 - aggr_roles_fromsess() -> aggr_roles_fad()
 - $sess   -> $ad
 - $access -> $ad

Consistency, save typing, shorter codelines...

17 years agoaccesslib:require_capability() revamp to check for USER->access
martinlanghoff [Wed, 19 Sep 2007 07:14:59 +0000 (07:14 +0000)]
accesslib:require_capability() revamp to check for USER->access

$USER->capabilities is deprecated.

17 years agoaccesslib:context_moved() remove debugging msgs
martinlanghoff [Wed, 19 Sep 2007 07:14:48 +0000 (07:14 +0000)]
accesslib:context_moved() remove debugging msgs