Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 148... Línea 148...
148
        $availablelangs  = get_string_manager()->get_list_of_translations();
148
        $availablelangs  = get_string_manager()->get_list_of_translations();
Línea 149... Línea 149...
149
 
149
 
Línea 150... Línea 150...
150
        $transaction = $DB->start_delegated_transaction();
150
        $transaction = $DB->start_delegated_transaction();
-
 
151
 
-
 
152
        $userids = array();
151
 
153
        $newpasswordusers = [];
152
        $userids = array();
154
 
153
        foreach ($params['users'] as $user) {
155
        foreach ($params['users'] as $user) {
154
            // Make sure that the username, firstname and lastname are not blank.
156
            // Make sure that the username, firstname and lastname are not blank.
155
            foreach (array('username', 'firstname', 'lastname') as $fieldname) {
157
            foreach (array('username', 'firstname', 'lastname') as $fieldname) {
Línea 244... Línea 246...
244
                }
246
                }
245
                profile_save_data((object) $user);
247
                profile_save_data((object) $user);
246
            }
248
            }
Línea 247... Línea 249...
247
 
249
 
248
            if ($createpassword) {
-
 
249
                setnew_password_and_mail($userobject);
250
            if ($createpassword) {
250
                unset_user_preference('create_password', $userobject);
251
                unset_user_preference('create_password', $userobject);
-
 
252
                set_user_preference('auth_forcepasswordchange', 1, $userobject);
-
 
253
                // Queue this user for email notification after user creation is finalized.
251
                set_user_preference('auth_forcepasswordchange', 1, $userobject);
254
                $newpasswordusers[] = $userobject;
Línea 252... Línea 255...
252
            }
255
            }
253
 
256
 
Línea 266... Línea 269...
266
            $userids[] = array('id' => $user['id'], 'username' => $user['username']);
269
            $userids[] = array('id' => $user['id'], 'username' => $user['username']);
267
        }
270
        }
Línea 268... Línea 271...
268
 
271
 
Línea -... Línea 272...
-
 
272
        $transaction->allow_commit();
-
 
273
 
-
 
274
        // After database commit, send password emails to queued users.
-
 
275
        foreach ($newpasswordusers as $userobject) {
-
 
276
            setnew_password_and_mail($userobject);
269
        $transaction->allow_commit();
277
        }
270
 
278
 
Línea 271... Línea 279...
271
        return $userids;
279
        return $userids;
272
    }
280
    }
Línea 408... Línea 416...
408
 
416
 
409
        // Preferences.
417
        // Preferences.
410
        if (!empty($preferences)) {
418
        if (!empty($preferences)) {
411
            $userpref = ['id' => $userid];
419
            $userpref = ['id' => $userid];
412
            foreach ($preferences as $preference) {
-
 
413
 
-
 
414
                /*
-
 
415
                 * Rename user message provider preferences to avoid orphan settings on old app versions.
-
 
416
                 * @todo Remove this "translation" block on MDL-73284.
-
 
417
                 */
-
 
418
                if (preg_match('/message_provider_.*_loggedin/', $preference['type']) ||
-
 
419
                        preg_match('/message_provider_.*_loggedoff/', $preference['type'])) {
-
 
420
                    $nameparts = explode('_', $preference['type']);
-
 
421
                    array_pop($nameparts);
-
 
422
                    $preference['type'] = implode('_', $nameparts).'_enabled';
-
 
423
                }
-
 
424
 
420
            foreach ($preferences as $preference) {
425
                $userpref['preference_' . $preference['type']] = $preference['value'];
421
                $userpref['preference_' . $preference['type']] = $preference['value'];
426
            }
422
            }
427
            useredit_update_user_preference($userpref);
423
            useredit_update_user_preference($userpref);
Línea 669... Línea 665...
669
                        $userpref->{'preference_'.$preference['type']} = $preference['value'];
665
                        $userpref->{'preference_'.$preference['type']} = $preference['value'];
670
                    }
666
                    }
671
                    useredit_update_user_preference($userpref);
667
                    useredit_update_user_preference($userpref);
672
                }
668
                }
673
                if (isset($user['suspended']) and $user['suspended']) {
669
                if (isset($user['suspended']) and $user['suspended']) {
674
                    \core\session\manager::kill_user_sessions($user['id']);
670
                    \core\session\manager::destroy_user_sessions($user['id']);
675
                }
671
                }
Línea 676... Línea 672...
676
 
672
 
677
                $transaction->allow_commit();
673
                $transaction->allow_commit();
678
            } catch (Exception $e) {
674
            } catch (Exception $e) {
Línea 1856... Línea 1852...
1856
                }
1852
                }
1857
            }
1853
            }
Línea 1858... Línea 1854...
1858
 
1854
 
Línea 1859... Línea -...
1859
            try {
-
 
1860
 
-
 
1861
                // Support legacy preferences from the old M.util.set_user_preference API (always using the current user).
-
 
1862
                if (isset($USER->ajax_updatable_user_prefs[$pref['name']])) {
-
 
1863
                    debugging('Updating preferences via ajax_updatable_user_prefs is deprecated. ' .
-
 
1864
                        'Please use the "core_user/repository" module instead.', DEBUG_DEVELOPER);
-
 
1865
 
-
 
1866
                    set_user_preference($pref['name'], $pref['value']);
-
 
1867
                    $saved[] = array(
-
 
1868
                        'name' => $pref['name'],
-
 
1869
                        'userid' => $USER->id,
1855
            try {
1870
                    );
1856
 
1871
                } else if (core_user::can_edit_preference($pref['name'], $user)) {
1857
                if (core_user::can_edit_preference($pref['name'], $user)) {
1872
                    $value = core_user::clean_preference($pref['value'], $pref['name']);
1858
                    $value = core_user::clean_preference($pref['value'], $pref['name']);
1873
                    set_user_preference($pref['name'], $value, $user->id);
1859
                    set_user_preference($pref['name'], $value, $user->id);
1874
                    $saved[] = array(
1860
                    $saved[] = array(