diff --git a/lib/classes/lock/file_lock_factory.php b/lib/classes/lock/file_lock_factory.php index 17c084a641b..52574273764 100644 --- a/lib/classes/lock/file_lock_factory.php +++ b/lib/classes/lock/file_lock_factory.php @@ -94,10 +94,15 @@ class file_lock_factory implements lock_factory { /** * Is available. - * @return boolean - True if this lock type is available in this environment. + * @return boolean - True if preventfilelocking is not set - or the file_lock_root is not in dataroot. */ public function is_available() { - return true; + $preventfilelocking = !empty($CFG->preventfilelocking); + $lockdirisdataroot = true; + if (!empty($CFG->file_lock_root) && strpos($CFG->file_lock_root, $CFG->dataroot) !== 0) { + $lockdirisdataroot = false; + } + return !$preventfilelocking || !$lockdirisdataroot; } /** diff --git a/lib/classes/lock/lock_config.php b/lib/classes/lock/lock_config.php index 50d2e1899a8..d1212bc3bf5 100644 --- a/lib/classes/lock/lock_config.php +++ b/lib/classes/lock/lock_config.php @@ -61,16 +61,13 @@ class lock_config { // DB Specific lock factory is prefered - should support auto-release. $lockfactoryclass = "\\core\\lock\\${dbtype}_lock_factory"; if (!class_exists($lockfactoryclass)) { - if (empty($CFG->preventfilelocking)) { - // File locking is second option - if $CFG->preventfilelocking allows it. - $lockfactoryclass = '\core\lock\file_lock_factory'; - } else { - // Final fallback - DB row locking. Does not support auto-release - so on failures - // we will have to wait for a timeout. - $lockfactoryclass = '\core\lock\db_record_lock_factory'; - } + $lockfactoryclass = '\core\lock\file_lock_factory'; } $lockfactory = new $lockfactoryclass($type); + if (!$lockfactory->is_available()) { + // Final fallback - DB row locking. + $lockfactory = new \core\lock\db_record_lock_factory($type); + } } return $lockfactory;