Git Product home page Git Product logo

moodle-tool_mergeusers's People

Contributors

andrewhancox avatar andrewmadden avatar aspark21 avatar codelingobot avatar danmarsden avatar fontinixxl avatar jpahullo avatar kenneth-hendricks avatar leitgab avatar leonstr avatar marxjohnson avatar michaelmeneses avatar ndunand avatar rlorenzo avatar sensei-hacker avatar t-schroeder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

moodle-tool_mergeusers's Issues

Merging in older versions of Moodle

I installed "version 2014071621" of the mergeusers tool on a version 2.2.11 (Build: 20130708) instance of Moodle on one of my test machines. It runs on a Windows Server 2008 R2 VM with IIS, PHP 5.4.31 NTS and a MSSQL 2008 R2 database.

After installing the mergeusers tool I logged into Moodle and got a blank white screen. The PHP error log contained the following:

[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP Fatal error: Class 'lang_string' not found in D:\Moodle\admin\tool\mergeusers\settings.php on line 79
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP Stack trace:
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 1. {main}() D:\Moodle\mod\quiz\review.php:0
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 2. mod_quiz_renderer->review_page() D:\Moodle\mod\quiz\review.php:251
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 3. mod_quiz_renderer->header() D:\Moodle\mod\quiz\renderer.php:54
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 4. plugin_renderer_base->__call() D:\Moodle\mod\quiz\renderer.php:54
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 5. call_user_func_array() D:\Moodle\lib\outputrenderers.php:189
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 6. core_renderer->header() D:\Moodle\lib\outputrenderers.php:189
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 7. core_renderer->render_page_layout() D:\Moodle\lib\outputrenderers.php:637
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 8. include() D:\Moodle\lib\outputrenderers.php:685
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 9. block_manager->region_has_content() D:\Moodle\theme\learning_university\layout\general.php:5
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 10. block_manager->ensure_content_created() D:\Moodle\lib\blocklib.php:349
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 11. block_manager->create_block_contents() D:\Moodle\lib\blocklib.php:986
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 12. block_base->get_content_for_output() D:\Moodle\lib\blocklib.php:934
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 13. block_base->formatted_contents() D:\Moodle\blocks\moodleblock.class.php:232
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 14. block_settings->get_content() D:\Moodle\blocks\moodleblock.class.php:280
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 15. moodle_page->__get() D:\Moodle\blocks\moodleblock.class.php:133
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 16. moodle_page->magic_get_settingsnav() D:\Moodle\lib\pagelib.php:617
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 17. settings_navigation->initialise() D:\Moodle\lib\pagelib.php:601
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 18. settings_navigation->load_administration_settings() D:\Moodle\lib\navigationlib.php:2926
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 19. admin_get_root() D:\Moodle\lib\navigationlib.php:3018
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 20. require() D:\Moodle\lib\adminlib.php:5940
[25-Aug-2014 12:59:10 Africa/Johannesburg] PHP 21. include() D:\Moodle\admin\settings\plugins.php:491

I've tried both "SQLSRV" and "MSSQL" as the $CFG->dbtype but I get the same results with both the drivers.

Is that Class 'lang_string' something that was only introduced in a newer version of Moodle?

If so, what versions of Moodle is this mergeusers tool supported on? The mergeusers README.md file shows the Minimum requirements as: "Moodle v2.x", which implies ALL versions of Moodle 2.x. But it's a bit vague...

Add confirmation step

When using the tool it is pretty surprising that once you enter in the two users you want to merge that it performs the action right away.

On such a potentially dangerous operation, it would be nice to have a confirmation step that displays the user's name, email, idnumber, and usernames before you merge just to do a quick visual check that a copy/paste error occurred.

Maybe a preview of what will happen? Like the courses each user is in and such?

Cohorts Duplicate Record Error

If the old and the new user are both in the same cohort, the script fails.

Merged user4733 (user ID = 4733) into user4725 (user ID = 4725)

For further reference, these results are recorded in the log id 1.
Some error occurred:

Exception thrown when merging: 'Error writing to database".
Duplicate entry '341-4725' for key 'mdl_cohomemb_cohuse_uix'
Trace:
#0 /path/to/moodle/lib/dml/mysqli_native_moodle_database.php(913): moodle_database->query_end(false)
#1 /path/to/moodle/admin/tool/mergeusers/lib/mergeusertool.php(244): mysqli_native_moodle_database->execute('UPDATE mdl_coho...')
#2 /path/to/moodle/admin/tool/mergeusers/lib/mergeusertool.php(170): MergeUserTool->_merge('4725', '4733')
#3 /path/to/moodle/admin/tool/mergeusers/index.php(87): MergeUserTool->merge('4725', '4733')
#4 {main}

moving help button to header

Hi,

I found, with John contributions, that help button in the part of the form is not the best place for it.

I think it is better to place it into the page header.

Are you agree?

place text as help button

In the index page, where the users to merge are selected, appears a constant text at the top.

We could place that text as a help button to make the page simpler and shorter than before.

'Search for User' field cannot contain spaces

Using Moodle 2.6.4+ (Build: 20140724) and $plugin->version = 2014071621; of the Merge Users script I've found that the 'Search for User' field on admin/tool/mergeusers/index.php cannot contain spaces.

To reproduce this problem, assuming you have two user profiles for "Herman Peter Smith", do this:

  1. Navigate to Site administration / Users / Accounts / Merge user accounts / Merge user accounts. By default you'll see just the empty "Search for User" field.
  2. Enter TWO names in the "Search for User" field, e.g. Herman Peter.
  3. Select FIRST NAME from the drop-down list. See the attached Search1.png screenshot.
  4. Click the Search button.
  5. Moodle will come back with NO RESULTS in the results table. This is wrong! There should be two results, one for each of the two "Herman Peter" profiles.
  6. Now look carefully at the value in the "Search for User" field. You'll see that the two names have been concatenated! "Herman Peter" is now "HermanPeter". See the attached Search2.png screenshot.

That's probably why no results were returned by the search - there is no user profile in the database for "HermanPeter" so Moodle correctly returned no results. So, it seems that Mergeusers is removing the space character from the search field and concatenating the values when the Search button is pressed and the form is submitted. Moodle core does not do this, so I presume this is a bug in the MergeUsers plugin.

I'm running a Windows 2003 SE SP2 Server using a MSSQL 2008 R2 database and IIS as the web server. PHP 5.4.31 NTS running as a FastCGI module.

Search:
search1

Result:
search2

Is "DELETE FROM mdl_grade_grades" the correct thing to do?

Using moodle-tool_mergeusers $plugin->version = 2014070900;

I merged profile 43493 into profile 44175 on my test site and I noticed the following DELETE statement on the results page, /admin/tool/mergeusers/index.php:

DELETE FROM mdl_grade_grades WHERE id IN (580471, 580470, 580909, 580875, 580828, 580640, 580677, 577710, 577709, 577854, 577713, 577798, 577801, 577858, 577805, 577816, 580469)

Why is the plugin DELETING records from mdl_grade_grades?

Surely we want to keep those grade_grades records and move them onto the profile during the merge, instead of deleting them? In other words, shouldn't it be doing a UPDATE instead of a DELETE?

Example:
UPDATE mdl_grade_grades
SET userid =
WHERE id IN (580471, 580470, 580909, 580875, 580828, 580640, 580677, 577710, 577709, 577854, 577713, 577798, 577801, 577858, 577805, 577816, 580469)

My test Moodle site is running on a Windows Server 2008 R2 virtual machine with:
IIS 7.5
PHP 5.5.12 NTS
MSSQL 2008 R2
and Moodle $release = '2.5.6+ (Build: 20140529)';.

settings.php

in settings.php this call is made before the check to $hassiteconfig.
require_once DIR . '/lib/autoload.php';

This function seems to do a bit of work and loads a lot of classes that don't appear to be needed within settings.php

settings.php is called on almost every Moodle page load so should be optimised to do as little work as possible.

Every time this is called:
MergeUserTool::transactionsSupported()

mergeusertool calls _construct and makes a sql query for every table that exists in the Moodle database. This causes significant unnecessary load on the server when $hassiteconfig = true. if you want to use trasactionsupported() it should sit outside the class and be usable without needing to make all those db calls.

Revisit lang strings according to transactions

Hi all,

Since we have added knowlegde on transactions supported, we can now customize message according to that (like when a merging error occurs, etc), instead of a generic message.

Problem with excluded table, user_lastaccess

In \admin\tool\mergeusers\config\config.php the 'exceptions' array lists the 'user_lastaccess' table as one of the excluded tables. Could the scenario below cause any problems?

Assume two user profiles:

/user/profile.php?id=1234 shows the 'Last access' date on his Moodle profile as 12 July 2012.
/user/profile.php?id=5678 shows the 'Last access' date on his Moodle profile as 30 September 2013.

Now lets say user 5678 has done a quiz attempt on 10 January 2013. Sometime AFTER 10 January 2013 you merge profiles 1234 and 5678 and you KEEP profile 1234. So the quiz/gradebook result for that 10 January 2013 exam is moved to the 1234 profile during the merge. But 'Last access' value for the 1234 user is still 12 July 2012 because that table is excluded from the merge. So Moodle is now saying that the student last accessed Moodle on 12 July 2012, but yet the quiz/gradebook result shows that he did a quiz attempt on 10 January 2013. So the 'quiz attempt' date is now AFTER his 'Last access' date, which doesn't make sense - he had to have accessed Moodle on 10 January 2013 in order to do the quiz, so his 'Last access' date does need to be updated during the merge.

So, is this actually good reason to INCLUDE the user_lastaccess table in the merge?
What were the reasons for excluding it?

Duplicate Record Error

Having the same issue as

#4 (comment)

(Merge failing)

Exception thrown when merging: 'Error writing to database".
Duplicate entry '96-1992-1' for key 'mdl_quizatte_quiuseatt_uix'
Trace:
#0 /home/cfalscom/public_html/lib/dml/mysqli_native_moodle_database.php(913): moodle_database->query_end(false)
#1 /home//public_html/admin/tool/mergeusers/lib/table/generictablemerger.php(225): mysqli_native_moodle_database->execute('UPDATE mdl_quiz...')
#2 /home/
/public_html/admin/tool/mergeusers/lib/table/generictablemerger.php(80): GenericTableMerger->updateRecords(Array, Array, 'userid', Array, Array)
#3 /home//public_html/admin/tool/mergeusers/lib/mergeusertool.php(277): GenericTableMerger->merge(Array, Array, Array)
#4 /home/
/public_html/admin/tool/mergeusers/lib/mergeusertool.php(212): MergeUserTool->_merge('1992', '364')
#5 /home/*****/public_html/admin/tool/mergeusers/index.php(135): MergeUserTool->merge('1992', '364')
#6 {main}

Not sure if how the post referenced helps, but I have updated the plugin and I am still getting this error.

Error: Database type mssql not supported.

My test Moodle site is running on a Windows Server 2008 R2 virtual machine with IIS 7.5 and PHP 5.5.12 NTS and Moodle $release = '2.5.6+ (Build: 20140529)';.

I installed the moodle-tool_mergeusers $plugin->version = 2014070900; on that test machine which is running on a MSSQL 2008 R2 database. When I use the FreeTDS driver - $CFG->dbtype = 'mssql'; and I load the /admin/tool/mergeusers/index.php page I get the following message:

"Error: Database type mssql not supported."

mssql_error

But when I switch to the Microsoft Drivers for PHP for SQL Server (v3.0.1) using $CFG->dbtype = 'sqlsrv'; the error goes away. This suggests that the mergeusers plugin does not fully support the FreeTDS driver - even though Moodle core does support it.

Unfortunately that Microsoft SQLSRV driver seems to be a bit buggy (upgrading Moodle 2.0 to 2.2 and 2.5 was a disaster with the SQLSRV driver for me) and Microssoft doesn't seem to be in a hurry to release a new version - the current version, 3.0.1, was released in 2012! And there's no hint of an updated driver being released anytime soon.

So, can we add full support for the FreeTDS driver (dbtype = 'sqlsrv') in this Merge Users plugin?

Thanks.

don't list inactive accounts

I suggest that inactive accounts don't get listed when searching accounts to be merged. It's annoying, especially when the same person has more than two accounts and the same search has to be made more than once.

Auto detection of compound indexes

Hi all!

The final solution for the compound indexes is to auto detect ALL compound indexes on every single Moodle instance, and considering also customizes indexes, even additional to those specified from Moodle.

The first step is to get all compound indexes. I get this SQL to get ALL compound indexes (i.e., indexes with more than a column).

To do so, we have $DB->get_tables(false); and then $DB->get_indexes($table_name); to get all indexes from the current Moodle instance, independent from the database engine 😃

Once I have all compound indexes, they will be filtered to consider only those with user-related column names.

The idea is to have a manual update (like an additional option to the administration settings), so that the compound indexes list is updated only on demand.

Any suggestions are welcome!

Jordi

Remove enrollments from old user so they don't appear in reports

Currently, on the old user, enrolments are merely marked as suspended, so on reports and such they appear exactly the same as a user whose enrolment has merely expired (depending on settings elsewhere). Therefore, at the end of a term a teacher may have a report with three "identical" students in the class:

George Bush
George Bush
George Bush

If they look at the end of a term, all students may be marked suspended, so it is not clear which copy is the "live" user and which is an old, unused artifact from before the merge.

Perhaps the old artifact user should be un-enrolled rather than just suspended?

Quiz Attempts

MDL_QUIZ_ATTEMPTS has a compound unique key called mdl_quizatte_quiuseatt_uix that consists of quiz, userid, attempt.

An issue arises if both users have taken the same quiz and the attempts match.

The issue I ran into involved two users taking the same quiz once. So changing the userid from fromID to toID caused an error.

I manually fixed this by changing the attempt of the toID to '2' before I ran the merge.

compound indexes with multiple columns and not all user-related

I found cases where the compound index is formed by several columns, and more than one, but not all of them are user-related.

Imagine an index 'blablaindex' formed by columns (userid1, userid2, othercolumn). The current configuration with the flag 'both' on 'compoundindexes' settings is not any more applicable.

Rethink about it to make generic the number of user-related fields in a compound index.

autoloading

Moodle has it's own built-in class autoloading, it would be better for the code to follow this standard rather than implement it's own class autoloading.

"Did you remember to..." PHP notices

I've installed '$plugin->version = 2014011012' of this Merge Users plugin on my Moodle 2.5.3+ (Build: 20131129) test server which is on a MSSQL 2008 R2, Windows Server 2008 R2, IIS 7 and PHP 5.3.8, SRLSRV platform. When the Moodle Debug messages option is set to 'DEVELOPER' and debugdisplay is set to 'Yes' I get the following debug messages when I open the Site administration / Users / Accounts / Merge user accounts / Merge user accounts page. Are these "Duplicate value ... found in column 'table_catalog'" messages something I should worry about?

The messages are:

Did you remember to call setType() for 'oldusergroup[olduserid]'? Defaulting to PARAM_RAW cleaning.?line 1334 of \lib\formslib.php: call to debugging()
?line 281 of \lib\formslib.php: call to moodleform->detectMissingSetType()
?line 202 of \lib\formslib.php: call to moodleform->_process_submission()
?line 56 of \admin\tool\mergeusers\index.php: call to moodleform->moodleform()

Did you remember to call setType() for 'newusergroup[newuserid]'? Defaulting to PARAM_RAW cleaning.?line 1334 of \lib\formslib.php: call to debugging()
?line 281 of \lib\formslib.php: call to moodleform->detectMissingSetType()
?line 202 of \lib\formslib.php: call to moodleform->_process_submission()
?line 56 of \admin\tool\mergeusers\index.php: call to moodleform->moodleform()

Did you remember to make the first column something unique in your call to get_records? Duplicate value 'MyMoodleDatabaseName' found in column 'table_catalog'.?line 845 of \lib\dml\sqlsrv_native_moodle_database.php: call to debugging()
?line 607 of \admin\tool\mergeusers\lib\mergeusertool.php: call to sqlsrv_native_moodle_database->get_records_sql()
?line 323 of \admin\tool\mergeusers\lib\mergeusertool.php: call to MergeUserTool->getCurrentUserFieldNames()
?line 153 of \admin\tool\mergeusers\lib\mergeusertool.php: call to MergeUserTool->init()
?line 61 of \admin\tool\mergeusers\index.php: call to MergeUserTool->__construct()

Did you remember to make the first column something unique in your call to get_records? Duplicate value 'MyMoodleDatabaseName' found in column 'table_catalog'.?line 845 of \lib\dml\sqlsrv_native_moodle_database.php: call to debugging()
?line 607 of \admin\tool\mergeusers\lib\mergeusertool.php: call to sqlsrv_native_moodle_database->get_records_sql()
?line 323 of \admin\tool\mergeusers\lib\mergeusertool.php: call to MergeUserTool->getCurrentUserFieldNames()
?line 153 of \admin\tool\mergeusers\lib\mergeusertool.php: call to MergeUserTool->init()
?line 61 of \admin\tool\mergeusers\index.php: call to MergeUserTool->__construct()

Did you remember to make the first column something unique in your call to get_records? Duplicate value 'MyMoodleDatabaseName' found in column 'table_catalog'.?line 845 of \lib\dml\sqlsrv_native_moodle_database.php: call to debugging()
?line 607 of \admin\tool\mergeusers\lib\mergeusertool.php: call to sqlsrv_native_moodle_database->get_records_sql()
?line 323 of \admin\tool\mergeusers\lib\mergeusertool.php: call to MergeUserTool->getCurrentUserFieldNames()
?line 153 of \admin\tool\mergeusers\lib\mergeusertool.php: call to MergeUserTool->init()
?line 61 of \admin\tool\mergeusers\index.php: call to MergeUserTool->__construct()

Merge Users who both use the same Checklist.

I´ve tried your plugin.

I´ve created two users. Both are enroled in the same course and both mark their progress in the same checklist.

When I merge the two users and the final user view his checklist following message is shown:

Did you remember to make the first column something unique in your call to get_records? Duplicate value '183' found in column 'id'.
line 780 of /lib/dml/pgsql_native_moodle_database.php: call to debugging()
line 1783 of /mod/checklist/locallib.php: call to pgsql_native_moodle_database->get_records_sql()
line 603 of /mod/checklist/locallib.php: call to checklist_class->view_report()
line 49 of /mod/checklist/report.php: call to checklist_class->report()

Revision as for Featured Plugin

We had the honor of being selected to be a Feature Plugin from Moodle.org (https://moodle.org/mod/forum/discuss.php?d=271187).

This interview ends with some conclusions and list of items to improve. This issue is a kind of EPIC issue. We should create new issues for every point to improve as a new issue, relating that new issue with this issue. There is very good feedback and ways of improving and normalization.

Show idnumber on confirmation page?

It has been requested that the idnumber be shown on the confirmation page.
This field is used to identify users within each organization. For example, in our case it is the "student ID" issued by the school, and is how the school identifies users. I'll submit a pull request implementing if the idea meets with the approval of @ndunand .

deleting users with same badge

If I try to merge two users that have same/equal badge, I get the error

Duplicate entry '62-78146' for key 'mdl_badgissu_baduse_uix'

that is reasonable response as one badge can not be issued more than once to one user. Can some sort of check in this direction be added?

warning for accessing a non existing object

( ! ) Notice: Trying to get property of non-object in /var/www/jpujol/moodle/admin/tool/mergeusers/lib/userreviewtable.php on line 100
Call Stack
#   Time    Memory  Function    Location
1   0.0005  295312  {main}( )   ../index.php:0
2   2.9133  60707448    tool_mergeusers_renderer->index_page( ) ../index.php:110
3   3.0164  60885816    tool_mergeusers_renderer->render_user_review_table( )   ../renderer.php:127
4   3.0166  60917008    UserReviewTable->__construct( ) ../renderer.php:152
5   3.0166  60918064    UserReviewTable->buildtable( )  ../userreviewtable.php:85

How to reproduce:

  1. Enable debug for developers in Moodle in a test environement.
  2. Search for a user to merge in admin/tool/mergeusers/index.php.
  3. Choose only one user either as a user to remove or to maintain (it does not matter).
  4. Save selection.
  5. When printing current selection you will see the above warning at the top.

It is produces by accessing directly to object attributes when one out of two objects may not exist yet:

Line 100 at userreviewtable.php:

if ($this->olduser->idnumber || $this->newuser->idnumber) {

Proposal to solve it:

if (isset($this->olduser->idnumber) || isset($this->newuser->idnumber)) {

WIP

Generic class name used in config.php

admin/tool/mergeusers/lib/config.php defines the class "Config" - this is way too generic and could conflict with a range of different things - it is also confusing as Moodle has it's own handling of generic config values.

This class should be renamed to something specific to tool_mergeusers - maybe something like:
class tool_mergeusers_config()

MS SQL Server support: Duplicate value found in column 'table_catalog'

See @luisdev comment on #24 :

(excerpt, edited)

I installed this version ($plugin->release = '1.7 (Build: 2014040200)';) on a Moodle 2.5.4+ (Build: 20140131) test machine - a Windows 7 Professional box running IIS 6.1 and PHP 5.4.22 NTS under FastCGI. $CFG->dbtype = 'sqlsrv'; in the Moodle config.php file.

As soon as I open the admin/tool/mergeusers/index.php page I get the following error complaining about a "Duplicate value 'MyMoodleDatabase' found in column 'table_catalog'."

[17-Apr-2014 09:07:20 Africa/Johannesburg] PHP Notice:  Did you remember to make the first column something unique in your call to get_records? Duplicate value 'MyMoodleDatabase' found in column 'table_catalog'.<ul style="text-align: left"><li>line 845 of \lib\dml\sqlsrv_native_moodle_database.php: call to debugging()</li><li>line 617 of \admin\tool\mergeusers\lib\mergeusertool.php: call to sqlsrv_native_moodle_database->get_records_sql()</li><li>line 333 of \admin\tool\mergeusers\lib\mergeusertool.php: call to MergeUserTool->getCurrentUserFieldNames()</li><li>line 163 of \admin\tool\mergeusers\lib\mergeusertool.php: call to MergeUserTool->init()</li><li>line 66 of \admin\tool\mergeusers\index.php: call to MergeUserTool->__construct()</li></ul> in C:\moodle\lib\weblib.php on line 2837
[17-Apr-2014 09:07:20 Africa/Johannesburg] PHP Stack trace:
[17-Apr-2014 09:07:20 Africa/Johannesburg] PHP   1. {main}() C:\moodle\admin\tool\mergeusers\index.php:0
[17-Apr-2014 09:07:20 Africa/Johannesburg] PHP   2. MergeUserTool->__construct() C:\moodle\admin\tool\mergeusers\index.php:66
[17-Apr-2014 09:07:20 Africa/Johannesburg] PHP   3. MergeUserTool->init() C:\moodle\admin\tool\mergeusers\lib\mergeusertool.php:163
[17-Apr-2014 09:07:20 Africa/Johannesburg] PHP   4. MergeUserTool->getCurrentUserFieldNames() C:\moodle\admin\tool\mergeusers\lib\mergeusertool.php:333
[17-Apr-2014 09:07:20 Africa/Johannesburg] PHP   5. sqlsrv_native_moodle_database->get_records_sql() C:\moodle\admin\tool\mergeusers\lib\mergeusertool.php:617
[17-Apr-2014 09:07:20 Africa/Johannesburg] PHP   6. debugging() C:\moodle\lib\dml\sqlsrv_native_moodle_database.php:845
[17-Apr-2014 09:07:20 Africa/Johannesburg] PHP   7. trigger_error() C:\moodle\lib\weblib.php:2837

Activities (assignment + database): Submission & Grade

When merging two users that have submited file or that they were already graded, two types of errors can appeare:

Duplicate entry '3324-77998-0-0' for key 'mdl_assisubm_assusegroatt_uix'
Duplicate entry '2577-38299-0' for key 'mdl_assigrad_assuseatt_uix'

I'm not expert in Moodle nor have knowledge to see into the database, but I have done some researche work. If I make some mistakes here, please correct me.

Submition:
At assignment it is possible to allow submiittion of only one or many files. If only one is allowed - that is the problem. And if two or more is allowed - there should be no problem - but there is. If user submitted two files (with the same name or two different names) with both user-accounts (one file per account), than there is "submission error". Then user delete one submitted file, and problem is stil there. The same thing holds for database activity. By my opinion, if submition is deleted, some records still remains in database.

Possible solutions:

  • If file was deleted - ignore that record
  • if two files have the same name - ignore one
  • if two files have different names - ignore file which is older or which has higher grade or which has no grade. Better solution is that new ".zip" file is created and both files is archived there.
    if user submited only text - append one text to another.

Grading:
If two users got grade at the seam activity - there is problem. Even if on grade is deleted by teacher or manager, there is the same problem. Even if submittion was removed by user, problem remains.

Possible solutions:

  • if grade is already deleted - ignore it
  • if grades are the same - ignore one
  • ignore lower grade. But plugin can't know the meaning of lower and greater.
  • ignore older grade. ???
  • combine both grades. ???
    Probably the most buletprof solution will be, that plugun outputs exact place where error accured (class name (id), assignment name (id) and grade for both users) and that manager deletes one. After that, deleted grade should be ignored.

New configuration settings to add for compound indexes

Reported in the plugin forum: https://moodle.org/plugins/view.php?plugin=tool_mergeusers

--
-- Table structure for table `mdl_certif_completion`
--

CREATE TABLE IF NOT EXISTS `mdl_certif_completion` (
`id` bigint(10) NOT NULL AUTO_INCREMENT,
`certifid` bigint(10) NOT NULL,
`userid` bigint(10) NOT NULL,
`certifpath` tinyint(2) NOT NULL,
`status` tinyint(2) NOT NULL,
`renewalstatus` tinyint(2) DEFAULT '0',
`timewindowopens` bigint(10) DEFAULT NULL,
`timeexpires` bigint(10) DEFAULT NULL,
`timecompleted` bigint(10) DEFAULT NULL,
`timemodified` bigint(10) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `mdl_certcomp_ceruse_uix` (`certifid`,`userid`),
KEY `mdl_certcomp_cer_ix` (`certifid`),
KEY `mdl_certcomp_use_ix` (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Certifications completed' AUTO_INCREMENT=10 ;

We should add the following compound index settings:

'compoundindexes' => array(
'certif_completion' => array(
'userfield' => 'userid',
'otherfields' => array('certifid'),
),
),

For course completion:

'course_modules_completion' => array(
'userfield' => 'userid',
'otherfields' => array('coursemoduleid'),
),
),

For scorm module:

Since scorm is a well-known and often used activity plugin, we'd like to see
the following addition to the compund configuration.
Note: this has been directly taken from our loval configuration.

return array(
    'compoundindexes' => array(
        'scorm_scoes_track' => array(
            'userfield' => 'userid',
            'otherfields' => array('scormid', 'scoid', 'attempt', 'element'),
//mdl_scorscoetrac_usescosco_uix (unique)
        ),
        ),
);

duplicate entry - assigments

When mergin two account I got Duplicate entry '2592-37258-0' for key 'mdl_assigrad_assuseatt_uix'

mdl_assigrad_assuseatt_uix is an index in table mdl_assign_grades, UNIQUE KEY mdl_assigrad_assuseatt_uix (assignment,userid,attemptnumber).

As I understand it, it is not possible for one person to get more than one grade for the same attempt on same assignment. I suggest that in this case the newer grade remains.

Install Error

I tried running the install through the web interface via pusing the Install Button.

Error I received -- tool_installaddon/err_curl_http_code

I tried using Release 1.5 (Build: 2013121115).

However it does work fine via standard upload via the install modules tool in my Moodle 2.5 version.

Thanks for your hard work on this module.
Forrest Gaston

exclude views from tool parsing

(Reported on plugin page: https://moodle.org/plugins/view.php?plugin=tool_mergeusers)

Hello, it seems your tool is attempting to update views in addition to tables. I added a print_r($data); line to the function merge() in /admin/tool/mergeusers/lib/table/generictablemerger.php at line 61 to find out where the problem was and it happened on a view that I made in our system to help with some external reporting purposes. Views should be eliminated from this tool's searching. Here is the error message I received on the web page after it failed:

For further reference, these results are recorded in the log id 3.
Some error occurred:

Exception thrown when merging: 'Error reading from database".
Unknown column 'id' in 'field list'
Trace:
#0 C:\Websites\moodle\lib\dml\mysqli_native_moodle_database.php(1014): moodle_database->query_end(false)
#1 C:\Websites\moodle\admin\tool\mergeusers\lib\table\generictablemerger.php(65): mysqli_native_moodle_database->get_records_sql('SELECT id FROM ...')
#2 C:\Websites\moodle\admin\tool\mergeusers\lib\mergeusertool.php(277): GenericTableMerger->merge(Array, Array, Array)
#3 C:\Websites\moodle\admin\tool\mergeusers\lib\mergeusertool.php(212): MergeUserTool->_merge('535', '1331')
#4 C:\Websites\moodle\admin\tool\mergeusers\index.php(135): MergeUserTool->merge('535', '1331')
#5 {main}

Merge failed!
Your database engine supports transactions. Therefore, the whole current transaction has been rolled back and no modification has been made to your database.
Report to moderator
Imatge Perry Way
Perry Way

dj, 15 gen 2015, 21:00
To add to my previous comment, I have a worthy enhancement to make things work right.

In /admin/tool/mergeusers/lib/mergeusertool.php line 135, if you take this code here:

$this->sqlListTables = 'SHOW TABLES like "' . $CFG->prefix . '%"';

and replace it with this:

$this->sqlListTables = "SHOW FULL TABLES WHERE `Tables_in_moodle` LIKE '" . $CFG->prefix . "%' AND `Table_type` = 'BASE TABLE'";

it should avoid attempting to set the values of records in views because it filters all views out from the results.

Once I did this then everything worked nicely!

Thanks for this tool!

Perry

Merge of custom profile fields

As I was merging about 20 students yesterday I merged the custom fields for the students by hand. I think it would be great if you can merge them automatically with the plugin.

transactions only

As John Hoppes introduced, allow this plugin to only merge users if the database suports transactions.

how to deal with unique keys in some tables?

For instance, this user has attempts at a quiz in both his accounts:

Merging «xxx» (user ID = 93) into «yyy» (user ID = 179)
Error writing to database

More information about this error

Debug info: Duplicate entry '106-179-1' for key 'mdl_quizatte_quiuseatt_uix'
UPDATE mdl_quiz_attempts SET userid = '179' WHERE id IN (744, 1302, 2659)
[array (
)]
Error code: dmlwriteexception
Stack trace:
line 426 of /lib/dml/moodle_database.php: dml_write_exception thrown
line 895 of /lib/dml/mysqli_native_moodle_database.php: call to
moodle_database->query_end()
line 179 of /admin/tool/mergeusers/index.php: call to
mysqli_native_moodle_database->execute()

New UI with search

With contribution related to pull request #24, thanks to @jhoopes, this plugin is open to have a new UI with improved capabilities:

  • Search for users to merge.
  • Old form available as advanced options.
  • And more...

getCurrentUserFieldNames() fails for multiple columns, overcomplicated

I've fixed a error being thrown in getCurrentUserFieldNames() and in cleaned it up a lot in the process. Cleaning all of this up, it's been simplified from from 49 lines to just 9 lines.

getCurrentUserFieldNames() finds field names that looks like userids. Currently it throws errors on some tables, such as 'mdl_message_contacts', because the table has more than one column that matches and the code isn't designed for that. (get_records_sql requires that the first field be unique because it's used as an array index).

Also, it re-implements the existing Moodle function get_fieldset_sql(), using get_records_sql(). Finally, it has a somewhat pointless loop, assigning each value from one array to another array, rather than just returning the first array (by only selecting the needed value in the first place).

Cleaning all of this up, we can reduce the function from 49 lines to just 9 lines. The new version follows. It should be tested on MySQL and PgSQL, but I'm fairly sure my transformation doesn't break anything.

    private function getCurrentUserFieldNames($tableName, $userFields)
    {
        global $CFG, $DB;

        if (($CFG->dbtype == 'sqlsrv') ||($CFG->dbtype == 'mssql')){
            return $DB->get_fieldset_sql("SELECT column_name FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME ='$tableName'
                    AND COLUMN_NAME IN (" . $userFields . ")");
        } else if (($CFG->dbtype == 'mysqli') || ($CFG->dbtype == 'pgsql')){
            return $DB->get_fieldset_sql("SELECT column_name FROM information_schema.columns WHERE table_name ='" .
                    $tableName . "' and column_name IN (" . $userFields . ")");
        }
    }

dedicated Moodle capability to use the tool

As requested by Arto Nieminen on https://moodle.org/plugins/view.php?plugin=tool_mergeusers, it would be nice to implement two capabilities:

  • tool_mergeusers:performmerge : to be able to perform a merge
  • tool_mergeusers:viewreports : to be able to view reports

For the sake of consistency with earlier versions, we could leave those 2 capabilities to unset for all roles, but a site administrator could enable it for a system role (like Manager) or for specific users.

events_trigger deprecated

I'm running Moodle 2.7.3+ (Build: 20141120) and get the notice that events_trigger is deprecated. Please update.

Other than that, everything worked great, and my added plugins to config.local ran without problems

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.