Ignore:
Timestamp:
May 2, 2016, 12:09:23 PM (3 years ago)
Author:
jrpelegrina
Message:

Updated to moodle 3.0.3

Location:
moodle/trunk/fuentes/lib/classes/lock
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • moodle/trunk/fuentes/lib/classes/lock/db_record_lock_factory.php

    r136 r1331  
    104104     */
    105105    protected function generate_unique_token() {
    106         $uuid = '';
    107 
    108         if (function_exists("uuid_create")) {
    109             $context = null;
    110             uuid_create($context);
    111 
    112             uuid_make($context, UUID_MAKE_V4);
    113             uuid_export($context, UUID_FMT_STR, $uuid);
    114         } else {
    115             // Fallback uuid generation based on:
    116             // "http://www.php.net/manual/en/function.uniqid.php#94959".
    117             $uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
    118 
    119                 // 32 bits for "time_low".
    120                 mt_rand(0, 0xffff), mt_rand(0, 0xffff),
    121 
    122                 // 16 bits for "time_mid".
    123                 mt_rand(0, 0xffff),
    124 
    125                 // 16 bits for "time_hi_and_version",
    126                 // four most significant bits holds version number 4.
    127                 mt_rand(0, 0x0fff) | 0x4000,
    128 
    129                 // 16 bits, 8 bits for "clk_seq_hi_res",
    130                 // 8 bits for "clk_seq_low",
    131                 // two most significant bits holds zero and one for variant DCE1.1.
    132                 mt_rand(0, 0x3fff) | 0x8000,
    133 
    134                 // 48 bits for "node".
    135                 mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
    136         }
    137         return trim($uuid);
    138     }
    139 
     106        return generate_uuid();
     107    }
    140108
    141109    /**
     
    249217        foreach ($this->openlocks as $key => $unused) {
    250218            $lock = new lock($key, $this);
    251             $this->release_lock($lock);
     219            $lock->release();
    252220        }
    253221    }
  • moodle/trunk/fuentes/lib/classes/lock/lock.php

    r136 r1331  
    5050    protected $released;
    5151
     52    /** @var string $caller Where was this called from? Stored for when a warning is shown */
     53    protected $caller = 'unknown';
     54
    5255    /**
    5356     * Construct a lock containing the unique key required to release it.
     
    6063        $this->key = $key;
    6164        $this->released = false;
     65        $caller = debug_backtrace(true, 2)[1];
     66        if ($caller && array_key_exists('file', $caller ) ) {
     67            $this->caller = $caller['file'] . ' on line ' . $caller['line'];
     68        } else if ($caller && array_key_exists('class', $caller)) {
     69            $this->caller = $caller['class'] . $caller['type'] . $caller['function'];
     70        }
    6271    }
    6372
     
    104113    public function __destruct() {
    105114        if (!$this->released && defined('PHPUNIT_TEST')) {
     115            $key = $this->key;
    106116            $this->release();
    107             throw new \coding_exception('\core\lock\lock(' . $this->key . ') has fallen out of scope ' .
    108                                         'without being released.' . "\n" .
    109                                         'Locks must ALWAYS be released by calling $mylock->release().');
     117            throw new \coding_exception("A lock was created but not released at:\n" .
     118                                        $this->caller . "\n\n" .
     119                                        " Code should look like:\n\n" .
     120                                        " \$factory = \core\lock\lock_config::get_lock_factory('type');\n" .
     121                                        " \$lock = \$factory->get_lock($key);\n" .
     122                                        " \$lock->release();  // Locks must ALWAYS be released like this.\n\n");
    110123        }
    111124    }
  • moodle/trunk/fuentes/lib/classes/lock/postgres_lock_factory.php

    r136 r1331  
    237237        foreach ($this->openlocks as $key => $unused) {
    238238            $lock = new lock($key, $this);
    239             $this->release_lock($lock);
     239            $lock->release();
    240240        }
    241241    }
Note: See TracChangeset for help on using the changeset viewer.