<commit_before><?php

/**
 * The Lock manager allows you to handle all file-locks centrally.
 *
 * This Lock Manager stores all its data in a database. You must pass a PDO
 * connection object in the constructor.
 * 
 * @package Sabre
 * @subpackage DAV
 * @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
 * @author <NAME> (http://www.rooftopsolutions.nl/) 
 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
 */
class Sabre_DAV_Locks_Backend_PDO extends Sabre_DAV_Locks_Backend_Abstract {

    /**
     * The PDO connection object 
     * 
     * @var pdo 
     */
    private $pdo;

    public function __construct(PDO $pdo) {

        $this->pdo = $pdo;

    }

    /**
     * Returns a list of Sabre_DAV_Locks_LockInfo objects  
     * 
     * This method should return all the locks for a particular uri, including
     * locks that might be set on a parent uri.
     *
     * If returnChildLocks is set to true, this method should also look for
     * any locks in the subtree of the uri for locks.
     *
     * @param string $uri 
     * @param bool $returnChildLocks
     * @return array 
     */
    public function getLocks($uri, $returnChildLocks) {

        // NOTE: the following 10 lines or so could be easily replaced by 
        // pure sql. MySQL's non-standard string concatination prevents us
        // from doing this though.
        $query = 'SELECT owner, token, timeout, created, scope, depth, uri FROM locks WHERE ((created + timeout) > CAST(? AS UNSIGNED INTEGER)) AND ((uri = ?)';
        $params = array(time(),$uri);

        // We need to check locks for every part in the uri.
        $uriParts = explode('/',$uri);

        // We already covered the last part of the uri
        array_pop($uriParts);

        $currentPath='';

        foreach($uriParts as $part) {

            if ($currentPath) $currentPath.='/';
            $currentPath.=$part;

            $query.=' OR (depth!=0 AND uri = ?)';
            $params[] = $currentPath;

        }

        $query.=')';

        if ($returnChildLocks) {

            $query.=' OR (uri LIKE ?)';
            $params[] = $uri . '%';

        }<commit_msg>Too many locks were returned<commit_after><?php

/**
 * The Lock manager allows you to handle all file-locks centrally.
 *
 * This Lock Manager stores all its data in a database. You must pass a PDO
 * connection object in the constructor.
 * 
 * @package Sabre
 * @subpackage DAV
 * @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
 * @author <NAME> (http://www.rooftopsolutions.nl/) 
 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
 */
class Sabre_DAV_Locks_Backend_PDO extends Sabre_DAV_Locks_Backend_Abstract {

    /**
     * The PDO connection object 
     * 
     * @var pdo 
     */
    private $pdo;

    public function __construct(PDO $pdo) {

        $this->pdo = $pdo;

    }

    /**
     * Returns a list of Sabre_DAV_Locks_LockInfo objects  
     * 
     * This method should return all the locks for a particular uri, including
     * locks that might be set on a parent uri.
     *
     * If returnChildLocks is set to true, this method should also look for
     * any locks in the subtree of the uri for locks.
     *
     * @param string $uri 
     * @param bool $returnChildLocks
     * @return array 
     */
    public function getLocks($uri, $returnChildLocks) {

        // NOTE: the following 10 lines or so could be easily replaced by 
        // pure sql. MySQL's non-standard string concatination prevents us
        // from doing this though.
        $query = 'SELECT owner, token, timeout, created, scope, depth, uri FROM locks WHERE ((created + timeout) > CAST(? AS UNSIGNED INTEGER)) AND ((uri = ?)';
        $params = array(time(),$uri);

        // We need to check locks for every part in the uri.
        $uriParts = explode('/',$uri);

        // We already covered the last part of the uri
        array_pop($uriParts);

        $currentPath='';

        foreach($uriParts as $part) {

            if ($currentPath) $currentPath.='/';
            $currentPath.=$part;

            $query.=' OR (depth!=0 AND uri = ?)';
            $params[] = $currentPath;

        }

        if ($returnChildLocks) {

            $query.=' OR (uri LIKE ?)';
            $params[] = $uri . '%';

        }
        $query.=')';
{'fraction_non_alphanumeric': 0.11181818181818182, 'fraction_numerical': 0.005, 'mean_word_length': 2.245575221238938, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7373000', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1263, 'n_words': 452}