Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace core\lock;
18
 
19
use coding_exception;
20
 
21
/**
22
 * Lock factory for use during installation.
23
 *
24
 * @package   core
25
 * @category  lock
26
 * @copyright  Andrew Nicols <andrew@nicols.co.uk>
27
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
29
class installation_lock_factory implements lock_factory {
30
 
31
    /**
32
     * Create this lock factory.
33
     *
34
     * @param string $type - The type, e.g. cron, cache, session
35
     */
36
    public function __construct($type) {
37
    }
38
 
39
    /**
40
     * Return information about the blocking behaviour of the lock type on this platform.
41
     *
42
     * @return boolean - False if attempting to get a lock will block indefinitely.
43
     */
44
    public function supports_timeout() {
45
        return true;
46
    }
47
 
48
    /**
49
     * This lock type will be automatically released when a process ends.
50
     *
51
     * @return boolean - True
52
     */
53
    public function supports_auto_release() {
54
        return true;
55
    }
56
 
57
    /**
58
     * This lock factory is only available during the initial installation.
59
     * To use it at any other time would be potentially dangerous.
60
     *
61
     * @return boolean
62
     */
63
    public function is_available() {
64
        return during_initial_install();
65
    }
66
 
67
    /**
68
     * @deprecated since Moodle 3.10.
69
     */
70
    public function supports_recursion() {
71
        throw new coding_exception('The function supports_recursion() has been removed, please do not use it anymore.');
72
    }
73
 
74
    /**
75
     * Get some info that might be useful for debugging.
76
     * @return boolean - string
77
     */
78
    protected function get_debug_info() {
79
        return 'host:' . php_uname('n') . ', pid:' . getmypid() . ', time:' . time();
80
    }
81
 
82
    /**
83
     * Get a lock within the specified timeout or return false.
84
     *
85
     * @param string $resource - The identifier for the lock. Should use frankenstyle prefix.
86
     * @param int $timeout - The number of seconds to wait for a lock before giving up.
87
     * @param int $maxlifetime - Unused by this lock type.
88
     * @return boolean - true if a lock was obtained.
89
     */
90
    public function get_lock($resource, $timeout, $maxlifetime = 86400) {
91
        return new lock($resource, $this);
92
    }
93
 
94
    /**
95
     * Release a lock that was previously obtained with @lock.
96
     *
97
     * @param lock $lock - A lock obtained from this factory.
98
     * @return boolean - true if the lock is no longer held (including if it was never held).
99
     */
100
    public function release_lock(lock $lock) {
101
        return true;
102
    }
103
 
104
    /**
105
     * @deprecated since Moodle 3.10.
106
     */
107
    public function extend_lock() {
108
        throw new coding_exception('The function extend_lock() has been removed, please do not use it anymore.');
109
    }
110
 
111
}