<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3ABackup_roles_1.7</id>
	<title>Development:Backup roles 1.7 - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3ABackup_roles_1.7"/>
	<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Backup_roles_1.7&amp;action=history"/>
	<updated>2026-05-07T03:16:59Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Backup_roles_1.7&amp;diff=10848&amp;oldid=prev</id>
		<title>Олег Давидович: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Backup_roles_1.7&amp;diff=10848&amp;oldid=prev"/>
		<updated>2024-10-21T08:51:01Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 08:51, 21 октября 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Олег Давидович</name></author>
	</entry>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Backup_roles_1.7&amp;diff=10847&amp;oldid=prev</id>
		<title>1&gt;Dougiamas в 16:25, 20 сентября 2006</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Backup_roles_1.7&amp;diff=10847&amp;oldid=prev"/>
		<updated>2006-09-20T16:25:10Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;===Backup===&lt;br /&gt;
Backup should be modified in two stages:&lt;br /&gt;
&lt;br /&gt;
1. &amp;#039;&amp;#039;&amp;#039;Calculating users to be included&amp;#039;&amp;#039;&amp;#039;: It&amp;#039;s controlled by the user_check_backup() function. Such function calculates the users to be included (based on whatever the teacher/admin has selected previously in the backup forms. All those users are stored in the &amp;#039;&amp;#039;&amp;#039;backupable_users&amp;#039;&amp;#039;&amp;#039; variable (an array of user-ids). No need to be modified, the logic is the same.&lt;br /&gt;
&lt;br /&gt;
Then, beginning in line 48 of backuplib.php, we iterate over each element in that variable, calculating which roles (in the sense of old roles) every user has. This part of code (3-4 queries per user) fshould be replaced with the proper select/function that returns the new roles each user has (exclusively in the COURSE context!). This list, hopefully one array, should be serialised and saved to &amp;#039;&amp;#039;&amp;#039;$backupids_rec-&amp;gt;info&amp;#039;&amp;#039;&amp;#039; (line 77), so all those info will be inserted to the temporal &amp;#039;&amp;#039;&amp;#039;backup_ids&amp;#039;&amp;#039;&amp;#039; table.&lt;br /&gt;
&lt;br /&gt;
One notable exception is that, some of the calculated users can have 0 roles in the CONTEXT (unenroled users, old teachers...). This is because all those users have had some interaction in the course (forum post...) but now, for any reason, they don&amp;#039;t belong to the course anymore. And, to keep information consistent, we need to restore such users too (with some sort of special &amp;#039;&amp;#039;virtual&amp;#039;&amp;#039; role assigned (currently such role is called &amp;#039;&amp;#039;needed&amp;#039;&amp;#039; and it must be added to the array of roles (current behaviour) or just leave such array empty. Note that such &amp;#039;&amp;#039;needed&amp;#039;&amp;#039; role is just one interim role used to know how to backup and restore such user later, not an official role at all.&lt;br /&gt;
&lt;br /&gt;
2. &amp;#039;&amp;#039;&amp;#039;Writing users to .xml file&amp;#039;&amp;#039;&amp;#039;: Good news are that, since the beginning, the moodle.xml backup file contains one &amp;lt;ROLES&amp;gt; section inside each &amp;lt;USER&amp;gt; entry. Exact structure is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;USERS&amp;gt;&lt;br /&gt;
:&amp;lt;USER&amp;gt;&lt;br /&gt;
::&amp;lt;ROLES&amp;gt;&lt;br /&gt;
:::&amp;lt;ROLE&amp;gt;&lt;br /&gt;
&lt;br /&gt;
XML output for users is controlled by the &amp;#039;&amp;#039;&amp;#039;backup_user_info()&amp;#039;&amp;#039;&amp;#039; function. After printing all the user attributes, in line 1095, the process of writing the ROLES section starts. The &amp;#039;&amp;#039;&amp;#039;$user-&amp;gt;info&amp;#039;&amp;#039;&amp;#039; variable must contain the serialised array of roles of the user (plus the &amp;#039;&amp;#039;needed&amp;#039;&amp;#039; virtual role named above). &lt;br /&gt;
After de-serialising such array, if the user has any role, we&amp;#039;ll start the &amp;lt;ROLES&amp;gt; tag, adding one &amp;lt;ROLE&amp;gt; tag for each role in the array.&lt;br /&gt;
&lt;br /&gt;
Inside each element of those &amp;lt;ROLE&amp;gt; tags, currently we write all the old info (fields) from the old user_xxxx tables. As those tables are out, we only have to write the role name and, if I&amp;#039;m not wrong, the last access information (gathered, if present, from the new &amp;#039;&amp;#039;&amp;#039;user_lastaccess&amp;#039;&amp;#039;&amp;#039; table).&lt;br /&gt;
Note that users with the &amp;#039;&amp;#039;needed&amp;#039;&amp;#039; virtual role are also exported.&lt;br /&gt;
&lt;br /&gt;
With these 2 simple modifications, backup should be able to export new roles without problems.&lt;br /&gt;
&lt;br /&gt;
Two important comments/questions:&lt;br /&gt;
&lt;br /&gt;
a) Is it needed to export capabilities? If so, strategy above should change slightly.&lt;br /&gt;
&lt;br /&gt;
b) How is going to be be the &amp;#039;&amp;#039;matching&amp;#039;&amp;#039; strategy on restore? Just by role name? It could cause some awful collisions depending of the name of the roles in the destination server.&lt;br /&gt;
&lt;br /&gt;
c) Are role-names constant? I.E. the legacy student, teacher... roles are fixed names or are they localised for each language (I really hope they won&amp;#039;t change by language, but just to be 100% sure).&lt;br /&gt;
&lt;br /&gt;
d) Also, I would suggest to change the &amp;#039;&amp;#039;needed&amp;#039;&amp;#039; virtual role name to something more difficult to be used as name (to avoid potential collisions if the role name is going to be the &amp;#039;&amp;#039;matching&amp;#039;&amp;#039; strategy. For example: &amp;#039;&amp;#039;needed_backup_int_role&amp;#039;&amp;#039; or something similar.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Backup:&lt;br /&gt;
&lt;br /&gt;
# Calculate all the roles to be exported by using get_roles_used_in_context() on each module within the course and adding them up.  Contexts searched are course, block and activity modules.&lt;br /&gt;
# Calculate all the course, block and module roles for each user. Save them to the backup_ids table.&lt;br /&gt;
# One unique ROLES section defining all the roles completely (with capabilities and level)&lt;br /&gt;
# One ROLES section inside each USER defining the granted roles with their context. It&amp;#039;s possible to have users without roles at all (unenrolled, or perhaps users who have access to the course via a category role_assign).&lt;br /&gt;
# One ROLES_OVERRIDES section inside each context (course, module, block) to annotate overrides&lt;br /&gt;
&lt;br /&gt;
Restore: &lt;br /&gt;
&lt;br /&gt;
# Restore the main ROLES section (3) completely!&lt;br /&gt;
# Restore users, saving assigned roles to interim backup_ids tables.&lt;br /&gt;
# When restoring course/module/block info, assign context roles to users.&lt;br /&gt;
# When restoring course/module/block contexts, restore the overrides.&lt;/div&gt;</summary>
		<author><name>1&gt;Dougiamas</name></author>
	</entry>
</feed>